Search in sources :

Example 1 with LogoutSecurityException

use of ddf.security.samlp.LogoutSecurityException in project ddf by codice.

the class LogoutRequestService method getSamlpRedirectLogoutRequest.

private Response getSamlpRedirectLogoutRequest(String relayState, LogoutWrapper<LogoutRequest> logoutRequest) throws IOException, SignatureException, LogoutSecurityException, URISyntaxException {
    LOGGER.debug("Configuring SAML Response for Redirect.");
    Document doc = DOMUtils.createDocument();
    doc.appendChild(doc.createElement(ROOT_NODE_NAME));
    if (logoutMessage == null) {
        throw new LogoutSecurityException("Logout message not ready yet.");
    }
    URI location = logoutMessage.signSamlGetRequest(logoutRequest, new URI(idpMetadata.getSingleLogoutLocation()), relayState);
    String redirectUpdated = String.format(redirectPage, location.toString());
    Response.ResponseBuilder ok = Response.ok(redirectUpdated);
    return ok.build();
}
Also used : Response(javax.ws.rs.core.Response) LogoutResponse(org.opensaml.saml.saml2.core.LogoutResponse) Document(org.w3c.dom.Document) URI(java.net.URI) LogoutSecurityException(ddf.security.samlp.LogoutSecurityException)

Example 2 with LogoutSecurityException

use of ddf.security.samlp.LogoutSecurityException in project ddf by codice.

the class LogoutRequestService method getSamlpRedirectLogoutResponse.

private Response getSamlpRedirectLogoutResponse(String relayState, LogoutWrapper<LogoutResponse> samlResponse) throws IOException, SignatureException, LogoutSecurityException, URISyntaxException {
    LOGGER.debug("Configuring SAML Response for Redirect.");
    Document doc = DOMUtils.createDocument();
    doc.appendChild(doc.createElement(ROOT_NODE_NAME));
    if (logoutMessage == null) {
        throw new LogoutSecurityException("Logout message is not ready yet.");
    }
    URI location = logoutMessage.signSamlGetResponse(samlResponse, new URI(idpMetadata.getSingleLogoutLocation()), relayState);
    return Response.ok(HtmlResponseTemplate.getRedirectPage(location.toString())).build();
}
Also used : Document(org.w3c.dom.Document) URI(java.net.URI) LogoutSecurityException(ddf.security.samlp.LogoutSecurityException)

Example 3 with LogoutSecurityException

use of ddf.security.samlp.LogoutSecurityException in project ddf by codice.

the class LogoutMessageImpl method extractXmlObject.

@Override
public LogoutWrapper<SignableSAMLObject> extractXmlObject(String samlLogoutResponse) throws LogoutSecurityException, XMLStreamException {
    try {
        Document responseDoc = StaxUtils.read(new ByteArrayInputStream(samlLogoutResponse.getBytes(StandardCharsets.UTF_8)));
        XMLObject xmlObject = OpenSAMLUtil.fromDom(responseDoc.getDocumentElement());
        if (xmlObject instanceof SignableSAMLObject) {
            return new LogoutWrapperImpl<>((SignableSAMLObject) xmlObject);
        }
        return null;
    } catch (WSSecurityException e) {
        throw new LogoutSecurityException(e);
    }
}
Also used : SignableSAMLObject(org.opensaml.saml.common.SignableSAMLObject) ByteArrayInputStream(java.io.ByteArrayInputStream) XMLObject(org.opensaml.core.xml.XMLObject) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) Document(org.w3c.dom.Document) LogoutSecurityException(ddf.security.samlp.LogoutSecurityException)

Example 4 with LogoutSecurityException

use of ddf.security.samlp.LogoutSecurityException in project ddf by codice.

the class LogoutMessageImpl method getElementFromSaml.

@Override
public Element getElementFromSaml(LogoutWrapper xmlObject) throws LogoutSecurityException {
    try {
        Document doc = DOMUtils.createDocument();
        doc.appendChild(doc.createElement("root"));
        return OpenSAMLUtil.toDom((XMLObject) xmlObject.getMessage(), doc);
    } catch (WSSecurityException e) {
        throw new LogoutSecurityException(e);
    }
}
Also used : WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) Document(org.w3c.dom.Document) LogoutSecurityException(ddf.security.samlp.LogoutSecurityException)

Example 5 with LogoutSecurityException

use of ddf.security.samlp.LogoutSecurityException in project ddf by codice.

the class LogoutMessageImpl method extractResponse.

private LogoutWrapper<LogoutResponse> extractResponse(String samlObject) throws LogoutSecurityException, XMLStreamException {
    try {
        Document responseDoc = StaxUtils.read(new ByteArrayInputStream(samlObject.getBytes(StandardCharsets.UTF_8)));
        XMLObject responseXmlObject = OpenSAMLUtil.fromDom(responseDoc.getDocumentElement());
        if (LogoutResponse.class.isAssignableFrom(responseXmlObject.getClass())) {
            return new LogoutWrapperImpl<>((LogoutResponse) responseXmlObject);
        }
        return null;
    } catch (WSSecurityException e) {
        throw new LogoutSecurityException(e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) XMLObject(org.opensaml.core.xml.XMLObject) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) Document(org.w3c.dom.Document) LogoutSecurityException(ddf.security.samlp.LogoutSecurityException)

Aggregations

LogoutSecurityException (ddf.security.samlp.LogoutSecurityException)7 Document (org.w3c.dom.Document)7 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)5 XMLObject (org.opensaml.core.xml.XMLObject)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 URI (java.net.URI)2 Response (javax.ws.rs.core.Response)1 UriBuilder (javax.ws.rs.core.UriBuilder)1 SamlSecurity (org.codice.ddf.security.jaxrs.impl.SamlSecurity)1 SignableSAMLObject (org.opensaml.saml.common.SignableSAMLObject)1 LogoutResponse (org.opensaml.saml.saml2.core.LogoutResponse)1