use of org.keycloak.component.ComponentValidationException in project keycloak by keycloak.
the class ComponentResource method create.
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response create(ComponentRepresentation rep) {
auth.realm().requireManageRealm();
try {
ComponentModel model = RepresentationToModel.toModel(session, rep);
if (model.getParentId() == null)
model.setParentId(realm.getId());
model = realm.addComponentModel(model);
adminEvent.operation(OperationType.CREATE).resourcePath(session.getContext().getUri(), model.getId()).representation(StripSecretsUtils.strip(session, rep)).success();
return Response.created(session.getContext().getUri().getAbsolutePathBuilder().path(model.getId()).build()).build();
} catch (ComponentValidationException e) {
return localizedErrorResponse(e);
} catch (IllegalArgumentException e) {
throw new BadRequestException(e);
}
}
use of org.keycloak.component.ComponentValidationException in project keycloak by keycloak.
the class ComponentResource method updateComponent.
@PUT
@Path("{id}")
@Consumes(MediaType.APPLICATION_JSON)
public Response updateComponent(@PathParam("id") String id, ComponentRepresentation rep) {
auth.realm().requireManageRealm();
try {
ComponentModel model = realm.getComponent(id);
if (model == null) {
throw new NotFoundException("Could not find component");
}
RepresentationToModel.updateComponent(session, rep, model, false);
adminEvent.operation(OperationType.UPDATE).resourcePath(session.getContext().getUri()).representation(StripSecretsUtils.strip(session, rep)).success();
realm.updateComponent(model);
return Response.noContent().build();
} catch (ComponentValidationException e) {
return localizedErrorResponse(e);
} catch (IllegalArgumentException e) {
throw new BadRequestException();
}
}
use of org.keycloak.component.ComponentValidationException in project keycloak by keycloak.
the class UserProfileTest method testInvalidConfiguration.
private static void testInvalidConfiguration(KeycloakSession session) {
DeclarativeUserProfileProvider provider = getDynamicUserProfileProvider(session);
try {
provider.setConfiguration("{\"validateConfigAttribute\": true}");
fail("Should fail validation");
} catch (ComponentValidationException ve) {
// OK
}
}
use of org.keycloak.component.ComponentValidationException in project keycloak by keycloak.
the class UserProfileTest method testConfigurationInvalidScope.
private static void testConfigurationInvalidScope(KeycloakSession session) throws IOException {
RealmModel realm = session.getContext().getRealm();
DeclarativeUserProfileProvider provider = getDynamicUserProfileProvider(session);
ComponentModel component = provider.getComponentModel();
assertNotNull(component);
UPConfig config = new UPConfig();
UPAttribute attribute = new UPAttribute();
attribute.setName(ATT_ADDRESS);
UPAttributeRequired requirements = new UPAttributeRequired();
requirements.setScopes(Collections.singleton("invalid"));
attribute.setRequired(requirements);
attribute.setSelector(new UPAttributeSelector());
attribute.getSelector().setScopes(Collections.singleton("invalid"));
config.addAttribute(attribute);
try {
provider.setConfiguration(JsonSerialization.writeValueAsString(config));
Assert.fail("Expected to fail due to invalid client scope");
} catch (ComponentValidationException cve) {
// ignore
}
}
use of org.keycloak.component.ComponentValidationException in project keycloak by keycloak.
the class LDAPStorageProviderFactory method validateConfiguration.
@Override
public void validateConfiguration(KeycloakSession session, RealmModel realm, ComponentModel config) throws ComponentValidationException {
LDAPConfig cfg = new LDAPConfig(config.getConfig());
UserStorageProviderModel userStorageModel = new UserStorageProviderModel(config);
String customFilter = cfg.getCustomUserSearchFilter();
LDAPUtils.validateCustomLdapFilter(customFilter);
String connectionTimeout = cfg.getConnectionTimeout();
if (connectionTimeout != null && !connectionTimeout.isEmpty()) {
try {
Long.parseLong(connectionTimeout);
} catch (NumberFormatException nfe) {
throw new ComponentValidationException("ldapErrorConnectionTimeoutNotNumber");
}
}
String readTimeout = cfg.getReadTimeout();
if (readTimeout != null && !readTimeout.isEmpty()) {
try {
Long.parseLong(readTimeout);
} catch (NumberFormatException nfe) {
throw new ComponentValidationException("ldapErrorReadTimeoutNotNumber");
}
}
if (cfg.isStartTls() && cfg.getConnectionPooling() != null) {
throw new ComponentValidationException("ldapErrorCantEnableStartTlsAndConnectionPooling");
}
// editMode is mandatory
if (config.get(LDAPConstants.EDIT_MODE) == null) {
throw new ComponentValidationException("ldapErrorEditModeMandatory");
}
// validatePasswordPolicy applicable only for WRITABLE mode
if (cfg.getEditMode() != UserStorageProvider.EditMode.WRITABLE) {
if (cfg.isValidatePasswordPolicy()) {
throw new ComponentValidationException("ldapErrorValidatePasswordPolicyAvailableForWritableOnly");
}
}
if (!userStorageModel.isImportEnabled() && cfg.getEditMode() == UserStorageProvider.EditMode.UNSYNCED) {
throw new ComponentValidationException("ldapErrorCantEnableUnsyncedAndImportOff");
}
}
Aggregations