use of org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.StandardInboundProtocols.SAML2 in project product-is by wso2.
the class TestPassiveSTSFederation method updateServiceProviderWithSAMLConfigs.
private void updateServiceProviderWithSAMLConfigs(int portOffset, String issuerName, String acsUrl, ServiceProvider serviceProvider) throws Exception {
String attributeConsumingServiceIndex = super.createSAML2WebSSOConfiguration(portOffset, getSAMLSSOServiceProviderDTO(issuerName, acsUrl));
Assert.assertNotNull(attributeConsumingServiceIndex, "Failed to create SAML2 Web SSO configuration for issuer '" + issuerName + "'");
InboundAuthenticationRequestConfig samlAuthenticationRequestConfig = new InboundAuthenticationRequestConfig();
samlAuthenticationRequestConfig.setInboundAuthKey(issuerName);
samlAuthenticationRequestConfig.setInboundAuthType(INBOUND_AUTH_TYPE);
org.wso2.carbon.identity.application.common.model.xsd.Property property = new org.wso2.carbon.identity.application.common.model.xsd.Property();
property.setName("attrConsumServiceIndex");
property.setValue(attributeConsumingServiceIndex);
samlAuthenticationRequestConfig.setProperties(new org.wso2.carbon.identity.application.common.model.xsd.Property[] { property });
serviceProvider.getInboundAuthenticationConfig().setInboundAuthenticationRequestConfigs(new InboundAuthenticationRequestConfig[] { samlAuthenticationRequestConfig });
}
use of org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.StandardInboundProtocols.SAML2 in project product-is by wso2.
the class TestPassiveSTSFederation method testCreateServiceProviderInPrimaryIS.
@Test(groups = "wso2.is", description = "Check create service provider in primary IS", dependsOnMethods = { "testCreateIdentityProviderInPrimaryIS" })
public void testCreateServiceProviderInPrimaryIS() throws Exception {
super.addServiceProvider(PORT_OFFSET_0, PRIMARY_IS_SERVICE_PROVIDER_NAME);
ServiceProvider serviceProvider = getServiceProvider(PORT_OFFSET_0, PRIMARY_IS_SERVICE_PROVIDER_NAME);
Assert.assertNotNull(serviceProvider, "Failed to create service provider 'travelocity' in primary IS");
updateServiceProviderWithSAMLConfigs(PORT_OFFSET_0, PRIMARY_IS_SAML_ISSUER_NAME, PRIMARY_IS_SAML_ACS_URL, serviceProvider);
AuthenticationStep authStep = new AuthenticationStep();
org.wso2.carbon.identity.application.common.model.xsd.IdentityProvider idP = new org.wso2.carbon.identity.application.common.model.xsd.IdentityProvider();
idP.setIdentityProviderName(IDENTITY_PROVIDER_NAME);
org.wso2.carbon.identity.application.common.model.xsd.FederatedAuthenticatorConfig saml2SSOAuthnConfig = new org.wso2.carbon.identity.application.common.model.xsd.FederatedAuthenticatorConfig();
saml2SSOAuthnConfig.setName("SAMLSSOAuthenticator");
saml2SSOAuthnConfig.setDisplayName("samlsso");
idP.setFederatedAuthenticatorConfigs(new org.wso2.carbon.identity.application.common.model.xsd.FederatedAuthenticatorConfig[] { saml2SSOAuthnConfig });
authStep.setFederatedIdentityProviders(new org.wso2.carbon.identity.application.common.model.xsd.IdentityProvider[] { idP });
serviceProvider.getLocalAndOutBoundAuthenticationConfig().setAuthenticationSteps(new AuthenticationStep[] { authStep });
serviceProvider.getLocalAndOutBoundAuthenticationConfig().setAuthenticationType(AUTHENTICATION_TYPE);
updateServiceProvider(PORT_OFFSET_0, serviceProvider);
serviceProvider = getServiceProvider(PORT_OFFSET_0, PRIMARY_IS_SERVICE_PROVIDER_NAME);
InboundAuthenticationRequestConfig[] configs = serviceProvider.getInboundAuthenticationConfig().getInboundAuthenticationRequestConfigs();
boolean success = false;
if (configs != null) {
for (InboundAuthenticationRequestConfig config : configs) {
if (PRIMARY_IS_SAML_ISSUER_NAME.equals(config.getInboundAuthKey()) && INBOUND_AUTH_TYPE.equals(config.getInboundAuthType())) {
success = true;
break;
}
}
}
Assert.assertTrue(success, "Failed to update service provider with inbound SAML2 configs " + "in primary IS");
}
use of org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.StandardInboundProtocols.SAML2 in project product-is by wso2.
the class SAML2SSOTestBase method extractAndProcessSAMLResponse.
/**
* Get SAML response object from the HTTP response.
*
* @param response HTTP response
* @return SAML response instance.
* @throws Exception
*/
public Response extractAndProcessSAMLResponse(HttpResponse response) throws Exception {
String encodedSAML2ResponseString = extractSAMLResponse(response);
EntityUtils.consume(response.getEntity());
String saml2ResponseString = new String(Base64.decode(encodedSAML2ResponseString), Charset.forName(StandardCharsets.UTF_8.name()));
XMLObject samlResponse = unmarshall(saml2ResponseString);
// Check for duplicate samlp:Response
NodeList list = samlResponse.getDOM().getElementsByTagNameNS(SAMLConstants.SAML20P_NS, RESPONSE_TAG_NAME);
if (list.getLength() > 0) {
log.error("Invalid schema for the SAML2 response. Multiple Response elements found.");
throw new Exception("Error occurred while processing SAML2 response.");
}
// Checking for multiple Assertions
NodeList assertionList = samlResponse.getDOM().getElementsByTagNameNS(SAMLConstants.SAML20_NS, ASSERTION_TAG_NAME);
if (assertionList.getLength() > 1) {
log.error("Invalid schema for the SAML2 response. Multiple Assertion elements found.");
throw new Exception("Error occurred while processing SAML2 response.");
}
return (Response) samlResponse;
}
use of org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.StandardInboundProtocols.SAML2 in project product-is by wso2.
the class SAML2SSOTestBase method getAssertionFromSAMLResponse.
/**
* Extract SAML Assertion from the SAML Response.
*
* @param samlResponse SAML Response.
* @param samlssoSPDTO SAMLSSO service Provider DTO.
* @param x509Credential x509Credential instance.
* @return SAML Response instance.
* @throws Exception
*/
public Assertion getAssertionFromSAMLResponse(Response samlResponse, SAMLSSOServiceProviderDTO samlssoSPDTO, X509Credential x509Credential) throws Exception {
Assertion assertion = null;
if (samlssoSPDTO.getDoEnableEncryptedAssertion()) {
List<EncryptedAssertion> encryptedAssertions = samlResponse.getEncryptedAssertions();
EncryptedAssertion encryptedAssertion = null;
if (!CollectionUtils.isEmpty(encryptedAssertions)) {
encryptedAssertion = encryptedAssertions.get(0);
try {
assertion = getDecryptedAssertion(encryptedAssertion, x509Credential);
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.debug("Assertion decryption failure : ", e);
}
throw new Exception("Unable to decrypt the SAML2 Assertion", e);
}
}
} else {
List<Assertion> assertions = samlResponse.getAssertions();
if (assertions != null && !assertions.isEmpty()) {
assertion = assertions.get(0);
}
}
if (assertion == null && !isNoPassive(samlResponse)) {
throw new Exception("SAML2 Assertion not found in the Response");
}
return assertion;
}
use of org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.StandardInboundProtocols.SAML2 in project product-is by wso2.
the class SAML2SSOTestBase method validateSignature.
private void validateSignature(XMLObject signature, X509Credential x509Credential) throws Exception {
SignatureImpl signImpl = (SignatureImpl) signature;
try {
SAMLSignatureProfileValidator signatureProfileValidator = new SAMLSignatureProfileValidator();
signatureProfileValidator.validate(signImpl);
} catch (ValidationException ex) {
String logMsg = "Signature do not confirm to SAML signature profile. Possible XML Signature " + "Wrapping Attack!";
if (log.isDebugEnabled()) {
log.debug(logMsg, ex);
}
throw new Exception(logMsg, ex);
}
try {
SignatureValidator validator = new SignatureValidator(x509Credential);
validator.validate(signImpl);
} catch (ValidationException e) {
if (log.isDebugEnabled()) {
log.debug("Validation exception : ", e);
}
throw new Exception("Signature validation failed for SAML2 Element");
}
}
Aggregations