AutomaticSAMLEntry extends WssEntryBase { public void process(WSSecHeader secHeader, Document doc, PropertyExpansionContext context) { try { SAMLParms samlParms = new SAMLParms(); SAMLCallbackHandler callbackHandler = null; if (!signed) { WSSecSAMLToken wsSecSAMLToken = new WSSecSAMLToken(); if (samlVersion.equals(SAML_VERSION_1)) { callbackHandler = new SAML1CallbackHandler(assertionType, confirmationMethod); } else if (samlVersion.equals(SAML_VERSION_2)) { callbackHandler = new SAML2CallbackHandler(assertionType, confirmationMethod); } else { throw new IllegalArgumentException(NOT_A_VALID_SAML_VERSION); } AssertionWrapper assertion = createAssertion(context, samlParms, callbackHandler); wsSecSAMLToken.build(doc, assertion, secHeader); } else { WSSecSignatureSAML wsSecSignatureSAML = new WSSecSignatureSAML(); WssCrypto wssCrypto = getWssContainer().getCryptoByName(crypto, true); String alias = context.expand(getUsername()); if (wssCrypto == null) { throw new RuntimeException("Missing keystore [" + crypto + "] for signature entry"); } else if (Strings.isNullOrEmpty(alias)) { throw new RuntimeException(" No alias was provided for the keystore '" + crypto + "'. Please check your SAML (Form) configurations"); } if (samlVersion.equals(SAML_VERSION_1)) { callbackHandler = new SAML1CallbackHandler(wssCrypto.getCrypto(), alias, assertionType, confirmationMethod); } else if (samlVersion.equals(SAML_VERSION_2)) { callbackHandler = new SAML2CallbackHandler(wssCrypto.getCrypto(), alias, assertionType, confirmationMethod); } else { throw new IllegalArgumentException(NOT_A_VALID_SAML_VERSION); } AssertionWrapper assertion = createAssertion(context, samlParms, callbackHandler); assertion.signAssertion(context.expand(getUsername()), context.expand(getPassword()), wssCrypto.getCrypto(), false); wsSecSignatureSAML.setUserInfo(context.expand(getUsername()), context.expand(getPassword())); if (confirmationMethod.equals(SENDER_VOUCHES_CONFIRMATION_METHOD)) { wsSecSignatureSAML.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE); wsSecSignatureSAML.build(doc, null, assertion, wssCrypto.getCrypto(), context.expand(getUsername()), context.expand(getPassword()), secHeader); } else if (confirmationMethod.equals(HOLDER_OF_KEY_CONFIRMATION_METHOD)) { wsSecSignatureSAML.setDigestAlgo(digestAlgorithm); if (assertionType.equals(AUTHENTICATION_ASSERTION_TYPE)) { wsSecSignatureSAML.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE); wsSecSignatureSAML.setSignatureAlgorithm(signatureAlgorithm); } else if (assertionType.equals(ATTRIBUTE_ASSERTION_TYPE)) { wsSecSignatureSAML.setKeyIdentifierType(WSConstants.X509_KEY_IDENTIFIER); wsSecSignatureSAML.setSignatureAlgorithm(signatureAlgorithm); byte[] ephemeralKey = callbackHandler.getEphemeralKey(); wsSecSignatureSAML.setSecretKey(ephemeralKey); } wsSecSignatureSAML.build(doc, wssCrypto.getCrypto(), assertion, null, null, null, secHeader); } } } catch (Exception e) { SoapUI.logError(e); } }  void init(WSSEntryConfig config, OutgoingWss container); void process(WSSecHeader secHeader, Document doc, PropertyExpansionContext context); void relase(); String getSamlVersion(); void setSamlVersion(String samlVersion); String getAssertionType(); void setAssertionType(String assertionType); String getConfirmationMethod(); void setConfirmationMethod(String confirmationMethod); String getIssuer(); void setIssuer(String issuer); String getCrypto(); void setCrypto(String crypto); String getSubjectName(); void setSubjectName(String subjectName); String getSubjectQualifier(); void setSubjectQualifier(String subjectQualifier); String getDigestAlgorithm(); void setDigestAlgorithm(String digestAlgorithm); String getSignatureAlgorithm(); void setSignatureAlgorithm(String signatureAlgorithm); boolean isSigned(); void setSigned(boolean signed); String getAttributeName(); void setAttributeName(String attributeName); List<StringToStringMap> getAttributeValues(); void setAttributeValues(List<StringToStringMap> attributeValues); static final String TYPE; static final String SAML_VERSION_1; static final String SAML_VERSION_2; static final String AUTHENTICATION_ASSERTION_TYPE; static final String ATTRIBUTE_ASSERTION_TYPE; static final String AUTHORIZATION_ASSERTION_TYPE; static final String ATTRIBUTE_VALUES_VALUE_COLUMN; static final String HOLDER_OF_KEY_CONFIRMATION_METHOD; static final String SENDER_VOUCHES_CONFIRMATION_METHOD; }
@Test public void testProcessUnsignedSAML1AuthenticationAssertionUsingSenderVouches() throws WSSecurityException, XPathExpressionException { setRequiredFields(AutomaticSAMLEntry.SAML_VERSION_1, false, AutomaticSAMLEntry.AUTHENTICATION_ASSERTION_TYPE, AutomaticSAMLEntry.SENDER_VOUCHES_CONFIRMATION_METHOD); automaticSamlEntry.process(secHeader, doc, contextMock); assertEquals(xpath.evaluate(" SAML1Constants.CONF_SENDER_VOUCHES); assertNotNull(xpath.evaluate(" }
@Test public void testProcessUnsignedSAML2AuthenticationAssertionUsingSenderVouches() throws WSSecurityException, XPathExpressionException { setRequiredFields(AutomaticSAMLEntry.SAML_VERSION_2, false, AutomaticSAMLEntry.AUTHENTICATION_ASSERTION_TYPE, AutomaticSAMLEntry.SENDER_VOUCHES_CONFIRMATION_METHOD); automaticSamlEntry.process(secHeader, doc, contextMock); assertEquals(xpath.evaluate(" SAML2Constants.CONF_SENDER_VOUCHES); assertNotNull(xpath.evaluate(" }
@Test public void testProcessUnsignedSAML1AttributeAssertionUsingSenderVouches() throws WSSecurityException, XPathExpressionException { setRequiredFields(AutomaticSAMLEntry.SAML_VERSION_1, false, AutomaticSAMLEntry.ATTRIBUTE_ASSERTION_TYPE, AutomaticSAMLEntry.SENDER_VOUCHES_CONFIRMATION_METHOD); createAttribute(); automaticSamlEntry.process(secHeader, doc, contextMock); System.out.println(XmlUtils.serializePretty(doc)); assertEquals(xpath.evaluate(" SAML1Constants.CONF_SENDER_VOUCHES); assertNotNull(xpath.evaluate(" assertEquals( xpath.evaluate(" ATTTRIBUTE_NAME); assertEquals(xpath.evaluate(" XPathConstants.STRING), ATTTRIBUTE_VALUE); }
@Test public void testProcessUnsignedSAML2AttributeAssertionUsingSenderVouches() throws WSSecurityException, XPathExpressionException { setRequiredFields(AutomaticSAMLEntry.SAML_VERSION_2, false, AutomaticSAMLEntry.ATTRIBUTE_ASSERTION_TYPE, AutomaticSAMLEntry.SENDER_VOUCHES_CONFIRMATION_METHOD); createAttribute(); automaticSamlEntry.process(secHeader, doc, contextMock); System.out.println(XmlUtils.serializePretty(doc)); assertEquals(xpath.evaluate(" SAML2Constants.CONF_SENDER_VOUCHES); assertNotNull(xpath.evaluate(" assertEquals( xpath.evaluate(" ATTTRIBUTE_NAME); assertEquals(xpath.evaluate(" XPathConstants.STRING), ATTTRIBUTE_VALUE); }
@Test public void testProcessUnsignedSAML1AuthorizationAssertionUsingSenderVouches() throws WSSecurityException, XPathExpressionException { setRequiredFields(AutomaticSAMLEntry.SAML_VERSION_1, false, AutomaticSAMLEntry.AUTHORIZATION_ASSERTION_TYPE, AutomaticSAMLEntry.SENDER_VOUCHES_CONFIRMATION_METHOD); automaticSamlEntry.process(secHeader, doc, contextMock); assertEquals(xpath.evaluate(" SAML1Constants.CONF_SENDER_VOUCHES); assertNotNull(xpath.evaluate(" }
@Test public void testProcessUnsignedSAML2AuthorizationAssertionUsingSenderVouches() throws WSSecurityException, XPathExpressionException { setRequiredFields(AutomaticSAMLEntry.SAML_VERSION_2, false, AutomaticSAMLEntry.AUTHORIZATION_ASSERTION_TYPE, AutomaticSAMLEntry.SENDER_VOUCHES_CONFIRMATION_METHOD); automaticSamlEntry.process(secHeader, doc, contextMock); assertEquals(xpath.evaluate(" SAML2Constants.CONF_SENDER_VOUCHES); assertNotNull(xpath.evaluate(" }
@Test public void testProcessSignedSAML1AuthenticationAssertionUsingHolderOfKey() throws WSSecurityException, XPathExpressionException { setRequiredFields(AutomaticSAMLEntry.SAML_VERSION_1, true, AutomaticSAMLEntry.AUTHENTICATION_ASSERTION_TYPE, AutomaticSAMLEntry.HOLDER_OF_KEY_CONFIRMATION_METHOD); automaticSamlEntry.process(secHeader, doc, contextMock); System.err.println(XmlUtils.serializePretty(doc)); assertNotNull(xpath.evaluate(" assertEquals(xpath.evaluate(" SAML1Constants.CONF_HOLDER_KEY); assertNotNull(xpath.evaluate(" }
@Test public void testProcessSignedSAML2AuthenticationAssertionUsingHolderOfKey() throws WSSecurityException, XPathExpressionException { setRequiredFields(AutomaticSAMLEntry.SAML_VERSION_2, true, AutomaticSAMLEntry.AUTHENTICATION_ASSERTION_TYPE, AutomaticSAMLEntry.HOLDER_OF_KEY_CONFIRMATION_METHOD); automaticSamlEntry.process(secHeader, doc, contextMock); assertNotNull(xpath.evaluate(" assertEquals(xpath.evaluate(" SAML2Constants.CONF_HOLDER_KEY); assertNotNull(xpath.evaluate(" }
@Test public void testProcessSignedSAML1AttributeAssertionUsingHolderOfKey() throws WSSecurityException, XPathExpressionException { setRequiredFields(AutomaticSAMLEntry.SAML_VERSION_1, true, AutomaticSAMLEntry.ATTRIBUTE_ASSERTION_TYPE, AutomaticSAMLEntry.HOLDER_OF_KEY_CONFIRMATION_METHOD); createAttribute(); automaticSamlEntry.process(secHeader, doc, contextMock); assertNotNull(xpath.evaluate(" assertEquals(xpath.evaluate(" SAML1Constants.CONF_HOLDER_KEY); assertNotNull(xpath.evaluate(" assertEquals( xpath.evaluate(" ATTTRIBUTE_NAME); assertEquals(xpath.evaluate(" XPathConstants.STRING), ATTTRIBUTE_VALUE); }
@Test public void testProcessSignedSAML2AttributeAssertionUsingHolderOfKey() throws WSSecurityException, XPathExpressionException { setRequiredFields(AutomaticSAMLEntry.SAML_VERSION_2, true, AutomaticSAMLEntry.ATTRIBUTE_ASSERTION_TYPE, AutomaticSAMLEntry.HOLDER_OF_KEY_CONFIRMATION_METHOD); createAttribute(); automaticSamlEntry.process(secHeader, doc, contextMock); assertNotNull(xpath.evaluate(" assertEquals(xpath.evaluate(" SAML2Constants.CONF_HOLDER_KEY); assertNotNull(xpath.evaluate(" assertEquals( xpath.evaluate(" ATTTRIBUTE_NAME); assertEquals(xpath.evaluate(" XPathConstants.STRING), ATTTRIBUTE_VALUE); }
@Test public void testProcessSignedSAML1AuthenticationAssertionUsingSenderVouces() throws WSSecurityException, XPathExpressionException { setRequiredFields(AutomaticSAMLEntry.SAML_VERSION_1, true, AutomaticSAMLEntry.AUTHENTICATION_ASSERTION_TYPE, AutomaticSAMLEntry.SENDER_VOUCHES_CONFIRMATION_METHOD); automaticSamlEntry.process(secHeader, doc, contextMock); assertNotNull(xpath.evaluate(" assertEquals(xpath.evaluate(" SAML1Constants.CONF_SENDER_VOUCHES); assertNotNull(xpath.evaluate(" }
@Test public void testProcessSignedSAML2AuthenticationAssertionUsingSenderVouches() throws WSSecurityException, XPathExpressionException { setRequiredFields(AutomaticSAMLEntry.SAML_VERSION_2, true, AutomaticSAMLEntry.AUTHENTICATION_ASSERTION_TYPE, AutomaticSAMLEntry.SENDER_VOUCHES_CONFIRMATION_METHOD); automaticSamlEntry.process(secHeader, doc, contextMock); assertNotNull(xpath.evaluate(" assertEquals(xpath.evaluate(" SAML2Constants.CONF_SENDER_VOUCHES); assertNotNull(xpath.evaluate(" }