Search in sources :

Example 1 with SimpleSign

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

the class IdpEndpoint method validatePost.

void validatePost(HttpServletRequest request, SignableSAMLObject samlObject, String requestId) throws ValidationException {
    if (strictSignature) {
        SamlValidator.Builder validator = new SamlValidator.Builder(new SimpleSign(systemCrypto));
        if (requestId != null) {
            validator.setRequestId(requestId);
        }
        validator.buildAndValidate(request.getRequestURL().toString(), SamlProtocol.Binding.HTTP_POST, samlObject);
    }
}
Also used : SimpleSign(ddf.security.samlp.SimpleSign) UriBuilder(javax.ws.rs.core.UriBuilder) RequestBuilder(ddf.security.liberty.paos.impl.RequestBuilder) ResponseBuilder(ddf.security.liberty.paos.impl.ResponseBuilder) SamlValidator(ddf.security.samlp.impl.SamlValidator)

Example 2 with SimpleSign

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

the class IdpEndpoint method getSamlPostResponse.

private Response getSamlPostResponse(SignableSAMLObject samlObject, String targetUrl, String relayState, SamlProtocol.Type samlType) throws SimpleSign.SignatureException, WSSecurityException {
    Document doc = DOMUtils.createDocument();
    doc.appendChild(doc.createElement("root"));
    LOGGER.debug("Signing SAML POST Response.");
    new SimpleSign(systemCrypto).signSamlObject(samlObject);
    LOGGER.debug("Converting SAML Response to DOM");
    String assertionResponse = DOM2Writer.nodeToString(OpenSAMLUtil.toDom(samlObject, doc));
    String encodedSamlResponse = Base64.getEncoder().encodeToString(assertionResponse.getBytes(StandardCharsets.UTF_8));
    return Response.ok(HtmlResponseTemplate.getPostPage(targetUrl, samlType, encodedSamlResponse, relayState)).build();
}
Also used : SimpleSign(ddf.security.samlp.SimpleSign) Document(org.w3c.dom.Document)

Example 3 with SimpleSign

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

the class LogoutMessageImpl method signSamlGet.

