我正在尝试创建用于身份验证和授权的自定义授权服务器。授权服务器以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