Search in sources :

Example 1 with ComponentValidationException

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

the class ConfigurationValidationHelper method checkLong.

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

Example 2 with ComponentValidationException

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

the class GeneratedEcdsaKeyProviderFactory method generateKeys.

private void generateKeys(ComponentModel model, String ecInNistRep) {
    KeyPair keyPair;
    try {
        keyPair = generateEcdsaKeyPair(convertECDomainParmNistRepToSecRep(ecInNistRep));
        model.put(ECDSA_PRIVATE_KEY_KEY, Base64.encodeBytes(keyPair.getPrivate().getEncoded()));
        model.put(ECDSA_PUBLIC_KEY_KEY, Base64.encodeBytes(keyPair.getPublic().getEncoded()));
        model.put(ECDSA_ELLIPTIC_CURVE_KEY, ecInNistRep);
    } catch (Throwable t) {
        throw new ComponentValidationException("Failed to generate ECDSA keys", t);
    }
}
Also used : ComponentValidationException(org.keycloak.component.ComponentValidationException) KeyPair(java.security.KeyPair)

Example 3 with ComponentValidationException

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

the class GroupLDAPStorageMapperFactory method validateConfiguration.

@Override
public void validateConfiguration(KeycloakSession session, RealmModel realm, ComponentModel config) throws ComponentValidationException {
    checkMandatoryConfigAttribute(GroupMapperConfig.GROUPS_DN, "LDAP Groups DN", config);
    checkMandatoryConfigAttribute(GroupMapperConfig.MODE, "Mode", config);
    String mt = config.getConfig().getFirst(CommonLDAPGroupMapperConfig.MEMBERSHIP_ATTRIBUTE_TYPE);
    MembershipType membershipType = mt == null ? MembershipType.DN : Enum.valueOf(MembershipType.class, mt);
    boolean preserveGroupInheritance = Boolean.parseBoolean(config.getConfig().getFirst(GroupMapperConfig.PRESERVE_GROUP_INHERITANCE));
    if (preserveGroupInheritance && membershipType != MembershipType.DN) {
        throw new ComponentValidationException("ldapErrorCantPreserveGroupInheritanceWithUIDMembershipType");
    }
    LDAPUtils.validateCustomLdapFilter(config.getConfig().getFirst(GroupMapperConfig.GROUPS_LDAP_FILTER));
    String group = new GroupMapperConfig(config).getGroupsPath();
    if (!GroupMapperConfig.DEFAULT_LDAP_GROUPS_PATH.equals(group) && KeycloakModelUtils.findGroupByPath(realm, group) == null) {
        throw new ComponentValidationException("ldapErrorMissingGroupsPathGroup");
    }
}
Also used : ComponentValidationException(org.keycloak.component.ComponentValidationException) MembershipType(org.keycloak.storage.ldap.mappers.membership.MembershipType) CommonLDAPGroupMapperConfig(org.keycloak.storage.ldap.mappers.membership.CommonLDAPGroupMapperConfig)

Example 4 with ComponentValidationException

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

the class HardcodedLDAPGroupStorageMapperFactory method validateConfiguration.

@Override
public void validateConfiguration(KeycloakSession session, RealmModel realm, ComponentModel config) throws ComponentValidationException {
    String groupName = config.getConfig().getFirst(HardcodedLDAPGroupStorageMapper.GROUP);
    if (groupName == null) {
        throw new ComponentValidationException("Group can't be null");
    }
    GroupModel group = KeycloakModelUtils.findGroupByPath(realm, groupName);
    if (group == null) {
        throw new ComponentValidationException("There is no group corresponding to configured value");
    }
}
Also used : ComponentValidationException(org.keycloak.component.ComponentValidationException) GroupModel(org.keycloak.models.GroupModel)

Example 5 with ComponentValidationException

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

the class MapRealmAdapter method importComponentModel.

@Override
public ComponentModel importComponentModel(ComponentModel model) {
    try {
        ComponentFactory 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 (IllegalArgumentException | ComponentValidationException e) {
        if (System.getProperty(COMPONENT_PROVIDER_EXISTS_DISABLED) == null) {
            throw e;
        }
    }
    if (entity.getComponent(model.getId()).isPresent()) {
        throw new ModelDuplicateException("A Component with given id already exists");
    }
    MapComponentEntity component = MapComponentEntity.fromModel(model);
    if (model.getParentId() == null) {
        component.setParentId(getId());
    }
    entity.addComponent(component);
    return MapComponentEntity.toModel(component);
}
Also used : ComponentValidationException(org.keycloak.component.ComponentValidationException) MapComponentEntity(org.keycloak.models.map.realm.entity.MapComponentEntity) ComponentFactory(org.keycloak.component.ComponentFactory) ModelDuplicateException(org.keycloak.models.ModelDuplicateException)

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