private URI signSamlGet(@NotNull SAMLObject samlObject, @NotNull URI target, String relayState, @NotNull String requestType) throws WSSecurityException, SimpleSign.SignatureException, IOException {
    Document doc = DOMUtils.createDocument();
    doc.appendChild(doc.createElement("root"));
    String encodedResponse = URLEncoder.encode(RestSecurity.deflateAndBase64Encode(DOM2Writer.nodeToString(OpenSAMLUtil.toDom(samlObject, 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();
}
Also used : SimpleSign(ddf.security.samlp.SimpleSign) Document(org.w3c.dom.Document) UriBuilder(javax.ws.rs.core.UriBuilder)

Example 4 with SimpleSign

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

the class TestAttributeQueryClaimsHandler method setUp.

@Before
public void setUp() throws IOException {
    signatureProperties = mock(Object.class);
    encryptionProperties = mock(Object.class);
    service = mock(Service.class);
    dispatch = (Dispatch<StreamSource>) mock(Dispatch.class);
    encryptionService = mock(EncryptionService.class);
    systemCrypto = new SystemCrypto("encryption.properties", "signature.properties", encryptionService);
    simpleSign = new SimpleSign(systemCrypto);
    supportedClaims = new ArrayList<>();
    supportedClaims.add("Role");
    supportedClaims.add("NameIdentifier");
    supportedClaims.add("Email");
    AttributeQueryClaimsHandlerTest attributeQueryClaimsHandler = new AttributeQueryClaimsHandlerTest();
    spyAttributeQueryClaimsHandler = spy(attributeQueryClaimsHandler);
    spyAttributeQueryClaimsHandler.setWsdlLocation("wsdlLocation");
    spyAttributeQueryClaimsHandler.setServiceName("serviceName");
    spyAttributeQueryClaimsHandler.setPortName("portName");
    spyAttributeQueryClaimsHandler.setSimpleSign(simpleSign);
    spyAttributeQueryClaimsHandler.setSupportedClaims(supportedClaims);
    spyAttributeQueryClaimsHandler.setExternalAttributeStoreUrl(EXTERNAL_ATTRIBUTE_STORE);
    spyAttributeQueryClaimsHandler.setIssuer(ISSUER);
    spyAttributeQueryClaimsHandler.setDestination(DESTINATION);
    spyAttributeQueryClaimsHandler.setAttributeMapLocation(getClass().getClassLoader().getResource("attributeMap.properties").getPath());
    spyAttributeQueryClaimsHandler.setSignatureProperties(signatureProperties);
    spyAttributeQueryClaimsHandler.setEncryptionProperties(encryptionProperties);
    doReturn(service).when(spyAttributeQueryClaimsHandler).createService();
    doReturn(dispatch).when(spyAttributeQueryClaimsHandler).createDispatcher(service);
    cannedResponse = Resources.toString(Resources.getResource(getClass(), "/SAMLResponse.xml"), Charsets.UTF_8);
}
Also used : SimpleSign(ddf.security.samlp.SimpleSign) SystemCrypto(ddf.security.samlp.SystemCrypto) EncryptionService(ddf.security.encryption.EncryptionService) StreamSource(javax.xml.transform.stream.StreamSource) Service(javax.xml.ws.Service) EncryptionService(ddf.security.encryption.EncryptionService) XMLObject(org.opensaml.core.xml.XMLObject) Before(org.junit.Before)

Example 5 with SimpleSign

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

the class TestAttributeQueryClient method setUp.

@Before
public void setUp() throws IOException {
    dispatch = mock(Dispatch.class);
    encryptionService = mock(EncryptionService.class);
    systemCrypto = new SystemCrypto("encryption.properties", "signature.properties", encryptionService);
    SimpleSign simpleSign = new SimpleSign(systemCrypto);
    spySimpleSign = spy(simpleSign);
    attributeQueryClient = new AttributeQueryClient(dispatch, spySimpleSign, EXTERNAL_ATTRIBUTE_STORE, ISSUER, DESTINATION);
    attributeQueryClient.setDispatch(dispatch);
    attributeQueryClient.setSimpleSign(spySimpleSign);
    attributeQueryClient.setExternalAttributeStoreUrl(EXTERNAL_ATTRIBUTE_STORE);
    attributeQueryClient.setIssuer(ISSUER);
    attributeQueryClient.setDestination(DESTINATION);
    cannedResponse = Resources.toString(Resources.getResource(getClass(), "/SAMLResponse.xml"), Charsets.UTF_8);
}
Also used : SimpleSign(ddf.security.samlp.SimpleSign) SystemCrypto(ddf.security.samlp.SystemCrypto) EncryptionService(ddf.security.encryption.EncryptionService) Dispatch(javax.xml.ws.Dispatch) Before(org.junit.Before)

Aggregations

SimpleSign (ddf.security.samlp.SimpleSign)7 EncryptionService (ddf.security.encryption.EncryptionService)3 SystemCrypto (ddf.security.samlp.SystemCrypto)3 UriBuilder (javax.ws.rs.core.UriBuilder)3 Before (org.junit.Before)3 Document (org.w3c.dom.Document)3 SessionFactory (ddf.security.http.SessionFactory)1 RequestBuilder (ddf.security.liberty.paos.impl.RequestBuilder)1 ResponseBuilder (ddf.security.liberty.paos.impl.ResponseBuilder)1 SamlValidator (ddf.security.samlp.impl.SamlValidator)1 Filter (javax.servlet.Filter)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 StreamSource (javax.xml.transform.stream.StreamSource)1 Dispatch (javax.xml.ws.Dispatch)1 Service (javax.xml.ws.Service)1 XMLObject (org.opensaml.core.xml.XMLObject)1