Java Code Examples for org.keycloak.component.ComponentModel#getId()
The following examples show how to use
org.keycloak.component.ComponentModel#getId() .
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: DefaultKeycloakSession.java From keycloak with Apache License 2.0 | 6 votes |
@Override public <T extends Provider> T getProvider(Class<T> clazz, ComponentModel componentModel) { String modelId = componentModel.getId(); Object found = getAttribute(modelId); if (found != null) { return clazz.cast(found); } ProviderFactory<T> providerFactory = factory.getProviderFactory(clazz, componentModel.getProviderId()); if (providerFactory == null) { return null; } @SuppressWarnings("unchecked") ComponentFactory<T, T> componentFactory = (ComponentFactory<T, T>) providerFactory; T provider = componentFactory.create(this, componentModel); enlistForClose(provider); setAttribute(modelId, provider); return provider; }
Example 2
Source File: TestLDAPResource.java From keycloak with Apache License 2.0 | 5 votes |
/** * @param ldapCfg configuration of LDAP provider * @param importEnabled specify if LDAP provider will have import enabled * @return ID of newly created provider */ @POST @Path("/create-ldap-provider") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public String createLDAPProvider(Map<String,String> ldapCfg, @QueryParam("import") boolean importEnabled) { MultivaluedHashMap<String, String> ldapConfig = toComponentConfig(ldapCfg); ldapConfig.putSingle(LDAPConstants.SYNC_REGISTRATIONS, "true"); ldapConfig.putSingle(LDAPConstants.EDIT_MODE, UserStorageProvider.EditMode.WRITABLE.toString()); UserStorageProviderModel model = new UserStorageProviderModel(); model.setLastSync(0); model.setChangedSyncPeriod(-1); model.setFullSyncPeriod(-1); model.setName("test-ldap"); model.setPriority(0); model.setProviderId(LDAPStorageProviderFactory.PROVIDER_NAME); model.setConfig(ldapConfig); model.setImportEnabled(importEnabled); model.setCachePolicy(UserStorageProviderModel.CachePolicy.MAX_LIFESPAN); model.setMaxLifespan(600000); // Lifetime is 10 minutes ComponentModel ldapModel = realm.addComponentModel(model); return ldapModel.getId(); }
Example 3
Source File: RealmAdapter.java From keycloak with Apache License 2.0 | 5 votes |
@Override public ComponentModel importComponentModel(ComponentModel model) { ComponentFactory componentFactory = null; try { componentFactory = ComponentUtil.getComponentFactory(session, model); if (componentFactory == null && System.getProperty(COMPONENT_PROVIDER_EXISTS_DISABLED) == null) { throw new IllegalArgumentException("Invalid component type"); } componentFactory.validateConfiguration(session, this, model); } catch (Exception e) { if (System.getProperty(COMPONENT_PROVIDER_EXISTS_DISABLED) == null) { throw e; } } ComponentEntity c = new ComponentEntity(); if (model.getId() == null) { c.setId(KeycloakModelUtils.generateId()); } else { c.setId(model.getId()); } c.setName(model.getName()); c.setParentId(model.getParentId()); if (model.getParentId() == null) { c.setParentId(this.getId()); model.setParentId(this.getId()); } c.setProviderType(model.getProviderType()); c.setProviderId(model.getProviderId()); c.setSubType(model.getSubType()); c.setRealm(realm); em.persist(c); realm.getComponents().add(c); setConfig(model, c); model.setId(c.getId()); return model; }