Java Code Examples for org.keycloak.models.RealmModel#addComponentModel()
The following examples show how to use
org.keycloak.models.RealmModel#addComponentModel() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MigrateTo1_8_0.java From keycloak with Apache License 2.0 | 6 votes |
protected void migrateRealm(RealmModel realm) { List<UserStorageProviderModel> federationProviders = realm.getUserStorageProviders(); for (UserStorageProviderModel fedProvider : federationProviders) { if (fedProvider.getProviderId().equals(LDAPConstants.LDAP_PROVIDER)) { if (isActiveDirectory(fedProvider)) { // Create mapper for MSAD account controls if (getMapperByName(realm, fedProvider, "MSAD account controls") == null) { ComponentModel mapperModel = KeycloakModelUtils.createComponentModel("MSAD account controls", fedProvider.getId(), LDAPConstants.MSAD_USER_ACCOUNT_CONTROL_MAPPER, "org.keycloak.storage.ldap.mappers.LDAPStorageMapper"); realm.addComponentModel(mapperModel); } } } } }
Example 2
Source File: DefaultKeyProviders.java From keycloak with Apache License 2.0 | 6 votes |
public static void createProviders(RealmModel realm) { if (!hasProvider(realm, "rsa-generated")) { ComponentModel generated = new ComponentModel(); generated.setName("rsa-generated"); generated.setParentId(realm.getId()); generated.setProviderId("rsa-generated"); generated.setProviderType(KeyProvider.class.getName()); MultivaluedHashMap<String, String> config = new MultivaluedHashMap<>(); config.putSingle("priority", "100"); generated.setConfig(config); realm.addComponentModel(generated); } createSecretProvider(realm); createAesProvider(realm); }
Example 3
Source File: DefaultKeyProviders.java From keycloak with Apache License 2.0 | 6 votes |
public static void createProviders(RealmModel realm, String privateKeyPem, String certificatePem) { if (!hasProvider(realm, "rsa")) { ComponentModel rsa = new ComponentModel(); rsa.setName("rsa"); rsa.setParentId(realm.getId()); rsa.setProviderId("rsa"); rsa.setProviderType(KeyProvider.class.getName()); MultivaluedHashMap<String, String> config = new MultivaluedHashMap<>(); config.putSingle("priority", "100"); config.putSingle("privateKey", privateKeyPem); if (certificatePem != null) { config.putSingle("certificate", certificatePem); } rsa.setConfig(config); realm.addComponentModel(rsa); } createSecretProvider(realm); createAesProvider(realm); }
Example 4
Source File: LDAPTestUtils.java From keycloak with Apache License 2.0 | 6 votes |
public static void addOrUpdateGroupMapper(RealmModel realm, ComponentModel providerModel, LDAPGroupMapperMode mode, String descriptionAttrName, String... otherConfigOptions) { ComponentModel mapperModel = getSubcomponentByName(realm, providerModel, "groupsMapper"); if (mapperModel != null) { mapperModel.getConfig().putSingle(GroupMapperConfig.MODE, mode.toString()); updateGroupMapperConfigOptions(mapperModel, otherConfigOptions); realm.updateComponent(mapperModel); } else { String baseDn = providerModel.getConfig().getFirst(LDAPConstants.BASE_DN); mapperModel = KeycloakModelUtils.createComponentModel("groupsMapper", providerModel.getId(), GroupLDAPStorageMapperFactory.PROVIDER_ID, LDAPStorageMapper.class.getName(), GroupMapperConfig.GROUPS_DN, "ou=Groups," + baseDn, GroupMapperConfig.MAPPED_GROUP_ATTRIBUTES, descriptionAttrName, GroupMapperConfig.PRESERVE_GROUP_INHERITANCE, "true", GroupMapperConfig.MODE, mode.toString(), GroupMapperConfig.LDAP_GROUPS_PATH, "/"); updateGroupMapperConfigOptions(mapperModel, otherConfigOptions); realm.addComponentModel(mapperModel); } }
Example 5
Source File: DefaultClientRegistrationPolicies.java From keycloak with Apache License 2.0 | 6 votes |
private static void addAnonymousPolicies(RealmModel realm, String policyTypeKey) { ComponentModel trustedHostModel = createModelInstance("Trusted Hosts", realm, TrustedHostClientRegistrationPolicyFactory.PROVIDER_ID, policyTypeKey); // Not any trusted hosts by default trustedHostModel.getConfig().put(TrustedHostClientRegistrationPolicyFactory.TRUSTED_HOSTS, Collections.emptyList()); trustedHostModel.getConfig().putSingle(TrustedHostClientRegistrationPolicyFactory.HOST_SENDING_REGISTRATION_REQUEST_MUST_MATCH, "true"); trustedHostModel.getConfig().putSingle(TrustedHostClientRegistrationPolicyFactory.CLIENT_URIS_MUST_MATCH, "true"); realm.addComponentModel(trustedHostModel); ComponentModel consentRequiredModel = createModelInstance("Consent Required", realm, ConsentRequiredClientRegistrationPolicyFactory.PROVIDER_ID, policyTypeKey); realm.addComponentModel(consentRequiredModel); ComponentModel scopeModel = createModelInstance("Full Scope Disabled", realm, ScopeClientRegistrationPolicyFactory.PROVIDER_ID, policyTypeKey); realm.addComponentModel(scopeModel); ComponentModel maxClientsModel = createModelInstance("Max Clients Limit", realm, MaxClientsClientRegistrationPolicyFactory.PROVIDER_ID, policyTypeKey); maxClientsModel.put(MaxClientsClientRegistrationPolicyFactory.MAX_CLIENTS, MaxClientsClientRegistrationPolicyFactory.DEFAULT_MAX_CLIENTS); realm.addComponentModel(maxClientsModel); addGenericPolicies(realm, policyTypeKey); }
Example 6
Source File: GeneratedAesKeyProviderFactory.java From keycloak with Apache License 2.0 | 6 votes |
@Override public boolean createFallbackKeys(KeycloakSession session, KeyUse keyUse, String algorithm) { if (keyUse.equals(KeyUse.ENC) && algorithm.equals(Algorithm.AES)) { RealmModel realm = session.getContext().getRealm(); ComponentModel generated = new ComponentModel(); generated.setName("fallback-" + algorithm); generated.setParentId(realm.getId()); generated.setProviderId(ID); generated.setProviderType(KeyProvider.class.getName()); MultivaluedHashMap<String, String> config = new MultivaluedHashMap<>(); config.putSingle(Attributes.PRIORITY_KEY, "-100"); generated.setConfig(config); realm.addComponentModel(generated); return true; } else { return false; } }
Example 7
Source File: GeneratedHmacKeyProviderFactory.java From keycloak with Apache License 2.0 | 6 votes |
@Override public boolean createFallbackKeys(KeycloakSession session, KeyUse keyUse, String algorithm) { if (keyUse.equals(KeyUse.SIG) && (algorithm.equals(Algorithm.HS256) || algorithm.equals(Algorithm.HS384) || algorithm.equals(Algorithm.HS512))) { RealmModel realm = session.getContext().getRealm(); ComponentModel generated = new ComponentModel(); generated.setName("fallback-" + algorithm); generated.setParentId(realm.getId()); generated.setProviderId(ID); generated.setProviderType(KeyProvider.class.getName()); MultivaluedHashMap<String, String> config = new MultivaluedHashMap<>(); config.putSingle(Attributes.PRIORITY_KEY, "-100"); config.putSingle(Attributes.ALGORITHM_KEY, algorithm); generated.setConfig(config); realm.addComponentModel(generated); return true; } else { return false; } }
Example 8
Source File: GeneratedRsaKeyProviderFactory.java From keycloak with Apache License 2.0 | 6 votes |
@Override public boolean createFallbackKeys(KeycloakSession session, KeyUse keyUse, String algorithm) { if (keyUse.equals(KeyUse.SIG) && isSupportedRsaAlgorithm(algorithm)) { RealmModel realm = session.getContext().getRealm(); ComponentModel generated = new ComponentModel(); generated.setName("fallback-" + algorithm); generated.setParentId(realm.getId()); generated.setProviderId(ID); generated.setProviderType(KeyProvider.class.getName()); MultivaluedHashMap<String, String> config = new MultivaluedHashMap<>(); config.putSingle(Attributes.PRIORITY_KEY, "-100"); config.putSingle(Attributes.ALGORITHM_KEY, algorithm); generated.setConfig(config); realm.addComponentModel(generated); return true; } else { return false; } }
Example 9
Source File: GeneratedEcdsaKeyProviderFactory.java From keycloak with Apache License 2.0 | 6 votes |
@Override public boolean createFallbackKeys(KeycloakSession session, KeyUse keyUse, String algorithm) { if (keyUse.equals(KeyUse.SIG) && (algorithm.equals(Algorithm.ES256) || algorithm.equals(Algorithm.ES384) || algorithm.equals(Algorithm.ES512))) { RealmModel realm = session.getContext().getRealm(); ComponentModel generated = new ComponentModel(); generated.setName("fallback-" + algorithm); generated.setParentId(realm.getId()); generated.setProviderId(ID); generated.setProviderType(KeyProvider.class.getName()); MultivaluedHashMap<String, String> config = new MultivaluedHashMap<>(); config.putSingle(Attributes.PRIORITY_KEY, "-100"); config.putSingle(ECDSA_ELLIPTIC_CURVE_KEY, convertAlgorithmToECDomainParmNistRep(algorithm)); generated.setConfig(config); realm.addComponentModel(generated); return true; } else { return false; } }
Example 10
Source File: DefaultKeyProviders.java From keycloak with Apache License 2.0 | 5 votes |
public static void createSecretProvider(RealmModel realm) { if (hasProvider(realm, "hmac-generated")) return; ComponentModel generated = new ComponentModel(); generated.setName("hmac-generated"); generated.setParentId(realm.getId()); generated.setProviderId("hmac-generated"); generated.setProviderType(KeyProvider.class.getName()); MultivaluedHashMap<String, String> config = new MultivaluedHashMap<>(); config.putSingle("priority", "100"); config.putSingle("algorithm", Algorithm.HS256); generated.setConfig(config); realm.addComponentModel(generated); }
Example 11
Source File: DefaultKeyProviders.java From keycloak with Apache License 2.0 | 5 votes |
public static void createAesProvider(RealmModel realm) { if (hasProvider(realm, "aes-generated")) return; ComponentModel generated = new ComponentModel(); generated.setName("aes-generated"); generated.setParentId(realm.getId()); generated.setProviderId("aes-generated"); generated.setProviderType(KeyProvider.class.getName()); MultivaluedHashMap<String, String> config = new MultivaluedHashMap<>(); config.putSingle("priority", "100"); generated.setConfig(config); realm.addComponentModel(generated); }
Example 12
Source File: LDAPTestUtils.java From keycloak with Apache License 2.0 | 5 votes |
public static ComponentModel addUserAttributeMapper(RealmModel realm, ComponentModel providerModel, String mapperName, String userModelAttributeName, String ldapAttributeName) { ComponentModel mapperModel = KeycloakModelUtils.createComponentModel(mapperName, providerModel.getId(), UserAttributeLDAPStorageMapperFactory.PROVIDER_ID, LDAPStorageMapper.class.getName(), UserAttributeLDAPStorageMapper.USER_MODEL_ATTRIBUTE, userModelAttributeName, UserAttributeLDAPStorageMapper.LDAP_ATTRIBUTE, ldapAttributeName, UserAttributeLDAPStorageMapper.READ_ONLY, "false", UserAttributeLDAPStorageMapper.ALWAYS_READ_VALUE_FROM_LDAP, "false", UserAttributeLDAPStorageMapper.IS_MANDATORY_IN_LDAP, "false"); return realm.addComponentModel(mapperModel); }
Example 13
Source File: DefaultClientRegistrationPolicies.java From keycloak with Apache License 2.0 | 5 votes |
private static void addGenericPolicies(RealmModel realm, String policyTypeKey) { ComponentModel protMapperModel = createModelInstance("Allowed Protocol Mapper Types", realm, ProtocolMappersClientRegistrationPolicyFactory.PROVIDER_ID, policyTypeKey); protMapperModel.getConfig().put(ProtocolMappersClientRegistrationPolicyFactory.ALLOWED_PROTOCOL_MAPPER_TYPES, Arrays.asList(DEFAULT_ALLOWED_PROTOCOL_MAPPERS)); realm.addComponentModel(protMapperModel); ComponentModel clientTemplatesModel = createModelInstance("Allowed Client Scopes", realm, ClientScopesClientRegistrationPolicyFactory.PROVIDER_ID, policyTypeKey); clientTemplatesModel.getConfig().put(ClientScopesClientRegistrationPolicyFactory.ALLOWED_CLIENT_SCOPES, Collections.emptyList()); clientTemplatesModel.put(ClientScopesClientRegistrationPolicyFactory.ALLOW_DEFAULT_SCOPES, true); realm.addComponentModel(clientTemplatesModel); }