Search in sources :

Example 1 with ProtocolMapperConfigException

use of org.keycloak.protocol.ProtocolMapperConfigException in project keycloak by keycloak.

the class PairwiseSubMapperValidator method getSectorRedirects.

private static Set<String> getSectorRedirects(KeycloakSession session, String sectorIdentifierUri) throws ProtocolMapperConfigException {
    InputStream is = null;
    try {
        is = session.getProvider(HttpClientProvider.class).get(sectorIdentifierUri);
        List<String> sectorRedirects = JsonSerialization.readValue(is, TypedList.class);
        return new HashSet<>(sectorRedirects);
    } catch (IOException e) {
        throw new ProtocolMapperConfigException("Failed to get redirect URIs from the Sector Identifier URI.", PAIRWISE_FAILED_TO_GET_REDIRECT_URIS, e);
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException ignored) {
            }
        }
    }
}
Also used : ProtocolMapperConfigException(org.keycloak.protocol.ProtocolMapperConfigException) InputStream(java.io.InputStream) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 2 with ProtocolMapperConfigException

use of org.keycloak.protocol.ProtocolMapperConfigException in project keycloak by keycloak.

the class ScriptBasedOIDCProtocolMapper method validateConfig.

@Override
public void validateConfig(KeycloakSession session, RealmModel realm, ProtocolMapperContainerModel client, ProtocolMapperModel mapperModel) throws ProtocolMapperConfigException {
    String scriptCode = getScriptCode(mapperModel);
    if (scriptCode == null) {
        return;
    }
    ScriptingProvider scripting = session.getProvider(ScriptingProvider.class);
    ScriptModel scriptModel = scripting.createScript(realm.getId(), ScriptModel.TEXT_JAVASCRIPT, mapperModel.getName() + "-script", scriptCode, "");
    try {
        scripting.prepareEvaluatableScript(scriptModel);
    } catch (ScriptCompilationException ex) {
        throw new ProtocolMapperConfigException("error", "{0}", ex.getMessage());
    }
}
Also used : ScriptModel(org.keycloak.models.ScriptModel) ProtocolMapperConfigException(org.keycloak.protocol.ProtocolMapperConfigException) ScriptingProvider(org.keycloak.scripting.ScriptingProvider) ScriptCompilationException(org.keycloak.scripting.ScriptCompilationException)

Example 3 with ProtocolMapperConfigException

use of org.keycloak.protocol.ProtocolMapperConfigException in project keycloak by keycloak.

the class DefaultClientValidationProvider method validatePairwise.

private void validatePairwise(ValidationContext<ClientModel> context, String sectorIdentifierUri) {
    ClientModel client = context.getObjectToValidate();
    String rootUrl = client.getRootUrl();
    Set<String> redirectUris = new HashSet<>();
    if (client.getRedirectUris() != null)
        redirectUris.addAll(client.getRedirectUris());
    try {
        PairwiseSubMapperValidator.validate(context.getSession(), rootUrl, redirectUris, sectorIdentifierUri);
    } catch (ProtocolMapperConfigException e) {
        context.addError("pairWise", e.getMessage(), e.getMessageKey());
    }
}
Also used : ClientModel(org.keycloak.models.ClientModel) ProtocolMapperConfigException(org.keycloak.protocol.ProtocolMapperConfigException) HashSet(java.util.HashSet)

Example 4 with ProtocolMapperConfigException

use of org.keycloak.protocol.ProtocolMapperConfigException in project keycloak by keycloak.

the class ScriptBasedMapper method validateConfig.

@Override
public void validateConfig(KeycloakSession session, RealmModel realm, ProtocolMapperContainerModel client, ProtocolMapperModel mapperModel) throws ProtocolMapperConfigException {
    String scriptCode = mapperModel.getConfig().get(ProviderConfigProperty.SCRIPT_TYPE);
    if (scriptCode == null) {
        return;
    }
    ScriptingProvider scripting = session.getProvider(ScriptingProvider.class);
    ScriptModel scriptModel = scripting.createScript(realm.getId(), ScriptModel.TEXT_JAVASCRIPT, mapperModel.getName() + "-script", scriptCode, "");
    try {
        scripting.prepareEvaluatableScript(scriptModel);
    } catch (ScriptCompilationException ex) {
        throw new ProtocolMapperConfigException("error", "{0}", ex.getMessage());
    }
}
Also used : ProtocolMapperConfigException(org.keycloak.protocol.ProtocolMapperConfigException) ScriptingProvider(org.keycloak.scripting.ScriptingProvider) ScriptCompilationException(org.keycloak.scripting.ScriptCompilationException)

Example 5 with ProtocolMapperConfigException

use of org.keycloak.protocol.ProtocolMapperConfigException in project keycloak by keycloak.

the class PairwiseSubMapperValidator method validateClientRedirectUris.

private static void validateClientRedirectUris(String rootUrl, Set<String> redirectUris) throws ProtocolMapperConfigException {
    Set<String> hosts = new HashSet<>();
    for (String redirectUri : PairwiseSubMapperUtils.resolveValidRedirectUris(rootUrl, redirectUris)) {
        try {
            URI uri = new URI(redirectUri);
            hosts.add(uri.getHost());
        } catch (URISyntaxException e) {
            throw new ProtocolMapperConfigException("Client contained an invalid redirect URI.", PAIRWISE_MALFORMED_CLIENT_REDIRECT_URI, e);
        }
    }
    if (hosts.isEmpty()) {
        throw new ProtocolMapperConfigException("Client redirect URIs must contain a valid host component.", PAIRWISE_CLIENT_REDIRECT_URIS_MISSING_HOST);
    }
    if (hosts.size() > 1) {
        throw new ProtocolMapperConfigException("Without a configured Sector Identifier URI, client redirect URIs must not contain multiple host components.", PAIRWISE_CLIENT_REDIRECT_URIS_MULTIPLE_HOSTS);
    }
}
Also used : ProtocolMapperConfigException(org.keycloak.protocol.ProtocolMapperConfigException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) HashSet(java.util.HashSet)

Aggregations

ProtocolMapperConfigException (org.keycloak.protocol.ProtocolMapperConfigException)5 HashSet (java.util.HashSet)3 ScriptCompilationException (org.keycloak.scripting.ScriptCompilationException)2 ScriptingProvider (org.keycloak.scripting.ScriptingProvider)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ClientModel (org.keycloak.models.ClientModel)1 ScriptModel (org.keycloak.models.ScriptModel)1