org.opensaml.saml2.core.Status Java Examples

The following examples show how to use org.opensaml.saml2.core.Status. 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: ArtifactResponseUnmarshaller.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
protected void processChildElement(XMLObject parentSAMLObject, XMLObject childSAMLObject)
        throws UnmarshallingException {
    ArtifactResponse artifactResponse = (ArtifactResponse) parentSAMLObject;

    if (childSAMLObject instanceof Issuer) {
        artifactResponse.setIssuer((Issuer) childSAMLObject);
    } else if (childSAMLObject instanceof Signature) {
        artifactResponse.setSignature((Signature) childSAMLObject);
    } else if (childSAMLObject instanceof Extensions) {
        artifactResponse.setExtensions((Extensions) childSAMLObject);
    } else if (childSAMLObject instanceof Status) {
        artifactResponse.setStatus((Status) childSAMLObject);
    } else {
        artifactResponse.setMessage((SAMLObject) childSAMLObject);
    }
}
 
Example #2
Source File: StatusResponseTypeUnmarshaller.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
protected void processChildElement(XMLObject parentSAMLObject, XMLObject childSAMLObject)
        throws UnmarshallingException {
    StatusResponseType sr = (StatusResponseType) parentSAMLObject;

    if (childSAMLObject instanceof Issuer) {
        sr.setIssuer((Issuer) childSAMLObject);
    } else if (childSAMLObject instanceof Signature) {
        sr.setSignature((Signature) childSAMLObject);
    } else if (childSAMLObject instanceof Extensions) {
        sr.setExtensions((Extensions) childSAMLObject);
    } else if (childSAMLObject instanceof Status) {
        sr.setStatus((Status) childSAMLObject);
    } else {
        super.processChildElement(parentSAMLObject, childSAMLObject);
    }
}
 
Example #3
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 #4
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 #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: 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 #7
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 #8
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 #9
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 #10
Source File: SamlAssertionProducer.java    From saml-generator with Apache License 2.0 5 votes vote down vote up
private Response createResponse(final DateTime issueDate, Issuer issuer, Status status, Assertion assertion) {
	ResponseBuilder responseBuilder = new ResponseBuilder();
	Response response = responseBuilder.buildObject();
	response.setID(UUID.randomUUID().toString());
	response.setIssueInstant(issueDate);
	response.setVersion(SAMLVersion.VERSION_20);
	response.setIssuer(issuer);
	response.setStatus(status);
	response.getAssertions().add(assertion);
	return response;
}
 
Example #11
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 #12
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 #13
Source File: ErrorResponseBuilder.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Set the StatusMessage for Status of Response
 *
 * @param statusMsg
 * @return
 */
private Status buildStatusMsg(Status status, String statusMsg) {
    if (statusMsg != null) {
        StatusMessage statusMesssage = new StatusMessageBuilder().buildObject();
        statusMesssage.setMessage(statusMsg);
        status.setStatusMessage(statusMesssage);
    }
    return status;
}
 
Example #14
Source File: StatusGenerator.java    From MaxKey with Apache License 2.0 4 votes vote down vote up
public Status builderStatus(){
	Status status =  (Status) new StatusBuilder().buildObject();
	return status;
}
 
Example #15
Source File: SamlAssertionProducer.java    From saml-generator with Apache License 2.0 4 votes vote down vote up
public Response createSAMLResponse(final String subjectId, final DateTime authenticationTime,
		                           final String credentialType, final HashMap<String, List<String>> attributes, String issuer, Integer samlAssertionDays) {
	
	try {
		DefaultBootstrap.bootstrap();
		
		Signature signature = createSignature();
		Status status = createStatus();
		Issuer responseIssuer = null;
		Issuer assertionIssuer = null;
		Subject subject = null;
		AttributeStatement attributeStatement = null;
		
		if (issuer != null) {
			responseIssuer = createIssuer(issuer);
			assertionIssuer = createIssuer(issuer);
		}
		
		if (subjectId != null) {
			subject = createSubject(subjectId, samlAssertionDays);
		}
		
		if (attributes != null && attributes.size() != 0) {
			attributeStatement = createAttributeStatement(attributes);
		}
		
		AuthnStatement authnStatement = createAuthnStatement(authenticationTime);
		
		Assertion assertion = createAssertion(new DateTime(), subject, assertionIssuer, authnStatement, attributeStatement);
		
		Response response = createResponse(new DateTime(), responseIssuer, status, assertion);
		response.setSignature(signature);
		
		ResponseMarshaller marshaller = new ResponseMarshaller();
		Element element = marshaller.marshall(response);
		
		if (signature != null) {
			Signer.signObject(signature);
		}
		
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		XMLHelper.writeNode(element, baos);
	
		return response;
		
	} catch (Throwable t) {
		t.printStackTrace();
		return null;
	}
}
 
Example #16
Source File: StatusSchemaValidator.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public void validate(Status status) throws ValidationException {
    validateStatusCode(status);

}
 
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: StatusResponseTypeImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public void setStatus(Status newStatus) {
    this.status = prepareForAssignment(this.status, newStatus);
}
 
Example #19
Source File: StatusResponseTypeImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public Status getStatus() {
    return this.status;
}
 
Example #20
Source File: StatusBuilder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public Status buildObject(String namespaceURI, String localName, String namespacePrefix) {
    return new StatusImpl(namespaceURI, localName, namespacePrefix);
}
 
Example #21
Source File: StatusBuilder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public Status buildObject() {
    return buildObject(SAMLConstants.SAML20P_NS, Status.DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML20P_PREFIX);
}
 
Example #22
Source File: StatusSchemaValidator.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected void validateStatusCode(Status status) throws ValidationException {
    if (status.getStatusCode() == null) {
        throw new ValidationException("StatusCode is required");
    }
}
 
Example #23
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;
}