Search in sources :

Example 6 with SAML2Config

use of org.forgerock.openam.sts.config.user.SAML2Config in project OpenAM by OpenRock.

the class SAML2TokenGenerationImplTest method getRestSTSInstanceConfig.

private RestSTSInstanceConfig getRestSTSInstanceConfig(boolean signAssertion) throws UnsupportedEncodingException {
    Map<String, String> context = new HashMap<>();
    context.put(AMSTSConstants.OPEN_ID_CONNECT_ID_TOKEN_AUTH_TARGET_HEADER_KEY, "oidc_id_token");
    AuthTargetMapping mapping = AuthTargetMapping.builder().addMapping(TokenType.USERNAME, "service", "ldapService").addMapping(TokenType.OPENIDCONNECT, "module", "oidc", context).build();
    DeploymentConfig deploymentConfig = DeploymentConfig.builder().uriElement("boborealm/inst1").authTargetMapping(mapping).build();
    Map<String, String> attributes = new HashMap<>();
    attributes.put("email", "mail");
    SAML2Config saml2Config = SAML2Config.builder().attributeMap(attributes).nameIdFormat("urn:oasis:names:tc:SAML:2.0:nameid-format:persistent").spEntityId("http://host.com/sp/entity/id").signAssertion(signAssertion).keystoreFile("/keystore.jks").keystorePassword("changeit".getBytes(AMSTSConstants.UTF_8_CHARSET_ID)).encryptionKeyAlias("test").signatureKeyAlias("test").signatureKeyPassword("changeit".getBytes(AMSTSConstants.UTF_8_CHARSET_ID)).idpId("da_idp").build();
    return RestSTSInstanceConfig.builder().deploymentConfig(deploymentConfig).saml2Config(saml2Config).addSupportedTokenTransform(TokenType.X509, TokenType.SAML2, !AMSTSConstants.INVALIDATE_INTERIM_OPENAM_SESSION).addSupportedTokenTransform(TokenType.USERNAME, TokenType.SAML2, AMSTSConstants.INVALIDATE_INTERIM_OPENAM_SESSION).addSupportedTokenTransform(TokenType.OPENAM, TokenType.SAML2, !AMSTSConstants.INVALIDATE_INTERIM_OPENAM_SESSION).addSupportedTokenTransform(TokenType.OPENIDCONNECT, TokenType.SAML2, AMSTSConstants.INVALIDATE_INTERIM_OPENAM_SESSION).build();
}
Also used : SAML2Config(org.forgerock.openam.sts.config.user.SAML2Config) HashMap(java.util.HashMap) AuthTargetMapping(org.forgerock.openam.sts.config.user.AuthTargetMapping) DeploymentConfig(org.forgerock.openam.sts.config.user.DeploymentConfig)

Example 7 with SAML2Config

use of org.forgerock.openam.sts.config.user.SAML2Config in project OpenAM by OpenRock.

the class RestSTSInstanceConfig method marshalFromAttributeMap.

/*
    When we are marshaling back from a Map<String, Set<String>>, this Map contains all of the values, also those
    contributed by encapsulated complex objects. So the structure must be 'un-flattened', where the top-level map
    is passed to encapsulated complex-objects, so that they may re-constitute themselves, and then the top-level json entry
    key is set to point at these re-constituted complex objects.

    Not that the marshalToAttributeMap first calls toJson to obtain the map representation, albeit with hierarchical
    elements, which must be subsequently flattened. The 'flattening' performed by the marshalToAttributeMap must then
     be 'inverted' by this method, where all complex objects are re-constituted, using the state in the flattened map.

     */
public static RestSTSInstanceConfig marshalFromAttributeMap(Map<String, Set<String>> attributeMap) {
    DeploymentConfig deploymentConfig = DeploymentConfig.marshalFromAttributeMap(attributeMap);
    Map<String, Object> jsonAttributes = MapMarshallUtils.toJsonValueMap(attributeMap);
    jsonAttributes.remove(DEPLOYMENT_CONFIG);
    jsonAttributes.put(DEPLOYMENT_CONFIG, deploymentConfig.toJson());
    SAML2Config saml2Config = SAML2Config.marshalFromAttributeMap(attributeMap);
    if (saml2Config != null) {
        jsonAttributes.remove(SAML2_CONFIG);
        jsonAttributes.put(SAML2_CONFIG, saml2Config.toJson());
    }
    OpenIdConnectTokenConfig openIdConnectTokenConfig = OpenIdConnectTokenConfig.marshalFromAttributeMap(attributeMap);
    if (openIdConnectTokenConfig != null) {
        jsonAttributes.remove(OIDC_ID_TOKEN_CONFIG);
        jsonAttributes.put(OIDC_ID_TOKEN_CONFIG, openIdConnectTokenConfig.toJson());
    }
    /*
         The SUPPORTED_TOKEN_TRANSFORMS, CUSTOM_TOKEN_TRANSFORMS, CUSTOM_TOKEN_VALIDATORS, and CUSTOM_TOKEN_PROVIDERS
          are currently each in a String representation in the Set<String> map entry corresponding
         to their respective key. I need to marshal each back into a TokenTransformConfig instance, and then
         call toJson on each, and put them in a JsonValue wrapping a list.
         */
    ArrayList<JsonValue> jsonTranslationsList = new ArrayList<>();
    JsonValue jsonTranslations = new JsonValue(jsonTranslationsList);
    jsonAttributes.remove(SUPPORTED_TOKEN_TRANSFORMS);
    jsonAttributes.put(SUPPORTED_TOKEN_TRANSFORMS, jsonTranslations);
    Set<String> stringTokenTranslations = attributeMap.get(SUPPORTED_TOKEN_TRANSFORMS);
    for (String translation : stringTokenTranslations) {
        jsonTranslationsList.add(TokenTransformConfig.fromSMSString(translation).toJson());
    }
    ArrayList<JsonValue> jsonCustomTranslationsList = new ArrayList<>();
    JsonValue jsonCustomTranslations = new JsonValue(jsonCustomTranslationsList);
    jsonAttributes.remove(CUSTOM_TOKEN_TRANSFORMS);
    jsonAttributes.put(CUSTOM_TOKEN_TRANSFORMS, jsonCustomTranslations);
    Set<String> stringCustomTranslations = attributeMap.get(CUSTOM_TOKEN_TRANSFORMS);
    for (String translation : stringCustomTranslations) {
        jsonCustomTranslationsList.add(TokenTransformConfig.fromSMSString(translation).toJson());
    }
    ArrayList<JsonValue> jsonCustomValidatorsList = new ArrayList<>();
    JsonValue jsonCustomValidators = new JsonValue(jsonCustomValidatorsList);
    jsonAttributes.remove(CUSTOM_TOKEN_VALIDATORS);
    jsonAttributes.put(CUSTOM_TOKEN_VALIDATORS, jsonCustomValidators);
    Set<String> stringCustomValidators = attributeMap.get(CUSTOM_TOKEN_VALIDATORS);
    for (String validator : stringCustomValidators) {
        jsonCustomValidatorsList.add(CustomTokenOperation.fromSMSString(validator).toJson());
    }
    ArrayList<JsonValue> jsonCustomProvidersList = new ArrayList<>();
    JsonValue jsonCustomProviders = new JsonValue(jsonCustomProvidersList);
    jsonAttributes.remove(CUSTOM_TOKEN_PROVIDERS);
    jsonAttributes.put(CUSTOM_TOKEN_PROVIDERS, jsonCustomProviders);
    Set<String> stringCustomProviders = attributeMap.get(CUSTOM_TOKEN_PROVIDERS);
    for (String provider : stringCustomProviders) {
        jsonCustomProvidersList.add(CustomTokenOperation.fromSMSString(provider).toJson());
    }
    return fromJson(new JsonValue(jsonAttributes));
}
Also used : SAML2Config(org.forgerock.openam.sts.config.user.SAML2Config) JsonValue(org.forgerock.json.JsonValue) DeploymentConfig(org.forgerock.openam.sts.config.user.DeploymentConfig) OpenIdConnectTokenConfig(org.forgerock.openam.sts.config.user.OpenIdConnectTokenConfig)

Example 8 with SAML2Config

use of org.forgerock.openam.sts.config.user.SAML2Config in project OpenAM by OpenRock.

the class SoapSTSInstanceStateServiceListenerTest method createInstanceConfig.

