org.opensaml.saml2.core.StatusCode Java Examples

The following examples show how to use org.opensaml.saml2.core.StatusCode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SAMLResponseBuilder.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Get status
 *
 * @param status
 * @param statMsg
 * @return Status object
 */
private Status buildStatus(String status, String statMsg) {

    Status stat = new StatusBuilder().buildObject();

    // Set the status code
    StatusCode statCode = new StatusCodeBuilder().buildObject();
    statCode.setValue(status);
    stat.setStatusCode(statCode);

    // Set the status Message
    if (statMsg != null) {
        StatusMessage statMesssage = new StatusMessageBuilder().buildObject();
        statMesssage.setMessage(statMsg);
        stat.setStatusMessage(statMesssage);
    }

    return stat;
}
 
Example #2
Source File: SingleLogoutMessageBuilder.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
private Status buildStatus(String status, String statMsg) {

        Status stat = new StatusBuilder().buildObject();

        //Set the status code
        StatusCode statCode = new StatusCodeBuilder().buildObject();
        statCode.setValue(status);
        stat.setStatusCode(statCode);

        //Set the status Message
        if (statMsg != null) {
            StatusMessage statMesssage = new StatusMessageBuilder().buildObject();
            statMesssage.setMessage(statMsg);
            stat.setStatusMessage(statMesssage);
        }

        return stat;
    }
 
Example #3
Source File: ErrorResponseBuilder.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Build the StatusCode for Status of Response
 *
 * @param parentStatusCode
 * @param childStatusCode
 * @return
 */
private StatusCode buildStatusCode(String parentStatusCode, StatusCode childStatusCode) throws IdentityException {

    if (parentStatusCode == null) {
        throw IdentityException.error("Invalid SAML Response Status Code");
    }

    StatusCode statusCode = new StatusCodeBuilder().buildObject();
    statusCode.setValue(parentStatusCode);

    //Set the status Message
    if (childStatusCode != null) {
        statusCode.setStatusCode(childStatusCode);
        return statusCode;
    } else {
        return statusCode;
    }
}
 
Example #4
Source File: ErrorResponseBuilder.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Build the error response
 *
 * @param inResponseToID
 * @param statusCodes
 * @param statusMsg
 * @return
 */
public Response buildResponse(String inResponseToID, List<String> statusCodes, String statusMsg,
                              String destination) throws IdentityException {
    if (statusCodes == null || statusCodes.isEmpty()) {
        throw IdentityException.error("No Status Values");
    }
    response.setIssuer(SAMLSSOUtil.getIssuer());
    Status status = new StatusBuilder().buildObject();
    StatusCode statusCode = null;
    for (String statCode : statusCodes) {
        statusCode = buildStatusCode(statCode, statusCode);
    }
    status.setStatusCode(statusCode);
    buildStatusMsg(status, statusMsg);
    response.setStatus(status);
    response.setVersion(SAMLVersion.VERSION_20);
    response.setID(SAMLSSOUtil.createID());
    if (inResponseToID != null) {
        response.setInResponseTo(inResponseToID);
    }
    if (destination != null) {
        response.setDestination(destination);
    }
    response.setIssueInstant(new DateTime());
    return response;
}
 
Example #5
Source File: DefaultResponseBuilder.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
private Status buildStatus(String status, String statMsg) {

        Status stat = new StatusBuilder().buildObject();

        // Set the status code
        StatusCode statCode = new StatusCodeBuilder().buildObject();
        statCode.setValue(status);
        stat.setStatusCode(statCode);

        // Set the status Message
        if (statMsg != null) {
            StatusMessage statMesssage = new StatusMessageBuilder().buildObject();
            statMesssage.setMessage(statMsg);
            stat.setStatusMessage(statMesssage);
        }

        return stat;
    }
 
Example #6
Source File: SamlHelper.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
public void validateStatus(org.opensaml.saml2.core.Response samlResponse) {
    Status responseStatus = samlResponse.getStatus();
    StatusCode statusCode = responseStatus.getStatusCode();
    String statusValue = statusCode.getValue();

    if (!statusValue.equals(SUCCESS_STATUS)) {
        LOG.error("SAML Response did not have a success status, instead status was {}", statusValue);
    }
}
 
Example #7
Source File: SAML2LoginAPIAuthenticatorCmdTest.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
private Response buildMockResponse() throws Exception {
    Response samlMessage = new ResponseBuilder().buildObject();
    samlMessage.setID("foo");
    samlMessage.setVersion(SAMLVersion.VERSION_20);
    samlMessage.setIssueInstant(new DateTime(0));
    Issuer issuer = new IssuerBuilder().buildObject();
    issuer.setValue("MockedIssuer");
    samlMessage.setIssuer(issuer);
    Status status = new StatusBuilder().buildObject();
    StatusCode statusCode = new StatusCodeBuilder().buildObject();
    statusCode.setValue(StatusCode.SUCCESS_URI);
    status.setStatusCode(statusCode);
    samlMessage.setStatus(status);
    Assertion assertion = new AssertionBuilder().buildObject();
    Subject subject = new SubjectBuilder().buildObject();
    NameID nameID = new NameIDBuilder().buildObject();
    nameID.setValue("SOME-UNIQUE-ID");
    nameID.setFormat(NameIDType.PERSISTENT);
    subject.setNameID(nameID);
    assertion.setSubject(subject);
    AuthnStatement authnStatement = new AuthnStatementBuilder().buildObject();
    authnStatement.setSessionIndex("Some Session String");
    assertion.getAuthnStatements().add(authnStatement);
    AttributeStatement attributeStatement = new AttributeStatementBuilder().buildObject();
    assertion.getAttributeStatements().add(attributeStatement);
    samlMessage.getAssertions().add(assertion);
    return samlMessage;
}
 
Example #8
Source File: SamlAssertionProducer.java    From saml-generator with Apache License 2.0 5 votes vote down vote up
private Status createStatus() {
	StatusCodeBuilder statusCodeBuilder = new StatusCodeBuilder();
	StatusCode statusCode = statusCodeBuilder.buildObject();
	statusCode.setValue(StatusCode.SUCCESS_URI);

	StatusBuilder statusBuilder = new StatusBuilder();
	Status status = statusBuilder.buildObject();
	status.setStatusCode(statusCode);

	return status;
}
 
Example #9
Source File: SAML2SSOManager.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
protected boolean isNoPassive(Response response) {

        return response.getStatus() != null &&
                response.getStatus().getStatusCode() != null &&
                response.getStatus().getStatusCode().getValue().equals(StatusCode.RESPONDER_URI) &&
                response.getStatus().getStatusCode().getStatusCode() != null &&
                response.getStatus().getStatusCode().getStatusCode().getValue().equals(
                        StatusCode.NO_PASSIVE_URI);
    }
 
Example #10
Source File: ErrorResponseBuilder.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
private static Status buildStatus() {

        Status stat = new StatusBuilder().buildObject();

        //Set the status code
        StatusCode statCode = new StatusCodeBuilder().buildObject();
        statCode.setValue("urn:oasis:names:tc:SAML:2.0:status:Responder");
        stat.setStatusCode(statCode);
        StatusMessage statMesssage = new StatusMessageBuilder().buildObject();
        statMesssage.setMessage("Error when processing the Authentication Request");
        stat.setStatusMessage(statMesssage);

        return stat;
    }
 
Example #11
Source File: StatusCodeUnmarshaller.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
protected void processChildElement(XMLObject parentSAMLObject, XMLObject childSAMLObject)
        throws UnmarshallingException {
    StatusCode statusCode = (StatusCode) parentSAMLObject;

    if (childSAMLObject instanceof StatusCode) {
        statusCode.setStatusCode((StatusCode) childSAMLObject);
    } else {
        super.processChildElement(parentSAMLObject, childSAMLObject);
    }
}
 
Example #12
Source File: StatusCodeUnmarshaller.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {
    StatusCode statusCode = (StatusCode) samlObject;

    if (attribute.getLocalName().equals(StatusCode.VALUE_ATTRIB_NAME)) {
        statusCode.setValue(attribute.getValue());
    } else {
        super.processAttribute(samlObject, attribute);
    }
}
 
Example #13
Source File: StatusUnmarshaller.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
protected void processChildElement(XMLObject parentSAMLObject, XMLObject childSAMLObject)
        throws UnmarshallingException {
    Status status = (Status) parentSAMLObject;

    if (childSAMLObject instanceof StatusCode) {
        status.setStatusCode((StatusCode) childSAMLObject);
    } else if (childSAMLObject instanceof StatusMessage) {
        status.setStatusMessage((StatusMessage) childSAMLObject);
    } else if (childSAMLObject instanceof StatusDetail) {
        status.setStatusDetail((StatusDetail) childSAMLObject);
    } else {
        super.processChildElement(parentSAMLObject, childSAMLObject);
    }
}
 
Example #14
Source File: StatusCodeMarshaller.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
protected void marshallAttributes(XMLObject samlObject, Element domElement) throws MarshallingException {
    StatusCode statusCode = (StatusCode) samlObject;

    if (statusCode.getValue() != null) {
        domElement.setAttributeNS(null, StatusCode.VALUE_ATTRIB_NAME, statusCode.getValue());
    }

}
 
Example #15
Source File: ConsumerEndpoint.java    From MaxKey with Apache License 2.0 4 votes vote down vote up
private void checkResponseStatus(Response samlResponse) {

		
		if(StatusCode.SUCCESS_URI.equals( StringUtils.trim(samlResponse.getStatus().getStatusCode().getValue()))) {
			
			additionalValidationChecksOnSuccessfulResponse(samlResponse);
			
		}
		
		
		else {
			
			StringBuilder extraInformation = extractExtraInformation(samlResponse);
			
			if(extraInformation.length() > 0) {
				logger.warn("Extra information extracted from authentication failure was {}", extraInformation.toString());
				
				throw new IdentityProviderAuthenticationException("Identity Provider has failed the authentication.", extraInformation.toString());
			}
			
			else {
				throw new IdentityProviderAuthenticationException("Identity Provider has failed the authentication.");
			}
			
		}
	}
 
Example #16
Source File: StatusCodeSchemaValidator.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public void validate(StatusCode statusCode) throws ValidationException {
    validateValue(statusCode);
}
 
Example #17
Source File: StatusGenerator.java    From MaxKey with Apache License 2.0 4 votes vote down vote up
public Status generateStatus( String value, String subStatus, String message ) {
	Status status =  builderStatus();
	
	StatusCode statusCode =  builderStatusCode(value);
	
	StatusCode subStatusCode =builderStatusCode(value);
	
	statusCode.setStatusCode(subStatusCode);
	
	status.setStatusCode(statusCode);
	
	StatusMessage statusMessage = builderStatusMessage(message);
	
	status.setStatusMessage(statusMessage);
	
	return status;
}
 
Example #18
Source File: StatusGenerator.java    From MaxKey with Apache License 2.0 4 votes vote down vote up
public StatusCode builderStatusCode(String value){
	StatusCode statusCode = (StatusCode) new StatusCodeBuilder().buildObject();
	statusCode.setValue(value);
	
	return statusCode;
}
 
Example #19
Source File: AuthnResponseGenerator.java    From MaxKey with Apache License 2.0 4 votes vote down vote up
public Response generateAuthnResponse(  AppsSAML20Details saml20Details,
										AuthnRequestInfo authnRequestInfo,
										HashMap<String,String>attributeMap, 
										BindingAdapter bindingAdapter){
	
	Response authResponse = new ResponseBuilder().buildObject();
	//builder Assertion
	Assertion assertion = assertionGenerator.generateAssertion( 
										saml20Details,
										bindingAdapter,
										saml20Details.getSpAcsUrl(),
										authnRequestInfo.getAuthnRequestID(),
										saml20Details.getAudience(),
										Integer.parseInt(saml20Details.getValidityInterval()), 
										attributeMap);
	
	//Encrypt 
	if(Boolean.isTrue(saml20Details.getEncrypted())) {
		logger.info("begin to encrypt assertion");
		try {
			// Assume this contains a recipient's RSA public
			EncryptionParameters encryptionParameters = new EncryptionParameters();
			encryptionParameters.setAlgorithm(EncryptionConstants.ALGO_ID_BLOCKCIPHER_AES128);
			logger.info("encryption assertion Algorithm : "+EncryptionConstants.ALGO_ID_BLOCKCIPHER_AES128);
			KeyEncryptionParameters keyEncryptionParameters = new KeyEncryptionParameters();
			keyEncryptionParameters.setEncryptionCredential(bindingAdapter.getSpSigningCredential());
			// kekParams.setAlgorithm(EncryptionConstants.ALGO_ID_KEYTRANSPORT_RSAOAEP);
			keyEncryptionParameters.setAlgorithm(EncryptionConstants.ALGO_ID_KEYTRANSPORT_RSA15);
			logger.info("keyEncryption  Algorithm : "+EncryptionConstants.ALGO_ID_KEYTRANSPORT_RSA15);
			KeyInfoGeneratorFactory keyInfoGeneratorFactory = Configuration
													.getGlobalSecurityConfiguration()
													.getKeyInfoGeneratorManager().getDefaultManager()
													.getFactory(bindingAdapter.getSpSigningCredential());
			keyEncryptionParameters.setKeyInfoGenerator(keyInfoGeneratorFactory.newInstance());
			Encrypter encrypter = new Encrypter(encryptionParameters, keyEncryptionParameters);
			encrypter.setKeyPlacement(KeyPlacement.PEER);
			EncryptedAssertion encryptedAssertion = encrypter.encrypt(assertion);
			authResponse.getEncryptedAssertions().add(encryptedAssertion);
		}catch(Exception e) {
			logger.info("Unable to encrypt assertion .",e);
		}
	}else { 
		authResponse.getAssertions().add(assertion);
	}
	
	authResponse.setIssuer(issuerGenerator.generateIssuer());
	authResponse.setID(idService.generateID());
	authResponse.setIssueInstant(timeService.getCurrentDateTime());
	authResponse.setInResponseTo(authnRequestInfo.getAuthnRequestID());
	authResponse.setDestination(saml20Details.getSpAcsUrl());
	authResponse.setStatus(statusGenerator.generateStatus(StatusCode.SUCCESS_URI));
	logger.debug("authResponse.isSigned "+authResponse.isSigned());
	return authResponse;
}
 
Example #20
Source File: StatusImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public void setStatusCode(StatusCode newStatusCode) {
    this.statusCode = prepareForAssignment(this.statusCode, newStatusCode);

}
 
Example #21
Source File: StatusImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public StatusCode getStatusCode() {
    return this.statusCode;
}
 
Example #22
Source File: StatusCodeBuilder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public StatusCode buildObject(String namespaceURI, String localName, String namespacePrefix) {
    return new StatusCodeImpl(namespaceURI, localName, namespacePrefix);
}
 
Example #23
Source File: StatusCodeBuilder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public StatusCode buildObject() {
    return buildObject(SAMLConstants.SAML20P_NS, StatusCode.DEFAULT_ELEMENT_LOCAL_NAME,
            SAMLConstants.SAML20P_PREFIX);
}
 
Example #24
Source File: StatusCodeImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public void setStatusCode(StatusCode newStatusCode) {
    this.childStatusCode = prepareForAssignment(this.childStatusCode, newStatusCode);
}
 
Example #25
Source File: StatusCodeImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public StatusCode getStatusCode() {
    return childStatusCode;
}
 
Example #26
Source File: StatusGenerator.java    From MaxKey with Apache License 2.0 3 votes vote down vote up
public Status generateStatus( String value ) {
	Status status =  builderStatus();
	
	StatusCode statusCode =  builderStatusCode(value);
	
	status.setStatusCode(statusCode);
	
	return status;
}
 
Example #27
Source File: StatusCodeSchemaValidator.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 *  Validates the Value attribute
 * 
 * @param sc
 * @throws ValidationException
 */
protected void validateValue(StatusCode sc) throws ValidationException {
    if (DatatypeHelper.isEmpty(sc.getValue())) {
        throw new ValidationException("Value attribute is required");
    }
}