Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Configuration
- @Component
- public class OAuth2ServerConfiguration {
- private static final String RESOURCE_ID = "restservice";
- @Configuration
- @Component
- @EnableResourceServer
- @Order(3)
- protected static class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
- @Override
- public void configure(ResourceServerSecurityConfigurer resources) {
- resources.resourceId(RESOURCE_ID);
- }
- @Override
- public void configure(HttpSecurity http) throws Exception {
- http.authorizeRequests().antMatchers("/users").hasRole("ADMIN").antMatchers("/greeting").authenticated();
- }
- }
- @Configuration
- @Component
- @EnableAuthorizationServer
- protected static class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter {
- private TokenStore tokenStore = new InMemoryTokenStore();
- @Autowired
- @Qualifier("authenticationManagerBean")
- private AuthenticationManager authenticationManager;
- @Autowired
- private CustomUserDetailsService userDetailsService;
- @Override
- public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
- endpoints.tokenStore(this.tokenStore).authenticationManager(this.authenticationManager)
- .userDetailsService(userDetailsService);
- }
- @Override
- public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
- clients.inMemory().withClient("clientapp").authorizedGrantTypes("password", "refresh_token")
- .authorities("USER").scopes("read", "write").resourceIds(RESOURCE_ID).secret("123456");
- }
- @Bean
- @Primary
- public DefaultTokenServices tokenServices() {
- DefaultTokenServices tokenServices = new DefaultTokenServices();
- tokenServices.setSupportRefreshToken(true);
- tokenServices.setTokenStore(this.tokenStore);
- return tokenServices;
- }
- }
- }
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:jpa="http://www.springframework.org/schema/data/jpa"
- xmlns:oauth2="http://www.springframework.org/schema/security/oauth2"
- xsi:schemaLocation="http://www.springframework.org/schema/security/oauth2 http://www.springframework.org/schema/security/spring-security-oauth2.xsd
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
- http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.8.xsd">
- <context:annotation-config base-package="net.mmm.ma"></context:annotation-config>
- <context:component-scan base-package="net.mmm.ma" />
- <jpa:repositories base-package="net.mmm.ma"></jpa:repositories>
- <bean id="dataSource"
- class="org.springframework.jdbc.datasource.DriverManagerDataSource">
- <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
- <property name="url" value="jdbc:mysql://localhost:3306/test20"></property>
- <property name="username" value="root"></property>
- <property name="password" value=""></property>
- </bean>
- <bean id="persistenceUnitManager"
- class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
- <property name="persistenceXmlLocations">
- <list>
- <value>classpath*:META-INF/persistence.xml</value>
- </list>
- </property>
- <property name="defaultDataSource" ref="dataSource"></property>
- </bean>
- <bean id="entityManagerFactory"
- class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
- <property name="persistenceUnitManager" ref="persistenceUnitManager"></property>
- <property name="persistenceUnitName" value="MY_P"></property>
- </bean>
- <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
- <property name="entityManagerFactory" ref="entityManagerFactory"></property>
- </bean>
- </beans>
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
- <!-- The definition of the Root Spring Container shared by all Servlets
- and Filters -->
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>classpath*:applicationContext.xml</param-value>
- </context-param>
- <!-- Creates the Spring Container shared by all Servlets and Filters -->
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
- <!-- Processes application requests -->
- <servlet>
- <servlet-name>appServlet</servlet-name>
- <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
- <init-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>appServlet</servlet-name>
- <url-pattern>/*</url-pattern>
- </servlet-mapping>
- </web-app>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement