授权服务器登录页面需要验证问题

时间:2019-09-05 18:33:57

标签: spring-security spring-oauth2 spring-boot-2

我正在尝试创建用于身份验证和授权的自定义授权服务器。授权服务器以http://localhost:2710/authua的身份运行。当我尝试击打authua/login时,它会给我以下响应。

<oauth>
 <error_description>
   Full authentication is required to access this resource
 </error_description>
 <error>unauthorized</error>
</oauth>

下面是我的配置代码

@Configuration
@EnableWebSecurity
@Order(SecurityProperties.BASIC_AUTH_ORDER)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

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

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

    @Override
    @Bean
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.antMatcher("/**")
        .authorizeRequests()
        .antMatchers("/login", "/webjars/**").permitAll()
        .anyRequest().authenticated()
        .and()
        .formLogin().permitAll()
        .and()
        .httpBasic();
    }

    @Autowired
    protected void globalUserDetails(AuthenticationManagerBuilder authBuilder) throws Exception {
        authBuilder
        .inMemoryAuthentication()
        .withUser("alexa")
        .password(encoder().encode("test"))
        .roles("USER");
    }
}

下面是我的授权服务器配置

@Configuration
@EnableAuthorizationServer
@EnableResourceServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {

    @Autowired
    @Qualifier("authenticationManagerBean")
    private AuthenticationManager authenticationManager;

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Autowired
    private TokenStore tokenStore;

    @Override
    public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
        oauthServer.tokenKeyAccess("permitAll()")
        .checkTokenAccess("isAuthenticated()")
        .passwordEncoder(passwordEncoder);
    }

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients.inMemory()
        .withClient("middora")
        .secret(passwordEncoder.encode("middora@midbone"))
        .authorizedGrantTypes("authorization_code", "client_credentials", "password", "refresh_token", "implicit")
        .scopes("create", "read", "modify", "delete")
        .autoApprove(true)
        .redirectUris("http://localhost:2730/admin/login");
    }

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

请帮助我找到我在哪里缺少什么,或分享描述此问题或类似问题的任何链接。

注意:@EnableResourceServer用于User-info-uri http://localhost:2711/authua/user

0 个答案:

没有答案