Search in sources :

Example 11 with ComponentValidationException

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

the class FullNameLDAPStorageMapperFactory method validateConfiguration.

@Override
public void validateConfiguration(KeycloakSession session, RealmModel realm, ComponentModel config) throws ComponentValidationException {
    checkMandatoryConfigAttribute(FullNameLDAPStorageMapper.LDAP_FULL_NAME_ATTRIBUTE, "LDAP Full Name Attribute", config);
    boolean readOnly = AbstractLDAPStorageMapper.parseBooleanParameter(config, FullNameLDAPStorageMapper.READ_ONLY);
    boolean writeOnly = AbstractLDAPStorageMapper.parseBooleanParameter(config, FullNameLDAPStorageMapper.WRITE_ONLY);
    ComponentModel parent = realm.getComponent(config.getParentId());
    if (parent == null) {
        throw new ComponentValidationException("can't find parent component model");
    }
    LDAPConfig cfg = new LDAPConfig(parent.getConfig());
    UserStorageProvider.EditMode editMode = cfg.getEditMode();
    if (writeOnly && cfg.getEditMode() != UserStorageProvider.EditMode.WRITABLE) {
        throw new ComponentValidationException("ldapErrorCantWriteOnlyForReadOnlyLdap");
    }
    if (writeOnly && readOnly) {
        throw new ComponentValidationException("ldapErrorCantWriteOnlyAndReadOnly");
    }
}
Also used : ComponentValidationException(org.keycloak.component.ComponentValidationException) UserStorageProvider(org.keycloak.storage.UserStorageProvider) LDAPConfig(org.keycloak.storage.ldap.LDAPConfig) ComponentModel(org.keycloak.component.ComponentModel)

Example 12 with ComponentValidationException

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

the class HardcodedLDAPRoleStorageMapperFactory method validateConfiguration.

@Override
public void validateConfiguration(KeycloakSession session, RealmModel realm, ComponentModel config) throws ComponentValidationException {
    String roleName = config.getConfig().getFirst(HardcodedLDAPRoleStorageMapper.ROLE);
    if (roleName == null) {
        throw new ComponentValidationException("Role can't be null");
    }
    RoleModel role = KeycloakModelUtils.getRoleFromString(realm, roleName);
    if (role == null) {
        throw new ComponentValidationException("There is no role corresponding to configured value");
    }
}
Also used : ComponentValidationException(org.keycloak.component.ComponentValidationException) RoleModel(org.keycloak.models.RoleModel)

Example 13 with ComponentValidationException

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

the class UserProfileResource method update.

@PUT
@Consumes(MediaType.APPLICATION_JSON)
public Response update(String text) {
    auth.realm().requireManageRealm();
    UserProfileProvider t = session.getProvider(UserProfileProvider.class);
    try {
        t.setConfiguration(text);
    } catch (ComponentValidationException e) {
        // show validation result containing details about error
        return ErrorResponse.error(e.getMessage(), Response.Status.BAD_REQUEST);
    }
    return Response.ok(t.getConfiguration()).type(MediaType.APPLICATION_JSON).build();
}
Also used : ComponentValidationException(org.keycloak.component.ComponentValidationException) UserProfileProvider(org.keycloak.userprofile.UserProfileProvider) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 14 with ComponentValidationException

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

the class AbstractGeneratedRsaKeyProviderFactory method generateCertificate.

private void generateCertificate(RealmModel realm, ComponentModel model, KeyPair keyPair) {
    try {
        Certificate certificate = CertificateUtils.generateV1SelfSignedCertificate(keyPair, realm.getName());
        model.put(Attributes.CERTIFICATE_KEY, PemUtils.encodeCertificate(certificate));
    } catch (Throwable t) {
        throw new ComponentValidationException("Failed to generate certificate", t);
    }
}
Also used : ComponentValidationException(org.keycloak.component.ComponentValidationException) Certificate(java.security.cert.Certificate)

Example 15 with ComponentValidationException

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

the class AbstractGeneratedSecretKeyProviderFactory method generateSecret.

private void generateSecret(ComponentModel model, int size) {
    try {
        byte[] secret = SecretGenerator.getInstance().randomBytes(size);
        model.put(Attributes.SECRET_KEY, Base64Url.encode(secret));
        String kid = KeycloakModelUtils.generateId();
        model.put(Attributes.KID_KEY, kid);
    } catch (Throwable t) {
        throw new ComponentValidationException("Failed to generate secret", t);
    }
}
Also used : ComponentValidationException(org.keycloak.component.ComponentValidationException)

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