Java Code Examples for org.keycloak.component.ComponentModel#setConfig()
The following examples show how to use
org.keycloak.component.ComponentModel#setConfig() .
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: 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 2
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 3
Source File: RepresentationToModel.java From keycloak with Apache License 2.0 | 6 votes |
protected static void importComponents(RealmModel newRealm, MultivaluedHashMap<String, ComponentExportRepresentation> components, String parentId) { for (Map.Entry<String, List<ComponentExportRepresentation>> entry : components.entrySet()) { String providerType = entry.getKey(); for (ComponentExportRepresentation compRep : entry.getValue()) { ComponentModel component = new ComponentModel(); component.setId(compRep.getId()); component.setName(compRep.getName()); component.setConfig(compRep.getConfig()); component.setProviderType(providerType); component.setProviderId(compRep.getProviderId()); component.setSubType(compRep.getSubType()); component.setParentId(parentId); component = newRealm.importComponentModel(component); if (compRep.getSubComponents() != null) { importComponents(newRealm, compRep.getSubComponents(), component.getId()); } } } }
Example 4
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 5
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 6
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 7
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 8
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 9
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 10
Source File: RepresentationToModel.java From keycloak with Apache License 2.0 | 5 votes |
public static ComponentModel toModel(KeycloakSession session, ComponentRepresentation rep) { ComponentModel model = new ComponentModel(); model.setId(rep.getId()); model.setParentId(rep.getParentId()); model.setProviderType(rep.getProviderType()); model.setProviderId(rep.getProviderId()); model.setConfig(new MultivaluedHashMap<>()); model.setName(rep.getName()); model.setSubType(rep.getSubType()); if (rep.getConfig() != null) { Set<String> keys = new HashSet<>(rep.getConfig().keySet()); for (String k : keys) { List<String> values = rep.getConfig().get(k); if (values != null) { ListIterator<String> itr = values.listIterator(); while (itr.hasNext()) { String v = itr.next(); if (v == null || v.trim().isEmpty()) { itr.remove(); } } if (!values.isEmpty()) { model.getConfig().put(k, values); } } } } return model; }
Example 11
Source File: RealmAdapter.java From keycloak with Apache License 2.0 | 5 votes |
protected ComponentModel entityToModel(ComponentEntity c) { ComponentModel model = new ComponentModel(); model.setId(c.getId()); model.setName(c.getName()); model.setProviderType(c.getProviderType()); model.setProviderId(c.getProviderId()); model.setSubType(c.getSubType()); model.setParentId(c.getParentId()); MultivaluedHashMap<String, String> config = new MultivaluedHashMap<>(); for (ComponentConfigEntity configEntity : c.getComponentConfigs()) { config.add(configEntity.getName(), configEntity.getValue()); } model.setConfig(config); return model; }