View | Details | Raw Unified | Return to bug 22895
Collapse All | Expand All

(-)IsUserInRoleTag.java (-6 / +23 lines)
Lines 69-77 Link Here
69
69
70
/**
70
/**
71
 * JSP Tag <b>isuserinrole</b>, used to determine if HttpServletRequest
71
 * JSP Tag <b>isuserinrole</b>, used to determine if HttpServletRequest
72
 * is for an authenticated user in a role.
72
 * is for an authenticated user in a comma-separated list of roles.
73
 * <p>
73
 * <p>
74
 * Includes the body of the tag if an authenticated user in a role.
74
 * Includes the body of the tag if an authenticated user in one of a list of
75
 * roles.
75
 * <p>
76
 * <p>
76
 * Requires that the attribute <b>role</b> be set.
77
 * Requires that the attribute <b>role</b> be set.
77
 * <p>
78
 * <p>
Lines 98-119 Link Here
98
 * </pre>
99
 * </pre>
99
 *
100
 *
100
 * @author Glenn Nielsen
101
 * @author Glenn Nielsen
102
 * @author Matthew Sgarlata
101
 */
103
 */
102
104
103
public class IsUserInRoleTag extends TagSupport
105
public class IsUserInRoleTag extends TagSupport
104
{
106
{
107
	private static final String ROLE_DELIMITERS = ", \t\n\r\f";
108
	
105
    private boolean value = true;
109
    private boolean value = true;
106
    private String role = null;
110
    private String role = null;
107
111
108
    /**
112
    /**
109
     * Determines whether remote user is in a role.
113
     * Determines whether remote user is in one of the specified roles.
110
     *
114
     *
111
     * @return SKIP_BODY if isuserinrole doesn't match value, EVAL_BODY_include if isuserinrole matches value
115
     * @return SKIP_BODY if isuserinrole doesn't match value, EVAL_BODY_include if isuserinrole matches value
112
     */
116
     */
113
    public final int doStartTag() throws JspException
117
    public final int doStartTag() throws JspException
114
    {
118
    {
115
	boolean result = ((HttpServletRequest)pageContext.getRequest()).isUserInRole(role);
119
    boolean result = false;
116
120
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
121
    StringTokenizer tokenizer = new StringTokenizer(role, ROLE_DELIMITERS);
122
    
123
    // while the user has not matched one of the roles
124
    while (tokenizer.hasMoreTokens() && !result)
125
    {
126
    	if (request.isUserInRole(tokenizer.nextToken()))
127
    	{
128
    		result = true;
129
    	}
130
    }
131
    
117
	if( value == result )
132
	if( value == result )
118
	    return EVAL_BODY_INCLUDE;
133
	    return EVAL_BODY_INCLUDE;
119
134
Lines 132-138 Link Here
132
147
133
    /**
148
    /**
134
     * Set the required tag attribute <b>role</b> to the name
149
     * Set the required tag attribute <b>role</b> to the name
135
     * of the role you wish to test remote user for.
150
     * of the role(s) you wish to test remote user for.  If more than one role
151
     * is to be specified, the names of the roles should be separated with
152
     * commas.
136
     *
153
     *
137
     * @param String role name
154
     * @param String role name
138
     */
155
     */

Return to bug 22895