我正在尝试使用Spring Boot和OAuth2建立概念验证。我已经建立了一些项目,与此处概述的项目非常相似:
https://spring.io/guides/tutorials/spring-boot-oauth2/
并在这里:https : //spring.io/guides/tutorials/spring-security-and-angular-js/
与我的主要区别是我遗漏了所有AngularJS的东西。
我有以下服务:
我想要发生的一切是这样的:
我可以使用auth服务器上的Basic身份验证来正常工作。但是,我希望能够用Active Directory中的基本身份验证代替基本身份验证。
我还有其他几个可以进行AD身份验证的Spring Boot项目,它可以工作,但是,每当我尝试将其放入其中时,都会出错。我认为这与身份验证服务器端点周围的安全性有关,但我不确定。
另外,我不清楚在生产环境中应通过哪种协议(OAuth2 v。Basic)保护哪些端点?文档建议某些端点应使用Basic保护。所有“ OAuth2客户端”都应以某种方式在其请求中包括这些凭据吗?
这是我的身份验证服务器应用程序(添加了用于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
看起来登录端点现在需要一个承载令牌?我不确定现在如何进行...
任何帮助/建议将不胜感激...
您@EnableResourceServer
但您尚未为要保护的资源提供任何规则,因此它正在尝试保护所有内容。您需要添加@Bean
类型,ResourceServerConfigurerAdapter
并设置请求匹配项(以及您想要的其他任何规则)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句