use of org.maxkey.authz.saml20.consumer.spring.ServiceProviderAuthenticationException in project MaxKey by dromara.
the class ConsumerEndpoint method consumer.
@RequestMapping(value = "/consumer/saml/v20/{spId}")
public ModelAndView consumer(HttpServletRequest request, HttpServletResponse response, @PathVariable("spId") String spId) throws Exception {
logger.debug("Attempting authentication.");
// 初始化SP 证书
initCredential(spId);
SAMLMessageContext messageContext = null;
/*
try {
messageContext = bindingAdapter.extractSAMLMessageContext(request);
} catch (MessageDecodingException me) {
logger.error("Could not decode SAML Response", me);
throw new Exception(me);
} catch (SecurityException se) {
logger.error("Could not decode SAML Response", se);
throw new Exception(se);
}*/
logger.debug("Message received from issuer: " + messageContext.getInboundMessageIssuer());
if (!(messageContext.getInboundSAMLMessage() instanceof Response)) {
logger.error("SAML Message was not a Response");
throw new Exception();
}
List<Assertion> assertionList = ((Response) messageContext.getInboundSAMLMessage()).getAssertions();
String credentials = extractBindingAdapter.extractSAMLMessage(request);
// 未认证token
Response samlResponse = (Response) messageContext.getInboundSAMLMessage();
AuthenticationDetailsSource<HttpServletRequest, ?> authenticationDetailsSource = new WebAuthenticationDetailsSource();
try {
validatorSuite.validate(samlResponse);
} catch (ValidationException ve) {
logger.warn("Response Message failed Validation", ve);
throw new ServiceProviderAuthenticationException("Invalid SAML REsponse Message", ve);
}
checkResponseStatus(samlResponse);
Assertion assertion = samlResponse.getAssertions().get(0);
logger.debug("authenticationResponseIssuingEntityName {}", samlResponse.getIssuer().getValue());
String username = assertion.getSubject().getNameID().getValue();
logger.debug("assertion.getID() ", assertion.getID());
logger.debug("assertion.getSubject().getNameID().getValue() ", username);
logger.debug("assertion.getID() ", assertion.getAuthnStatements());
LoginCredential loginCredential = new LoginCredential(username, "", ConstsLoginType.SAMLTRUST);
authenticationProvider.authentication(loginCredential, true);
ModelAndView mav = new ModelAndView();
mav.addObject("username", username);
mav.setViewName("redirect:/appList");
return mav;
}
Aggregations