2016-02-03 10:20:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Red Hat, Inc. and/or its affiliates
|
|
|
|
* and other contributors as indicated by the @author tags.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2015-07-17 11:45:43 +00:00
|
|
|
package org.keycloak.protocol;
|
|
|
|
|
2015-10-02 19:01:39 +00:00
|
|
|
import org.keycloak.models.KeycloakSession;
|
2015-07-17 11:45:43 +00:00
|
|
|
import org.keycloak.models.ProtocolMapperModel;
|
|
|
|
import org.keycloak.models.UserModel;
|
2015-10-02 19:01:39 +00:00
|
|
|
import org.keycloak.protocol.oidc.OIDCLoginProtocol;
|
|
|
|
import org.keycloak.protocol.oidc.OIDCLoginProtocolFactory;
|
|
|
|
import org.keycloak.provider.ProviderFactory;
|
2015-07-17 11:45:43 +00:00
|
|
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
|
|
|
* @version $Revision: 1 $
|
|
|
|
*/
|
|
|
|
public class ProtocolMapperUtils {
|
2016-06-03 13:31:16 +00:00
|
|
|
|
|
|
|
public static final String USER_ROLE = "user.role";
|
2015-07-17 11:45:43 +00:00
|
|
|
public static final String USER_ATTRIBUTE = "user.attribute";
|
|
|
|
public static final String USER_SESSION_NOTE = "user.session.note";
|
|
|
|
public static final String MULTIVALUED = "multivalued";
|
2015-10-07 15:34:34 +00:00
|
|
|
public static final String USER_MODEL_PROPERTY_LABEL = "usermodel.prop.label";
|
|
|
|
public static final String USER_MODEL_PROPERTY_HELP_TEXT = "usermodel.prop.tooltip";
|
|
|
|
public static final String USER_MODEL_ATTRIBUTE_LABEL = "usermodel.attr.label";
|
|
|
|
public static final String USER_MODEL_ATTRIBUTE_HELP_TEXT = "usermodel.attr.tooltip";
|
2016-06-03 13:31:16 +00:00
|
|
|
|
|
|
|
public static final String USER_MODEL_CLIENT_ROLE_MAPPING_CLIENT_ID = "usermodel.clientRoleMapping.clientId";
|
|
|
|
public static final String USER_MODEL_CLIENT_ROLE_MAPPING_CLIENT_ID_LABEL = "usermodel.clientRoleMapping.clientId.label";
|
|
|
|
public static final String USER_MODEL_CLIENT_ROLE_MAPPING_CLIENT_ID_HELP_TEXT = "usermodel.clientRoleMapping.clientId.tooltip";
|
|
|
|
|
|
|
|
public static final String USER_MODEL_CLIENT_ROLE_MAPPING_ROLE_PREFIX = "usermodel.clientRoleMapping.rolePrefix";
|
|
|
|
public static final String USER_MODEL_CLIENT_ROLE_MAPPING_ROLE_PREFIX_LABEL = "usermodel.clientRoleMapping.rolePrefix.label";
|
|
|
|
public static final String USER_MODEL_CLIENT_ROLE_MAPPING_ROLE_PREFIX_HELP_TEXT = "usermodel.clientRoleMapping.rolePrefix.tooltip";
|
|
|
|
|
|
|
|
public static final String USER_MODEL_REALM_ROLE_MAPPING_ROLE_PREFIX = "usermodel.realmRoleMapping.rolePrefix";
|
|
|
|
public static final String USER_MODEL_REALM_ROLE_MAPPING_ROLE_PREFIX_LABEL = "usermodel.realmRoleMapping.rolePrefix.label";
|
|
|
|
public static final String USER_MODEL_REALM_ROLE_MAPPING_ROLE_PREFIX_HELP_TEXT = "usermodel.realmRoleMapping.rolePrefix.tooltip";
|
|
|
|
|
2015-10-07 15:34:34 +00:00
|
|
|
public static final String USER_SESSION_MODEL_NOTE_LABEL = "userSession.modelNote.label";
|
|
|
|
public static final String USER_SESSION_MODEL_NOTE_HELP_TEXT = "userSession.modelNote.tooltip";
|
|
|
|
public static final String MULTIVALUED_LABEL = "multivalued.label";
|
|
|
|
public static final String MULTIVALUED_HELP_TEXT = "multivalued.tooltip";
|
2015-07-17 11:45:43 +00:00
|
|
|
|
|
|
|
public static String getUserModelValue(UserModel user, String propertyName) {
|
|
|
|
|
|
|
|
String methodName = "get" + Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1);
|
|
|
|
try {
|
|
|
|
Method method = UserModel.class.getMethod(methodName);
|
|
|
|
Object val = method.invoke(user);
|
|
|
|
if (val != null) return val.toString();
|
|
|
|
} catch (Exception ignore) {
|
|
|
|
|
|
|
|
}
|
|
|
|
methodName = "is" + Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1);
|
|
|
|
try {
|
|
|
|
Method method = UserModel.class.getMethod(methodName);
|
|
|
|
Object val = method.invoke(user);
|
|
|
|
if (val != null) return val.toString();
|
|
|
|
} catch (Exception ignore) {
|
|
|
|
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-10-02 19:01:39 +00:00
|
|
|
/**
|
|
|
|
* Find the builtin locale mapper.
|
|
|
|
*
|
|
|
|
* @param session A KeycloakSession
|
|
|
|
* @return The builtin locale mapper.
|
|
|
|
*/
|
|
|
|
public static ProtocolMapperModel findLocaleMapper(KeycloakSession session) {
|
|
|
|
ProtocolMapperModel found = null;
|
|
|
|
for (ProviderFactory p : session.getKeycloakSessionFactory().getProviderFactories(LoginProtocol.class)) {
|
|
|
|
LoginProtocolFactory factory = (LoginProtocolFactory) p;
|
|
|
|
for (ProtocolMapperModel mapper : factory.getBuiltinMappers()) {
|
|
|
|
if (mapper.getName().equals(OIDCLoginProtocolFactory.LOCALE) && mapper.getProtocol().equals(OIDCLoginProtocol.LOGIN_PROTOCOL)) {
|
|
|
|
found = mapper;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (found != null) break;
|
|
|
|
}
|
|
|
|
return found;
|
|
|
|
}
|
2015-07-17 11:45:43 +00:00
|
|
|
}
|