Search in sources :

Example 21 with ComponentValidationException

use of org.keycloak.component.ComponentValidationException in project keycloak by keycloak.

the class CustomUserProfileTest 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
    }
}
Also used : ComponentValidationException(org.keycloak.component.ComponentValidationException) DeclarativeUserProfileProvider(org.keycloak.userprofile.DeclarativeUserProfileProvider)

Example 22 with ComponentValidationException

use of org.keycloak.component.ComponentValidationException in project keycloak by keycloak.

the class ConfigurationValidationHelper method checkInt.

public ConfigurationValidationHelper checkInt(String key, String label, boolean required) throws ComponentValidationException {
    checkSingle(key, label, required);
    String val = model.getConfig().getFirst(key);
    if (val != null) {
        try {
            Integer.parseInt(val);
        } catch (NumberFormatException e) {
            throw new ComponentValidationException("''{0}'' should be a number", label);
        }
    }
    return this;
}
Also used : ComponentValidationException(org.keycloak.component.ComponentValidationException)

Example 23 with ComponentValidationException

use of org.keycloak.component.ComponentValidationException in project keycloak by keycloak.

the class DeclarativeUserProfileProvider method validateConfiguration.

@Override
public void validateConfiguration(KeycloakSession session, RealmModel realm, ComponentModel model) throws ComponentValidationException {
    String upConfigJson = getConfigJsonFromComponentModel(model);
    if (!isBlank(upConfigJson)) {
        try {
            UPConfig upc = readConfig(new ByteArrayInputStream(upConfigJson.getBytes("UTF-8")));
            List<String> errors = UPConfigUtils.validate(session, upc);
            if (!errors.isEmpty()) {
                throw new ComponentValidationException(errors.toString());
            }
        } catch (IOException e) {
            throw new ComponentValidationException(e.getMessage(), e);
        }
    }
    // throught #configureUserProfile(metadata, session)
    if (model != null) {
        model.removeNote(PARSED_CONFIG_COMPONENT_KEY);
    }
}
Also used : ComponentValidationException(org.keycloak.component.ComponentValidationException) ByteArrayInputStream(java.io.ByteArrayInputStream) UPConfig(org.keycloak.userprofile.config.UPConfig) IOException(java.io.IOException)

Example 24 with ComponentValidationException

use of org.keycloak.component.ComponentValidationException in project keycloak by keycloak.

the class UserPropertyFileStorageFactory method validateConfiguration.

@Override
public void validateConfiguration(KeycloakSession session, RealmModel realm, ComponentModel config) throws ComponentValidationException {
    String fp = config.getConfig().getFirst(PROPERTY_FILE);
    if (fp == null) {
        throw new ComponentValidationException(VALIDATION_PROP_FILE_NOT_CONFIGURED);
    }
    fp = EnvUtil.replace(fp);
    File file = new File(fp);
    if (!file.exists()) {
        throw new ComponentValidationException(VALIDATION_PROP_FILE_DOESNT_EXIST);
    }
}
Also used : ComponentValidationException(org.keycloak.component.ComponentValidationException) File(java.io.File)

Aggregations

ComponentValidationException (org.keycloak.component.ComponentValidationException)24 ComponentModel (org.keycloak.component.ComponentModel)5 KeyPair (java.security.KeyPair)3 Consumes (javax.ws.rs.Consumes)3 DeclarativeUserProfileProvider (org.keycloak.userprofile.DeclarativeUserProfileProvider)3 Certificate (java.security.cert.Certificate)2 BadRequestException (javax.ws.rs.BadRequestException)2 PUT (javax.ws.rs.PUT)2 RealmModel (org.keycloak.models.RealmModel)2 UPConfig (org.keycloak.userprofile.config.UPConfig)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 KeyFactory (java.security.KeyFactory)1 PrivateKey (java.security.PrivateKey)1 PublicKey (java.security.PublicKey)1 ECPublicKey (java.security.interfaces.ECPublicKey)1 X509EncodedKeySpec (java.security.spec.X509EncodedKeySpec)1 NotFoundException (javax.ws.rs.NotFoundException)1 POST (javax.ws.rs.POST)1