use of org.keycloak.representations.idm.ComponentTypeRepresentation in project keycloak by keycloak.
the class ServerInfoAdminResource method setProviders.
private void setProviders(ServerInfoRepresentation info) {
info.setComponentTypes(new HashMap<>());
LinkedHashMap<String, SpiInfoRepresentation> spiReps = new LinkedHashMap<>();
List<Spi> spis = new LinkedList<>(session.getKeycloakSessionFactory().getSpis());
Collections.sort(spis, new Comparator<Spi>() {
@Override
public int compare(Spi s1, Spi s2) {
return s1.getName().compareTo(s2.getName());
}
});
for (Spi spi : spis) {
SpiInfoRepresentation spiRep = new SpiInfoRepresentation();
spiRep.setInternal(spi.isInternal());
List<String> providerIds = new LinkedList<>(session.listProviderIds(spi.getProviderClass()));
Collections.sort(providerIds);
Map<String, ProviderRepresentation> providers = new HashMap<>();
if (providerIds != null) {
for (String name : providerIds) {
ProviderRepresentation provider = new ProviderRepresentation();
ProviderFactory<?> pi = session.getKeycloakSessionFactory().getProviderFactory(spi.getProviderClass(), name);
provider.setOrder(pi.order());
if (ServerInfoAwareProviderFactory.class.isAssignableFrom(pi.getClass())) {
provider.setOperationalInfo(((ServerInfoAwareProviderFactory) pi).getOperationalInfo());
}
if (pi instanceof ConfiguredProvider) {
ComponentTypeRepresentation rep = new ComponentTypeRepresentation();
rep.setId(pi.getId());
ConfiguredProvider configured = (ConfiguredProvider) pi;
rep.setHelpText(configured.getHelpText());
List<ProviderConfigProperty> configProperties = configured.getConfigProperties();
if (configProperties == null)
configProperties = Collections.EMPTY_LIST;
rep.setProperties(ModelToRepresentation.toRepresentation(configProperties));
if (pi instanceof ComponentFactory) {
rep.setMetadata(((ComponentFactory) pi).getTypeMetadata());
}
List<ComponentTypeRepresentation> reps = info.getComponentTypes().get(spi.getProviderClass().getName());
if (reps == null) {
reps = new LinkedList<>();
info.getComponentTypes().put(spi.getProviderClass().getName(), reps);
}
reps.add(rep);
}
providers.put(name, provider);
}
}
spiRep.setProviders(providers);
spiReps.put(spi.getName(), spiRep);
}
info.setProviders(spiReps);
}
use of org.keycloak.representations.idm.ComponentTypeRepresentation in project keycloak by keycloak.
the class UserStorageRestTest method testLDAPMapperProviderConfigurationForVendorOther.
// KEYCLOAK-12934
@Test
public void testLDAPMapperProviderConfigurationForVendorOther() {
ComponentRepresentation ldapRep = createBasicLDAPProviderRep();
ldapRep.getConfig().putSingle(LDAPConstants.VENDOR, LDAPConstants.VENDOR_OTHER);
String ldapModelId = createComponent(ldapRep);
ComponentTypeRepresentation groupLDAPMapperType = findMapperTypeConfiguration(ldapModelId, GroupLDAPStorageMapperFactory.PROVIDER_ID);
ConfigPropertyRepresentation groupRetrieverConfigProperty = getUserRolesRetrieveStrategyConfigProperty(groupLDAPMapperType, CommonLDAPGroupMapperConfig.USER_ROLES_RETRIEVE_STRATEGY);
// LOAD_GROUPS_BY_MEMBER_ATTRIBUTE_RECURSIVELY is expected to be present just for the active directory
List<String> options = groupRetrieverConfigProperty.getOptions();
Assert.assertNames(options, GroupMapperConfig.LOAD_GROUPS_BY_MEMBER_ATTRIBUTE, GroupMapperConfig.GET_GROUPS_FROM_USER_MEMBEROF_ATTRIBUTE);
Assert.assertFalse(groupRetrieverConfigProperty.getHelpText().contains("LOAD_GROUPS_BY_MEMBER_ATTRIBUTE_RECURSIVELY"));
ComponentTypeRepresentation roleLDAPMapperType = findMapperTypeConfiguration(ldapModelId, RoleLDAPStorageMapperFactory.PROVIDER_ID);
ConfigPropertyRepresentation roleRetrieverConfigProperty = getUserRolesRetrieveStrategyConfigProperty(roleLDAPMapperType, CommonLDAPGroupMapperConfig.USER_ROLES_RETRIEVE_STRATEGY);
// LOAD_ROLES_BY_MEMBER_ATTRIBUTE_RECURSIVELY is expected to be present just for the active directory
options = roleRetrieverConfigProperty.getOptions();
Assert.assertNames(options, RoleMapperConfig.LOAD_ROLES_BY_MEMBER_ATTRIBUTE, RoleMapperConfig.GET_ROLES_FROM_USER_MEMBEROF_ATTRIBUTE);
Assert.assertFalse(roleRetrieverConfigProperty.getHelpText().contains("LOAD_ROLES_BY_MEMBER_ATTRIBUTE_RECURSIVELY"));
// Cleanup including mappers
removeComponent(ldapModelId);
}
use of org.keycloak.representations.idm.ComponentTypeRepresentation in project keycloak by keycloak.
the class ClientRegistrationPolicyResource method getProviders.
/**
* Base path for retrieve providers with the configProperties properly filled
*
* @return
*/
@Path("providers")
@GET
@NoCache
@Produces(MediaType.APPLICATION_JSON)
public Stream<ComponentTypeRepresentation> getProviders() {
return session.getKeycloakSessionFactory().getProviderFactoriesStream(ClientRegistrationPolicy.class).map((ProviderFactory factory) -> {
ClientRegistrationPolicyFactory clientRegFactory = (ClientRegistrationPolicyFactory) factory;
List<ProviderConfigProperty> configProps = clientRegFactory.getConfigProperties(session);
ComponentTypeRepresentation rep = new ComponentTypeRepresentation();
rep.setId(clientRegFactory.getId());
rep.setHelpText(clientRegFactory.getHelpText());
rep.setProperties(ModelToRepresentation.toRepresentation(configProps));
return rep;
});
}
use of org.keycloak.representations.idm.ComponentTypeRepresentation in project keycloak by keycloak.
the class ComponentResource method toComponentTypeRepresentation.
private ComponentTypeRepresentation toComponentTypeRepresentation(ProviderFactory factory, ComponentModel parent) {
ComponentTypeRepresentation rep = new ComponentTypeRepresentation();
rep.setId(factory.getId());
ComponentFactory componentFactory = (ComponentFactory) factory;
rep.setHelpText(componentFactory.getHelpText());
List<ProviderConfigProperty> props;
Map<String, Object> metadata;
if (factory instanceof SubComponentFactory) {
props = ((SubComponentFactory) factory).getConfigProperties(realm, parent);
metadata = ((SubComponentFactory) factory).getTypeMetadata(realm, parent);
} else {
props = componentFactory.getConfigProperties();
metadata = componentFactory.getTypeMetadata();
}
List<ConfigPropertyRepresentation> propReps = ModelToRepresentation.toRepresentation(props);
rep.setProperties(propReps);
rep.setMetadata(metadata);
return rep;
}
use of org.keycloak.representations.idm.ComponentTypeRepresentation in project keycloak by keycloak.
the class ClientRegistrationPoliciesTest method testProviders.
@Test
public void testProviders() throws Exception {
List<ComponentTypeRepresentation> reps = realmResource().clientRegistrationPolicy().getProviders();
Map<String, ComponentTypeRepresentation> providersMap = reps.stream().collect(Collectors.toMap((ComponentTypeRepresentation rep) -> {
return rep.getId();
}, (ComponentTypeRepresentation rep) -> {
return rep;
}));
// test that ProtocolMappersClientRegistrationPolicy provider contains available protocol mappers
ComponentTypeRepresentation protMappersRep = providersMap.get(ProtocolMappersClientRegistrationPolicyFactory.PROVIDER_ID);
List<String> availableMappers = getProviderConfigProperty(protMappersRep, ProtocolMappersClientRegistrationPolicyFactory.ALLOWED_PROTOCOL_MAPPER_TYPES);
List<String> someExpectedMappers = Arrays.asList(UserAttributeStatementMapper.PROVIDER_ID, UserAttributeMapper.PROVIDER_ID, UserPropertyAttributeStatementMapper.PROVIDER_ID, UserPropertyMapper.PROVIDER_ID, HardcodedRole.PROVIDER_ID);
availableMappers.containsAll(someExpectedMappers);
// test that clientScope provider contains just the default client scopes
ComponentTypeRepresentation clientScopeRep = providersMap.get(ClientScopesClientRegistrationPolicyFactory.PROVIDER_ID);
List<String> clientScopes = getProviderConfigProperty(clientScopeRep, ClientScopesClientRegistrationPolicyFactory.ALLOWED_CLIENT_SCOPES);
Assert.assertFalse(clientScopes.isEmpty());
Assert.assertTrue(clientScopes.contains(OAuth2Constants.SCOPE_PROFILE));
Assert.assertFalse(clientScopes.contains("foo"));
Assert.assertFalse(clientScopes.contains("bar"));
// Add some clientScopes
ClientScopeRepresentation clientScope = new ClientScopeRepresentation();
clientScope.setName("foo");
clientScope.setProtocol(OIDCLoginProtocol.LOGIN_PROTOCOL);
Response response = realmResource().clientScopes().create(clientScope);
String fooScopeId = ApiUtil.getCreatedId(response);
response.close();
clientScope = new ClientScopeRepresentation();
clientScope.setName("bar");
clientScope.setProtocol(OIDCLoginProtocol.LOGIN_PROTOCOL);
response = realmResource().clientScopes().create(clientScope);
String barScopeId = ApiUtil.getCreatedId(response);
response.close();
// send request again and test that clientScope provider contains added client scopes
reps = realmResource().clientRegistrationPolicy().getProviders();
clientScopeRep = reps.stream().filter((ComponentTypeRepresentation rep1) -> {
return rep1.getId().equals(ClientScopesClientRegistrationPolicyFactory.PROVIDER_ID);
}).findFirst().get();
clientScopes = getProviderConfigProperty(clientScopeRep, ClientScopesClientRegistrationPolicyFactory.ALLOWED_CLIENT_SCOPES);
Assert.assertTrue(clientScopes.contains("foo"));
Assert.assertTrue(clientScopes.contains("bar"));
// Revert client scopes
realmResource().clientScopes().get(fooScopeId).remove();
realmResource().clientScopes().get(barScopeId).remove();
}
Aggregations