Search in sources :

Example 6 with LogoutSecurityException

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

the class LogoutMessageImpl method extractRequest.

private LogoutWrapper<LogoutRequest> extractRequest(String samlObject) throws LogoutSecurityException, XMLStreamException {
    try {
        Document requestDoc = StaxUtils.read(new ByteArrayInputStream(samlObject.getBytes(StandardCharsets.UTF_8)));
        XMLObject requestXmlObject = OpenSAMLUtil.fromDom(requestDoc.getDocumentElement());
        if (LogoutRequest.class.isAssignableFrom(requestXmlObject.getClass())) {
            return new LogoutWrapperImpl<>((LogoutRequest) requestXmlObject);
        }
        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)

Example 7 with LogoutSecurityException

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

the class LogoutMessageImpl method signSamlGet.

private URI signSamlGet(LogoutWrapper samlObject, URI target, String relayState, String requestType) throws LogoutSecurityException, SignatureException, IOException {
    try {
        Document doc = DOMUtils.createDocument();
        doc.appendChild(doc.createElement("root"));
        SamlSecurity samlSecurity = new SamlSecurity();
        String encodedResponse = URLEncoder.encode(samlSecurity.deflateAndBase64Encode(DOM2Writer.nodeToString(OpenSAMLUtil.toDom((XMLObject) samlObject.getMessage(), doc, false))), "UTF-8");
        String requestToSign = String.format("%s=%s&%s=%s", requestType, encodedResponse, SSOConstants.RELAY_STATE, relayState);
        UriBuilder uriBuilder = UriBuilder.fromUri(target);
        uriBuilder.queryParam(requestType, encodedResponse);
        uriBuilder.queryParam(SSOConstants.RELAY_STATE, relayState);
        new SimpleSign(systemCrypto).signUriString(requestToSign, uriBuilder);
        return uriBuilder.build();
    } catch (WSSecurityException e) {
        throw new LogoutSecurityException(e);
    }
}
Also used : XMLObject(org.opensaml.core.xml.XMLObject) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) Document(org.w3c.dom.Document) SamlSecurity(org.codice.ddf.security.jaxrs.impl.SamlSecurity) UriBuilder(javax.ws.rs.core.UriBuilder) 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