@Override
    public boolean isUserInRole(String role) {
        if (super.getSession(false) == null) {
            return super.isUserInRole(role);
        }

        // Check the wrapped request first
        final boolean isUserInRole = super.isUserInRole(role);
        if (isUserInRole) {
            return true;
        }

        // Find the group for the role, if not found return false
        IEntityGroup groupForRole = GroupService.findGroup(role);
        if (groupForRole == null) {
            final EntityIdentifier[] results =
                    GroupService.searchForGroups(
                            role, GroupService.SearchMethod.DISCRETE, IPerson.class);
            if (results == null || results.length == 0) {
                return false;
            }

            if (results.length > 1) {
                this.logger.warn(
                        results.length
                                + " groups were found for role '"
                                + role
                                + "'. The first result will be used.");
            }

            IGroupMember member = GroupService.getGroupMember(results[0]);
            if (member == null || !member.isGroup()) {
                return false;
            }
            groupForRole = member.asGroup();
        }

        // Load the group information about the current user
        final IUserInstance userInstance =
                this.userInstanceManager.getUserInstance(this.getWrappedRequest());
        final IPerson person = userInstance.getPerson();
        final EntityIdentifier personEntityId = person.getEntityIdentifier();
        final IGroupMember personGroupMember = GroupService.getGroupMember(personEntityId);

        final boolean rslt = personGroupMember.isDeepMemberOf(groupForRole);
        logger.trace(
                "Answering {} for isUserInRole where user='{}', role='{}', and groupForRole='{}'",
                rslt,
                person.getUserName(),
                role,
                groupForRole.getName());
        return rslt;
    }
@ Override public boolean isUserInRole ( String role ) { if ( super . getSession ( false ) == null ) { return super . isUserInRole ( role ) ; } final boolean isUserInRole = super . isUserInRole ( role ) ; if ( isUserInRole ) { return true ; } IEntityGroup groupForRole = GroupService . findGroup ( role ) ; if ( groupForRole == null ) { final EntityIdentifier [ ] results = GroupService . searchForGroups ( role , GroupService . SearchMethod . DISCRETE , IPerson . class ) ; if ( results == null || results . length == 0 ) { return false ; } if ( results . length > 1 ) { this . logger . warn ( results . length + " groups were found for role '" + role + "'. The first result will be used." ) ; } IGroupMember member = GroupService . getGroupMember ( results [ 0 ] ) ; if ( member == null || ! member . isGroup ( ) ) { return false ; } groupForRole = member . asGroup ( ) ; } final IUserInstance userInstance = this . userInstanceManager . getUserInstance ( this . getWrappedRequest ( ) ) ; final IPerson person = userInstance . getPerson ( ) ; final EntityIdentifier personEntityId = person . getEntityIdentifier ( ) ; final IGroupMember personGroupMember = GroupService . getGroupMember ( personEntityId ) ; final boolean rslt = personGroupMember . isDeepMemberOf ( groupForRole ) ; logger . trace ( "Answering {} for isUserInRole where user='{}', role='{}', and groupForRole='{}'" , rslt , person . getUserName ( ) , role , groupForRole . getName ( ) ) ; return rslt ; }
Determines whether or not the user is in the given role. The wrapped request is consulted
first then the {@link GroupService} is used to determine if a group exists for the specified
role and if the user is a member of it.

<p>Role is case sensitive.

@see
org.apereo.portal.utils.web.AbstractHttpServletRequestWrapper#isUserInRole(java.lang.String)