Error refresh_token spring oauth2

0

Hello, I'm experiencing the following error when requesting the refresh_token. The application does not go up.

Error

Field userDetailsService in com.school.config.AuthorizationServerConfig required a bean of type 'org.springframework.security.core.userdetails.UserDetailsService' that could not be found.
    - Bean method 'inMemoryUserDetailsManager' not loaded because @ConditionalOnMissingBean (types: org.springframework.security.authentication.AuthenticationManager,org.springframework.security.authentication.AuthenticationProvider,org.springframework.security.core.userdetails.UserDetailsService; SearchStrategy: all) found beans of type 'org.springframework.security.authentication.AuthenticationManager' authenticationManager and found beans of type 'org.springframework.security.core.userdetails.UserDetailsService' userDetailsService


Action:

Consider revisiting the conditions above or defining a bean of type 'org.springframework.security.core.userdetails.UserDetailsService' in your configuration.

ResourceServerConfig

@Profile("oauth-security")
@Configuration
public class ResourceServerConfig extends ResourceServerConfigurerAdapter {

@Bean
public BCryptPasswordEncoder passwordEncoder() {
    return new BCryptPasswordEncoder();
}


@Bean
public MethodSecurityExpressionHandler createExpressionHandler() {
    return new OAuth2MethodSecurityExpressionHandler();
}

@Autowired
protected void configure(AuthenticationManagerBuilder auth) throws Exception {

    BCryptPasswordEncoder encoder = passwordEncoder();
    auth
    .inMemoryAuthentication()
    .withUser("admin")
    .password(encoder.encode("admin")) // admin   $2a$10$QVLgDyVzVuQhLbilE9GWUecbxL2rQh4WrnJLE3NF0MG8iDvWKDxzq
    .roles("ROLE");

}

@Override
public void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests()
    .antMatchers("/lesson").permitAll()
    .anyRequest().authenticated() 
    .and()
    .sessionManagement()
    .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
    .and()
    .csrf().disable();
}


@Override
public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
    resources.stateless(true);
}

AuthorizationServerConfig

 @Profile("oauth-security")
 @Configuration
 public class AuthorizationServerConfig extends 
 AuthorizationServerConfigurerAdapter {

@Autowired
private AuthenticationManager authenticationManager;


@Autowired
private UserDetailsService userDetailsService;


@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
    clients.inMemory()
        .withClient("angular")
        .secret("$2a$10$4CvdsdqhNu/A1ERtlyqOYeSbwnRbL7xCbPclZ7k3o6HvWw0oU3v1u") // @ngul@r0
        .scopes("read", "write")
        .authorizedGrantTypes("password")
        .accessTokenValiditySeconds(20)
        .and()
        .withClient("mobile")
        .secret("$2a$10$KJRZ.d9lgifvJU420wX7Oeb2sA3mgnGjv9iyUWNqcN1RxjXnKfcKK") // m0b1l30
        .scopes("read")
        .authorizedGrantTypes("password", "refresh_token")
        .accessTokenValiditySeconds(20)
        .refreshTokenValiditySeconds(3600 * 24);
}

@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    endpoints
        .tokenStore(tokenStore())
        .accessTokenConverter(accessTokenConverter())
        .reuseRefreshTokens(false)
        .userDetailsService(userDetailsService)
        .authenticationManager(authenticationManager);
}


@Bean
public JwtAccessTokenConverter accessTokenConverter() {
    JwtAccessTokenConverter accessTokenConverter = new JwtAccessTokenConverter();
    accessTokenConverter.setSigningKey("chave");

    return accessTokenConverter;
}

@Bean
public TokenStore tokenStore() {
    return new JwtTokenStore(accessTokenConverter());
}

}

OauthSecurityConfig

@Profile("oauth-security")
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableAuthorizationServer
@EnableResourceServer
public class OauthSecurityConfig  extends WebSecurityConfigurerAdapter{


@Bean
@Override
protected AuthenticationManager authenticationManager() throws Exception {
    return super.authenticationManager();
}

@Bean
public PasswordEncoder passwordEncoder() {
    return new BCryptPasswordEncoder();
}

}

    
asked by anonymous 23.10.2018 / 22:29

0 answers