Spring Security SAML SSO重定向到控制器



使用代码片段重定向到IdP启动的设置中的控制器(/bootstrap/v1(:

public SavedRequestAwareAuthenticationSuccessHandler successRedirectHandler() {
SavedRequestAwareAuthenticationSuccessHandler successRedirectHandler = new SavedRequestAwareAuthenticationSuccessHandler();
successRedirectHandler.setDefaultTargetUrl("/bootstrap/v1");
return successRedirectHandler;
}

控制器代码片段:

public class BootstrapController extends ParentController {
@RequestMapping(value = "/v1", method = RequestMethod.POST)
public ResponseEntity<BootstrapResponseDto> bootstrap(@RequestBody BootstrapRequestDto bootstrapRequestDto, @RequestHeader(value = "MAC-ADDRESS", required = false) String macAddress) {
myAppUserDetails userDetails = SecurityContextUtils.getUserDetails();
BootstrapResponseDto bootstrapResponseDto = new BootstrapResponseDto();
// some app specific logic goes here...
return new ResponseEntity<>(bootstrapResponseDto, HttpStatus.OK);
}
}

调试级别日志片段:

11-29-2018 13:33:53 e7a5edb2-4051-4132-bad0-856d58af1c7dZDJhMWExYWUtZTAxNy00NDQwLWJmOTctNzcyNTJlOWUyNmQ2信息http-nio-8080-exec-6 Spring安全调试器:


收到POST'/saml/SSO'请求:

org.springframework.session.web.http.SessionRepositoryFilter$SessionRepositoryRequestWrapper@28cc5b21

servlet路径:/saml/SSO路径信息:空标头:主机:localhost:8080用户代理:Mozilla/5.0(Macintosh;英特尔Mac OS X 10.13;rv:63.0(Gecko/20100101 Firefox/63.0接受:text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8接受语言:en-US,en;q=0.5接受编码:gzip,deflate内容类型:application/x-www-form-urlencoded内容长度:11320dnt:1连接:保持活动cookie:JSESSIONID=ZDJhMWExYWUtZTAxNy00NDQwLWJmOTctNzcyNTJlOWUyNmQ2升级不安全请求:1个

安全过滤链:[MetadataGeneratorFilter
WebAsyncManagerIntegrationFilter SecurityContextPersistenceFilterFilterSecurityInterceptor]


11-29-2018 13:33:53 e7a5edb2-4051-4132-bad0-856d58af1c7d信息http-nio-8080-exec-6o.o.c.b.s.SAML协议消息XML签名安全策略规则:协议消息签名验证成功,消息类型:{urn:aoasis:names:tc:SAML:2.0:protocol}响应11-29-2018 13:33:53e7a5edb2-4051-4132-bad0-856d58af1c7dZDJhMWExYWUtZTAxNy00NDQwLWJmOTctNzcyNTJlOWUyNmQ2信息http-nio-8080-exec-7 Spring安全调试器:


收到GET'/bootstrap/v1'请求:

org.springframework.session.web.http.SessionRepositoryFilter$SessionRepositoryRequestWrapper@5f9e2aff

servletPath:/bootstrap/v1 pathInfo:null headers:host:localhost:8080用户代理:Mozilla/5.0(Macintosh;英特尔Mac OS X 10.13;rv:63.0(Gecko/20100101 Firefox/63.0接受:text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8接受语言:en-US,en;q=0.5接受编码:gzip,deflate dnt:1连接:保持活动cookie:JSESSIONID=ZDJhMWExYWUtZTAxNy00NDQwLWJmOTctNzcyNTJlOWUyNmQ2升级不安全请求:1个

安全过滤链:[MetadataGeneratorFilter
WebAsyncManagerIntegrationFilter SecurityContextPersistenceFilterFilterSecurityInterceptor]


11-29-2018 13:33:53 e7a5edb2-4051-4132-bad0-856d58af1c7d警告http-nio-8080-exec-7 o.s.w.s.PageNotFound:未找到请求方法"GET"支持的

ExpiringUsernameAuthenticationToken设置为返回:

org.springframework.security.providers.ExpiringUsernameAuthenticationToken@fee70636:委托人:com.<我的公司>。security.authentication@325fcf8b;全权证书:[受保护];认证:真实;明细:空;授予权限:权限_1、权限_2、权限_3、权限_4

所以,我猜我的SAML验证和用户身份验证&授权是好的。

我面临的问题似乎是HTTP获取不起作用。

如何配置并提交HTTPPOST?或我应该重构我的控制器来处理行为吗(这可能会破坏基于表单的登录,这也是应用程序身份验证的一部分(?

HTTP状态405-方法不允许错误

我相信这个问题根本与SAML无关,而是一个通用的Spring Security问题。此外,您没有指定正文BootstrapRequestDto的来源。

你有一个SuccessHandler,它会重定向:

successRedirectHandler.setDefaultTargetUrl("/bootstrap/v1");这将执行GET

并且您有一个只接受POST的控制器。你还没有具体说明那具尸体是从哪里来的?

您需要编写一个自定义的成功处理程序来发布帖子(可能是javascript自动提交表单?(,或者只需更改控制器即可接受GET。

public class BootstrapController extends ParentController {
@RequestMapping(value = "/v1", method = RequestMethod.GET)
public ResponseEntity<BootstrapResponseDto> bootstrap() {
myAppUserDetails userDetails = SecurityContextUtils.getUserDetails();
BootstrapResponseDto bootstrapResponseDto = new bootstrapResponseDto();
// some app specific logic goes here...
return new ResponseEntity<>(bootstrapResponseDto, HttpStatus.OK);
}
@RequestMapping(value = "/v1", method = RequestMethod.POST)
public ResponseEntity<BootstrapResponseDto> bootstrap(@RequestBody BootstrapRequestDto bootstrapRequestDto, @RequestHeader(value = "MAC-ADDRESS", required = false) String macAddress) {
myAppUserDetails userDetails = SecurityContextUtils.getUserDetails();
BootstrapResponseDto bootstrapResponseDto = new BootstrapResponseDto();
// some app specific logic goes here...
return new ResponseEntity<>(bootstrapResponseDto, HttpStatus.OK);
}
}

相关内容

  • 没有找到相关文章

最新更新