405535 implement Request.isUserInRole(role) check security-role-refs defaulting to security-role if no matching ref

This commit is contained in:
Jan Bartel 2013-07-23 17:20:55 +10:00
parent 0aa2a5b6bb
commit f19421112a
2 changed files with 10 additions and 4 deletions

View File

@ -56,11 +56,17 @@ public class DefaultUserIdentity implements UserIdentity
public boolean isUserInRole(String role, Scope scope)
{
if (scope!=null && scope.getRoleRefMap()!=null)
role=scope.getRoleRefMap().get(role);
{
String mappedRole = scope.getRoleRefMap().get(role);
if (mappedRole != null)
role = mappedRole;
}
for (String r :_roles)
{
if (r.equals(role))
return true;
}
return false;
}

View File

@ -75,7 +75,7 @@ public class RoleAnnotationTest extends HttpServlet
result = request.isUserInRole("manager");
out.println("<br/><b>Result: isUserInRole(\"manager\")="+result+":"+ (result?" <span class=\"pass\">PASS":" <span class=\"fail\">FAIL")+"</span></b>");
result = request.isUserInRole("user");
out.println("<br/><b>Result: isUserInRole(\"user\")="+result+":"+ (result==false?" <span class=\"pass\">PASS":" <span class=\"fail\">FAIL")+"</span></b>");
out.println("<br/><b>Result: isUserInRole(\"user\")="+result+":"+ (result?" <span class=\"pass\">PASS":" <span class=\"fail\">FAIL")+"</span></b>");
String context = _config.getServletContext().getContextPath();
if (!context.endsWith("/"))
context += "/";