Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Configuration
- @EnableWebSecurity
- @EnableResourceServer
- public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
- @Autowired
- public void configure(AuthenticationManagerBuilder auth) throws Exception {
- auth.inMemoryAuthentication()
- .withUser("admin").password("admin").roles("ROLE");
- }
- @Override
- public void configure(HttpSecurity http) throws Exception {
- http.authorizeRequests()
- .antMatchers("/categorias").permitAll()
- .anyRequest().authenticated()
- .and()
- .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
- .and()
- .csrf().disable();
- }
- @Override
- public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
- resources.stateless(true);
- }
- }
- @Configuration
- @EnableAuthorizationServer
- public class AuthorizationServerConfig extends
- AuthorizationServerConfigurerAdapter {
- @Autowired
- private AuthenticationManager authenticationManager;
- @Override
- public void configure(ClientDetailsServiceConfigurer clients) throws
- Exception {
- clients.inMemory()
- .withClient("angular")
- .secret("@ngul@r0")
- .scopes("read", "write")
- .authorizedGrantTypes("password")
- .accessTokenValiditySeconds(1800);
- }
- @Override
- public void configure(AuthorizationServerEndpointsConfigurer endpoints)
- throws Exception {
- endpoints
- .tokenStore(tokenStore())
- .accessTokenConverter(accessTokenConverter())
- .authenticationManager(authenticationManager);
- }
- @Bean
- public JwtAccessTokenConverter accessTokenConverter() {
- JwtAccessTokenConverter accessTokenConverter = new
- JwtAccessTokenConverter();
- accessTokenConverter.setSigningKey("algaworks");
- return accessTokenConverter;
- }
- @Bean
- public TokenStore tokenStore() {
- return new JwtTokenStore(accessTokenConverter());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement