Class IdentityRestUtils


  • public final class IdentityRestUtils
    extends Object
    • 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
      • identityDetailsToJsonValue

        public static org.forgerock.json.JsonValue identityDetailsToJsonValue​(IdentityDetails details)
        Convert an IdentityDetails object into a JsonValue. 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.BadRequestException
        When 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 context
        jsonValue - The request
        objectType - 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 a CaseInsensitiveHashMap, 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 content
        attributeName - 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 a SelfServiceContext, 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 in
        jsonValue - The JSON representation of the identity to create
        objectType - 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 through
        realm - The realm the user is being registered in
        jsonValue - The request content, with the action parameters already stripped out
        objectType - 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 through
        context - The context of the request
        jsonValue - The JSON representation of the identity to create
        objectType - 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 converted
        realm - 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