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) {
}
}
}
}
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());
}
}
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());
}
}
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());
}
}
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);
}
}
Aggregations