private SoapSTSInstanceConfig createInstanceConfig(String amDeploymentUrl) throws UnsupportedEncodingException {
    AuthTargetMapping mapping = AuthTargetMapping.builder().addMapping(TokenType.USERNAME, "service", "ldap").build();
    SoapDeploymentConfig deploymentConfig = SoapDeploymentConfig.builder().portQName(AMSTSConstants.STANDARD_STS_PORT_QNAME).serviceQName(AMSTSConstants.STANDARD_STS_SERVICE_NAME).wsdlLocation("wsdl_loc").realm("realm").amDeploymentUrl(amDeploymentUrl).uriElement(DEPLOYMENT_URL_ELEMENT).authTargetMapping(mapping).build();
    SoapSTSKeystoreConfig keystoreConfig = SoapSTSKeystoreConfig.builder().keystoreFileName("stsstore.jks").keystorePassword("stsspass".getBytes(AMSTSConstants.UTF_8_CHARSET_ID)).encryptionKeyAlias("mystskey").signatureKeyAlias("mystskey").encryptionKeyPassword("stskpass".getBytes(AMSTSConstants.UTF_8_CHARSET_ID)).signatureKeyPassword("stskpass".getBytes(AMSTSConstants.UTF_8_CHARSET_ID)).build();
    Map<String, String> attributes = new HashMap<>();
    attributes.put("email", "mail");
    SAML2Config saml2Config = SAML2Config.builder().attributeMap(attributes).nameIdFormat("urn:oasis:names:tc:SAML:2.0:nameid-format:persistent").spEntityId("http://host.com/sp/entity/id").idpId("da_idp").build();
    SoapSTSInstanceConfig.SoapSTSInstanceConfigBuilderBase<?> builder = SoapSTSInstanceConfig.builder();
    builder.addSecurityPolicyTokenValidationConfiguration(TokenType.OPENAM, false);
    builder.addIssueTokenType(TokenType.SAML2);
    return builder.deploymentConfig(deploymentConfig).soapSTSKeystoreConfig(keystoreConfig).saml2Config(saml2Config).build();
}
Also used : SoapSTSKeystoreConfig(org.forgerock.openam.sts.soap.config.user.SoapSTSKeystoreConfig) SAML2Config(org.forgerock.openam.sts.config.user.SAML2Config) SoapSTSInstanceConfig(org.forgerock.openam.sts.soap.config.user.SoapSTSInstanceConfig) AuthTargetMapping(org.forgerock.openam.sts.config.user.AuthTargetMapping) HashMap(java.util.HashMap) SoapDeploymentConfig(org.forgerock.openam.sts.soap.config.user.SoapDeploymentConfig)

Example 9 with SAML2Config

use of org.forgerock.openam.sts.config.user.SAML2Config in project OpenAM by OpenRock.

the class StatementProviderImplTest method testCustomProvider.

@Test
public void testCustomProvider() throws TokenCreationException {
    SAML2Config config = SAML2Config.builder().customConditionsProviderClassName("org.forgerock.openam.sts.tokengeneration.saml2.statements.DefaultConditionsProvider").spEntityId("http://host.com/sp/entity/id").idpId("da_idp").build();
    StatementProvider statementProvider = Guice.createInjector(new MyModule()).getInstance(StatementProvider.class);
    assertTrue(statementProvider.getConditionsProvider(config) instanceof DefaultConditionsProvider);
}
Also used : SAML2Config(org.forgerock.openam.sts.config.user.SAML2Config) DefaultConditionsProvider(org.forgerock.openam.sts.tokengeneration.saml2.statements.DefaultConditionsProvider) Test(org.testng.annotations.Test)

Example 10 with SAML2Config

use of org.forgerock.openam.sts.config.user.SAML2Config in project OpenAM by OpenRock.

the class StatementProviderImplTest method testSpeciousProvider.

@Test(expectedExceptions = TokenCreationException.class)
public void testSpeciousProvider() throws TokenCreationException {
    SAML2Config config = SAML2Config.builder().customConditionsProviderClassName("faux_class_name").spEntityId("http://host.com/sp/entity/id").idpId("da_idp").build();
    StatementProvider statementProvider = Guice.createInjector(new MyModule()).getInstance(StatementProvider.class);
    statementProvider.getConditionsProvider(config);
}
Also used : SAML2Config(org.forgerock.openam.sts.config.user.SAML2Config) Test(org.testng.annotations.Test)

Aggregations

SAML2Config (org.forgerock.openam.sts.config.user.SAML2Config)16 HashMap (java.util.HashMap)9 AuthTargetMapping (org.forgerock.openam.sts.config.user.AuthTargetMapping)9 DeploymentConfig (org.forgerock.openam.sts.config.user.DeploymentConfig)6 OpenIdConnectTokenConfig (org.forgerock.openam.sts.config.user.OpenIdConnectTokenConfig)5 SoapDeploymentConfig (org.forgerock.openam.sts.soap.config.user.SoapDeploymentConfig)4 SoapSTSKeystoreConfig (org.forgerock.openam.sts.soap.config.user.SoapSTSKeystoreConfig)4 SoapSTSInstanceConfig (org.forgerock.openam.sts.soap.config.user.SoapSTSInstanceConfig)3 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)2 HashSet (java.util.HashSet)2 JsonValue (org.forgerock.json.JsonValue)2 TokenCreationException (org.forgerock.openam.sts.TokenCreationException)2 Test (org.testng.annotations.Test)2 Assertion (com.sun.identity.saml2.assertion.Assertion)1 EncryptedAssertion (com.sun.identity.saml2.assertion.EncryptedAssertion)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 PrivateKey (java.security.PrivateKey)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 QName (javax.xml.namespace.QName)1