use of org.opensaml.ws.message.encoder.MessageEncodingException in project MaxKey by dromara.
the class AssertionEndpoint method assertion.
@RequestMapping(value = "/authz/saml20/assertion")
public ModelAndView assertion(HttpServletRequest request, HttpServletResponse response) throws Exception {
logger.debug("saml20 assertion start.");
bindingAdapter = (BindingAdapter) request.getSession().getAttribute(WebConstants.AUTHORIZE_SIGN_ON_APP_SAMLV20_ADAPTER);
logger.debug("saml20 assertion get session samlv20Adapter " + bindingAdapter);
AppsSAML20Details saml20Details = bindingAdapter.getSaml20Details();
logger.debug("saml20Details " + saml20Details.getExtendAttr());
AuthnRequestInfo authnRequestInfo = bindingAdapter.getAuthnRequestInfo();
if (authnRequestInfo == null) {
logger.warn("Could not find AuthnRequest on the request. Responding with SC_FORBIDDEN.");
throw new Exception();
}
logger.debug("AuthnRequestInfo: {}", authnRequestInfo);
HashMap<String, String> attributeMap = new HashMap<String, String>();
attributeMap.put(WebConstants.ONLINE_TICKET_NAME, ((SigninPrincipal) WebContext.getAuthentication().getPrincipal()).getOnlineTicket().getTicketId());
// saml20Details
Response authResponse = authnResponseGenerator.generateAuthnResponse(saml20Details, authnRequestInfo, attributeMap, bindingAdapter);
Endpoint endpoint = endpointGenerator.generateEndpoint(saml20Details.getSpAcsUrl());
request.getSession().removeAttribute(AuthnRequestInfo.class.getName());
// request issuer...
try {
bindingAdapter.sendSAMLMessage(authResponse, endpoint, request, response);
} catch (MessageEncodingException mee) {
logger.error("Exception encoding SAML message", mee);
throw new Exception(mee);
}
return null;
}
use of org.opensaml.ws.message.encoder.MessageEncodingException in project MaxKey by dromara.
the class WebServicePostEncoder method encodeMsgContext.
@SuppressWarnings("rawtypes")
public VelocityContext encodeMsgContext(MessageContext messageContext) throws MessageEncodingException {
SAMLMessageContext samlMsgCtx = (SAMLMessageContext) messageContext;
SAMLObject outboundMessage = samlMsgCtx.getOutboundSAMLMessage();
if (outboundMessage == null) {
throw new MessageEncodingException("No outbound SAML message contained in message context");
}
signMessage(samlMsgCtx);
samlMsgCtx.setOutboundMessage(outboundMessage);
return encodeMsgContext(samlMsgCtx);
}
use of org.opensaml.ws.message.encoder.MessageEncodingException in project MaxKey by dromara.
the class WebServicePostEncoder method generateSignature.
/**
* Generates the signature over the string of concatenated form control data
* as indicated by the SimpleSign spec.
*
* @param signingCredential
* credential that will be used to sign
* @param algorithmURI
* algorithm URI of the signing credential
* @param formData
* form control data to be signed
*
* @return base64 encoded signature of form control data
*
* @throws MessageEncodingException
* there is an error computing the signature
*/
protected String generateSignature(Credential signingCredential, String algorithmURI, String formData) throws MessageEncodingException {
log.debug(String.format("Generating signature with key type '%s', algorithm URI '%s' over form control string '%s'", SecurityHelper.extractSigningKey(signingCredential).getAlgorithm(), algorithmURI, formData));
String b64Signature = null;
try {
byte[] rawSignature = SigningUtil.signWithURI(signingCredential, algorithmURI, formData.getBytes("UTF-8"));
b64Signature = Base64.encodeBytes(rawSignature, Base64.DONT_BREAK_LINES);
log.debug("Generated digital signature value (base64-encoded) {}", b64Signature);
} catch (SecurityException e) {
log.error("Error during URL signing process", e);
throw new MessageEncodingException("Unable to sign form control string", e);
} catch (UnsupportedEncodingException e) {
// UTF-8 encoding is required to be supported by all JVMs
}
return b64Signature;
}
use of org.opensaml.ws.message.encoder.MessageEncodingException in project MaxKey by dromara.
the class WebServicePostEncoder method encodeMsgContext.
/**
* Base64 and POST encodes the outbound message and writes it to the
* outbound transport.
*
* @param messageContext
* current message context
* @param endpointURL
* endpoint URL to encode message to
*
* @throws MessageEncodingException
* thrown if there is a problem encoding the message
*/
@SuppressWarnings("rawtypes")
protected VelocityContext encodeMsgContext(SAMLMessageContext messageContext) throws MessageEncodingException {
try {
VelocityContext context = new VelocityContext();
populateVelocityContext(context, messageContext);
return context;
} catch (Exception e) {
log.error("Error invoking velocity template", e);
throw new MessageEncodingException("Error creating output document", e);
}
}
use of org.opensaml.ws.message.encoder.MessageEncodingException in project uaa by cloudfoundry.
the class IdpSamlAuthenticationSuccessHandler method onAuthenticationSuccess.
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException {
SAMLMessageContext context = ((UaaAuthentication) authentication).getSamlMessageContext();
IdpExtendedMetadata extendedMetadata = null;
try {
extendedMetadata = (IdpExtendedMetadata) metadataManager.getExtendedMetadata(context.getLocalEntityId());
} catch (MetadataProviderException e) {
throw new ServletException("Failed to obtain local SAML IdP extended metadata.", e);
}
try {
populatePeerContext(context);
} catch (MetadataProviderException e) {
throw new ServletException("Failed to populate peer SAML SP context.", e);
}
try {
IdpWebSSOProfileOptions options = new IdpWebSSOProfileOptions();
options.setAssertionsSigned(extendedMetadata.isAssertionsSigned());
options.setAssertionTimeToLiveSeconds(extendedMetadata.getAssertionTimeToLiveSeconds());
idpWebSsoProfile.sendResponse(authentication, context, options);
} catch (SAMLException e) {
LOGGER.debug("Incoming SAML message is invalid.", e);
throw new AuthenticationServiceException("Incoming SAML message is invalid.", e);
} catch (MetadataProviderException e) {
LOGGER.debug("Error determining metadata contracts.", e);
throw new AuthenticationServiceException("Error determining metadata contracts.", e);
} catch (MessageEncodingException e) {
LOGGER.debug("Error decoding incoming SAML message.", e);
throw new AuthenticationServiceException("Error encoding outgoing SAML message.", e);
} catch (MarshallingException | SecurityException | SignatureException e) {
LOGGER.debug("Error signing SAML assertion.", e);
throw new AuthenticationServiceException("Error signing SAML assertion.", e);
}
}
Aggregations