001    /**
002     * Implements the CFML Function isuserinrole
003     */
004    package railo.runtime.functions.decision;
005    
006    import railo.runtime.PageContext;
007    import railo.runtime.exp.PageException;
008    import railo.runtime.ext.function.Function;
009    import railo.runtime.security.Credential;
010    import railo.runtime.security.CredentialImpl;
011    
012    public final class IsUserInRole implements Function {
013            public static boolean call(PageContext pc , Object object) throws PageException {
014                String[] givenRoles = CredentialImpl.toRole(object);
015                Credential ru = pc.getRemoteUser();
016                if(ru==null) return false;
017                String[] roles = ru.getRoles();
018                for(int i=0;i<roles.length;i++) {
019                    for(int y=0;y<givenRoles.length;y++) {
020                        if(roles[i].equalsIgnoreCase(givenRoles[y])) return true;
021                    }
022                }
023                return false;
024            }
025    }