我尝试使用Spring Boot和OAuth2设置概念验证。我设置的项目与此处列出的项目非常相似:
https://spring.io/guides/tutorials/spring-boot-oauth2/
在这里:https://spring.io/guides/tutorials/spring-security-and-angular-js/
与我的主要区别在于我遗漏了所有AngularJS的东西。
我有以下服务:
我想要发生的一切就是:
我可以通过auth服务器上的基本身份验证使这一切正常工作。但是,我希望能够将基本身份验证替换为Active Directory中的身份验证。
我还有其他几个可以进行AD身份验证的Spring Boot项目,但是无论什么时候我尝试将其放入这个内容都会出错。我认为这与auth服务器端点周围的安全性有关,但我不确定是什么。
另外,我不清楚哪些端点应该通过生产环境中的哪种协议(OAuth2 v.Basic)来保护?文档建议使用Basic保护一些端点。是否所有' OAuth2客户'以某种方式将这些凭证包含在他们的请求中?
这是我的auth服务器应用程序(添加了Active Directory的位):
@EnableResourceServer
@EnableAuthorizationServer
@SpringBootApplication
@RestController
public class AuthServerLdapApplication {
public static void main(String[] args) {
SpringApplication.run(AuthServerLdapApplication.class, args);
}
@RequestMapping("/user")
public Principal user(Principal user) {
return user;
}
@Order(ManagementServerProperties.ACCESS_OVERRIDE_ORDER)
@Configuration
protected static class ActiveDirectoryConfig extends WebSecurityConfigurerAdapter {
@Value("${activedirectory.url}")
private String activeDirectoryUrl;
@Value("${activedirectory.domain}")
private String getActiveDirectoryDomain;
@Autowired private AuthenticationManager authenticationManager;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
ActiveDirectoryLdapAuthenticationProvider provider = new ActiveDirectoryLdapAuthenticationProvider(getActiveDirectoryDomain,
activeDirectoryUrl);
provider.setConvertSubErrorCodesToExceptions(true);
provider.setUseAuthenticationRequestCredentials(true);
auth.authenticationProvider(provider);
auth.parentAuthenticationManager(authenticationManager);
}
}
}
基本上,当我点击UI服务器时,我得到了这个:
<oauth>
<error_description>
Full authentication is required to access this resource
</error_description>
<error>unauthorized</error>
</oauth>
如果我针对授权服务器执行此操作:
curl -v http://localhost:9004/uaa/login
* Trying ::1...
* Connected to localhost (::1) port 9004 (#0)
> GET /uaa/login HTTP/1.1
> Host: localhost:9004
> User-Agent: curl/7.44.0
> Accept: */*
>
< HTTP/1.1 401 Unauthorized
< Server: Apache-Coyote/1.1
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: 0
< X-Frame-Options: DENY
< Cache-Control: no-store
< Pragma: no-cache
< WWW-Authenticate: Bearer realm="null", error="unauthorized", error_description="Full authentication is required to access this resource"
< Content-Type: application/json;charset=UTF-8
< Transfer-Encoding: chunked
< Date: Tue, 01 Dec 2015 12:38:53 GMT
<
{"error":"unauthorized","error_description":"Full authentication is required to access this resource"}* Connection #0 to host localhost left intact
看起来登录端点现在需要持票人令牌?我现在不确定怎么办......
任何帮助/建议都将不胜感激......
答案 0 :(得分:2)
您@EnableResourceServer
但是您还没有为要保护的资源提供任何规则,因此它会尝试保护所有内容。您需要添加@Bean
类型ResourceServerConfigurerAdapter
并设置请求匹配器(以及您想要的其他规则)。