2015-02-28 16:17:06 +00:00
package org.keycloak.protocol ;
import org.keycloak.models.UserModel ;
import java.lang.reflect.Method ;
/ * *
* @author < a href = " mailto:bill@burkecentral.com " > Bill Burke < / a >
* @version $Revision : 1 $
* /
public class ProtocolMapperUtils {
2015-03-01 00:48:50 +00:00
public static final String USER_ATTRIBUTE = " user.attribute " ;
2015-03-04 19:02:53 +00:00
public static final String USER_SESSION_NOTE = " user.session.note " ;
2015-03-01 00:48:50 +00:00
public static final String USER_MODEL_PROPERTY_LABEL = " User Property " ;
2015-02-28 16:17:06 +00:00
public static final String USER_MODEL_PROPERTY_HELP_TEXT = " Name of the property method in the UserModel interface. For example, a value of 'email' would reference the UserModel.getEmail() method. " ;
2015-03-01 00:48:50 +00:00
public static final String USER_MODEL_ATTRIBUTE_LABEL = " User Attribute " ;
2015-02-28 16:17:06 +00:00
public static final String USER_MODEL_ATTRIBUTE_HELP_TEXT = " Name of stored user attribute which is the name of an attribute within the UserModel.attribute map. " ;
2015-03-04 19:02:53 +00:00
public static final String USER_SESSION_MODEL_NOTE_LABEL = " User Session Note " ;
public static final String USER_SESSION_MODEL_NOTE_HELP_TEXT = " Name of stored user session note within the UserSessionModel.note map. " ;
2015-02-28 16:17:06 +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 ;
}
}