Announcement Announcement Module
Collapse
No announcement yet.
Spring OAuth2 2.0.0.RELEASE Java Config questions/problems Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring OAuth2 2.0.0.RELEASE Java Config questions/problems

    Hey all,

    I'm trying to move over to the new release and the new java config, but I'm having some issues. First, how would I add a custom filter to the /oauth/token URL? Seems like if I use @EnableAuthorizationServer, that endpoint is configured for me and I no longer have access to it.

    Secondly, forget the custom filter for a second and let's assume I just want to test out authentication. I have what I think is a minimal java-based config, and I can authenticate successfully. However, if I'm testing out bad credentials, I get the appropriate response from the server, except the encoding is text/html and I'm expecting it to be application/json. It has been in the past. Problem with it being text/html is that the RestTemplate I'm using to test it fails to find a converter for it.

    It's worth mentioning that I'm using Spring Boot.

    Here is my java config:

    Code:
     @Configuration
      @EnableWebSecurity
      public class SecurityConfig extends WebSecurityConfigurerAdapter {
      
        @Configuration
          @EnableAuthorizationServer
          static class AuthServerConfigurer extends AuthorizationServerConfigurerAdapter {
              @Autowired
              private ClientDetailsService clientDetailsService;
           
              @Autowired
              private TokenStore tokenStore;
     
              @Autowired
              @Qualifier("authenticationManager")
              private AuthenticationManager authenticationManager;
     
              public AuthServerConfigurer() {
              }
     
              @Override
              public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
                  clients.withClientDetails(clientDetailsService);
              }
       
              @Override
              public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
                  endpoints.clientDetailsService(clientDetailsService);
                  endpoints.tokenStore(tokenStore);
                  endpoints.authenticationManager(authenticationManager);
              }
          }
       
         @Configuration
         @EnableResourceServer
          static class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
              @Autowired
             private TokenStore tokenStore
      
            public ResourceServerConfiguration() {
              }
              @Override
             public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
                 resources.tokenStore(tokenStore);
             }
          }
     
          @Override
          protected void configure(AuthenticationManagerBuilder auth) throws Exception {
              DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
              authProvider.setUserDetailsService(userDetailsService());
              auth.authenticationProvider(authProvider);
          }
     
          @Bean(name="authenticationManager")
          public AuthenticationManager authenticationManager() throws Exception {
               return super.authenticationManagerBean();
          }
      
        @Bean
          public UserDetailsService userDetailsService() {
               return new ClientDetailsUserDetailsService(clientDetailsService());
          }
    
    
       @Bean
          public ClientDetailsService clientDetailsService() {
             //stuff
         }
     
         @Bean
          public TokenStore tokenStore() {
              return new InMemoryTokenStore();
          }
    }
Working...
X