Package org.forgerock.openam.core.rest
Class IdentityRestUtils
- java.lang.Object
-
- org.forgerock.openam.core.rest.IdentityRestUtils
-
public final class IdentityRestUtils extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static StringAGENT_TYPEstatic StringFIELD_MAILstatic StringGROUP_TYPEstatic StringREALMstatic StringUNIVERSAL_IDstatic StringUSER_KBA_ATTRIBUTEstatic StringUSER_TYPEstatic StringUSERNAME
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidchangeMemberships(org.forgerock.services.context.Context serverContext, String realm, String username, Set<String> groupNames)static voidchangePassword(org.forgerock.services.context.Context serverContext, String realm, String username, String oldPassword, String newPassword)static voidenforceSelfRegistrationWhiteList(ConsoleConfigHandler configHandler, String realm, org.forgerock.json.JsonValue jsonValue, String objectType)Applies the self service whitelist of valid creation attributes to an anonymous self-registration request.static voidenforceSelfRegistrationWhiteList(ConsoleConfigHandler configHandler, org.forgerock.services.context.Context context, org.forgerock.json.JsonValue jsonValue, String objectType)Applies the self service whitelist of valid creation attributes to a request that carries the calling context, which is what decides whether the whitelist applies at all.static voidenforceWhiteList(String realm, org.forgerock.json.JsonValue jsonValue, String objectType, Set<String> validUserAttributes)Applies the whitelist of valid attribute names regardless of the calling context.static voidenforceWhiteList(org.forgerock.services.context.Context context, org.forgerock.json.JsonValue jsonValue, String objectType, Set<String> validUserAttributes)When an instance of a user is created via self service, we impose additional rules for security purposes.static Map<String,Set<String>>getIdentityServicesAttributes(String realm, String objectType)static SSOTokengetSSOToken(String ssoTokenId)static org.forgerock.json.JsonValueidentityDetailsToJsonValue(IdentityDetails details)Convert anIdentityDetailsobject into aJsonValue.static booleanisUserActive(String uid)Uses an amAdmin SSOtoken to create an AMIdentity from the UID provided and checks whether the AMIdentity in context is active/inactivestatic IdentityDetailsjsonValueToIdentityDetails(String objectType, org.forgerock.json.JsonValue jVal, String realm)Returns an IdentityDetails from a JsonValue.static voidremoveIgnoringCase(org.forgerock.json.JsonValue jsonValue, String attributeName)Removes every spelling of an attribute from a request.
-
-
-
Field Detail
-
USER_TYPE
public static final String USER_TYPE
- See Also:
- Constant Field Values
-
GROUP_TYPE
public static final String GROUP_TYPE
- See Also:
- Constant Field Values
-
AGENT_TYPE
public static final String AGENT_TYPE
- See Also:
- Constant Field Values
-
UNIVERSAL_ID
public static final String UNIVERSAL_ID
- See Also:
- Constant Field Values
-
FIELD_MAIL
public static final String FIELD_MAIL
- See Also:
- Constant Field Values
-
REALM
public static final String REALM
- See Also:
- Constant Field Values
-
USER_KBA_ATTRIBUTE
public static final String USER_KBA_ATTRIBUTE
- See Also:
- Constant Field Values
-
USERNAME
public static final String USERNAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
changePassword
public static void changePassword(org.forgerock.services.context.Context serverContext, String realm, String username, String oldPassword, String newPassword) throws org.forgerock.json.resource.ResourceException- Throws:
org.forgerock.json.resource.ResourceException
-
changeMemberships
public static void changeMemberships(org.forgerock.services.context.Context serverContext, String realm, String username, Set<String> groupNames) throws org.forgerock.json.resource.ResourceException- Throws:
org.forgerock.json.resource.ResourceException
-
getIdentityServicesAttributes
public static Map<String,Set<String>> getIdentityServicesAttributes(String realm, String objectType)
-
getSSOToken
public static SSOToken getSSOToken(String ssoTokenId) throws SSOException
- Throws:
SSOException
-
identityDetailsToJsonValue
public static org.forgerock.json.JsonValue identityDetailsToJsonValue(IdentityDetails details)
Convert anIdentityDetailsobject into aJsonValue. Package private for IdentityResourceV2.- Parameters:
details- The IdentityDetails- Returns:
- The JsonValue
-
enforceWhiteList
public static void enforceWhiteList(org.forgerock.services.context.Context context, org.forgerock.json.JsonValue jsonValue, String objectType, Set<String> validUserAttributes) throws org.forgerock.json.resource.BadRequestExceptionWhen an instance of a user is created via self service, we impose additional rules for security purposes. Namely, we strictly apply a whitelist of valid attribute names to each attribute, and to any group membership, in the incoming JSON representation of the user object. This ensures a hacker can't manipulate the request and thereby pretend to be a manager, demigod or individual they are not. There is no return value. If you survive calling this function without an exception being thrown, there are no illegal values in the incoming JSON- Parameters:
context- The contextjsonValue- The requestobjectType- The type of object we're creating, user, group, etc.validUserAttributes- The set of valid user attributes- Throws:
org.forgerock.json.resource.BadRequestException- If the JSON representation of the user object cannot be converted into an identity, or contains an attribute or a group membership that is not in our whitelist
-
removeIgnoringCase
public static void removeIgnoringCase(org.forgerock.json.JsonValue jsonValue, String attributeName)Removes every spelling of an attribute from a request. The identity repository matches attribute names case insensitively - DJLDAPv3Repo wraps them in aCaseInsensitiveHashMap, and the directory does the same - so removing only the key as spelled here would leave a case variant of it behind to be created under the very name that was supposed to have been taken out.- Parameters:
jsonValue- The request contentattributeName- The attribute to remove, in any casing
-
enforceWhiteList
public static void enforceWhiteList(String realm, org.forgerock.json.JsonValue jsonValue, String objectType, Set<String> validUserAttributes) throws org.forgerock.json.resource.BadRequestException
Applies the whitelist of valid attribute names regardless of the calling context. The context based overload above only applies the whitelist to requests carrying aSelfServiceContext, which the self service framework adds to the requests it makes on behalf of an anonymous user. Endpoints that are anonymous in their own right, such as the legacy anonymousCreate action, never carry that context, so they have to ask for the whitelist explicitly.- Parameters:
realm- The realm the identity is being created injsonValue- The JSON representation of the identity to createobjectType- The type of object we're creating, user, group, etc.validUserAttributes- The set of valid user attributes- Throws:
org.forgerock.json.resource.BadRequestException- If the JSON representation of the user object cannot be converted into an identity, or contains an attribute or a group membership that is not in our whitelist
-
enforceSelfRegistrationWhiteList
public static void enforceSelfRegistrationWhiteList(ConsoleConfigHandler configHandler, String realm, org.forgerock.json.JsonValue jsonValue, String objectType) throws org.forgerock.json.resource.ResourceException
Applies the self service whitelist of valid creation attributes to an anonymous self-registration request. Shared by both versions of the users endpoint on purpose: the gap this closes was itself duplicated across them, so keeping the check in one place is what stops the two from drifting apart again.- Parameters:
configHandler- The handler the whitelist is configured throughrealm- The realm the user is being registered injsonValue- The request content, with the action parameters already stripped outobjectType- The type of object we're creating, user, group, etc.- Throws:
org.forgerock.json.resource.ResourceException- If the request sets an attribute or a group membership that is not whitelisted, or the whitelist itself cannot be read
-
enforceSelfRegistrationWhiteList
public static void enforceSelfRegistrationWhiteList(ConsoleConfigHandler configHandler, org.forgerock.services.context.Context context, org.forgerock.json.JsonValue jsonValue, String objectType) throws org.forgerock.json.resource.ResourceException
Applies the self service whitelist of valid creation attributes to a request that carries the calling context, which is what decides whether the whitelist applies at all.- Parameters:
configHandler- The handler the whitelist is configured throughcontext- The context of the requestjsonValue- The JSON representation of the identity to createobjectType- The type of object we're creating, user, group, etc.- Throws:
org.forgerock.json.resource.ResourceException- If the request sets an attribute or a group membership that is not whitelisted, or the whitelist itself cannot be read
-
jsonValueToIdentityDetails
public static IdentityDetails jsonValueToIdentityDetails(String objectType, org.forgerock.json.JsonValue jVal, String realm)
Returns an IdentityDetails from a JsonValue.- Parameters:
objectType- the object type, eg. user, group, etc.jVal- The JsonValue Object to be convertedrealm- The realm- Returns:
- The IdentityDetails object
-
isUserActive
public static boolean isUserActive(String uid) throws org.forgerock.json.resource.NotFoundException
Uses an amAdmin SSOtoken to create an AMIdentity from the UID provided and checks whether the AMIdentity in context is active/inactive- Parameters:
uid- the universal identifier of the user- Returns:
- true is the user is active, false otherwise
- Throws:
org.forgerock.json.resource.NotFoundException- invalid SSOToken, invalid UID
-
-