https://bz.apache.org/bugzilla/show_bug.cgi?id=60469
Bug ID: 60469
Summary: RealmBase#hasRole() imposes too much boilerplate code
if principal is not of type GenericPrincipal
Product: Tomcat 8
Version: 8.5.x-trunk
Hardware: All
OS: All
Status: NEW
Severity: major
Priority: P2
Component: Catalina
Assignee: [email protected]
Reporter: [email protected]
Target Milestone: ----
If your custom realm extends RealmBase but uses a custom principal, just like
mine, you need to duplicate the entire #hasRole(Wrapper, Princpal, String)
method.
The only interesting part for an implementor is
!(principal instanceof GenericPrincipal)
and
GenericPrincipal gp = (GenericPrincipal) principal;
boolean result = gp.hasRole(role);
A verbatim copy of the method is need just to adapt three lines. Which
basically means to double-check every Tomcat release for changes in this
method.
I am proposing to introduce a new sub-method: hasRoleInternal(Wrapper,
Principal, String) (or alike) which performs just the code above. The entire
boilerplate code remains in #hasRole()
My custom realm would simply do:
public boolean hasRoleInternal(Wrappr wrapper, Principal principal, String
role) {
if(!(principal instanceof CustomPrincipal))
return false;
CustomPrincipal cp = (CustomPrincipal) principal;
return cp.hasRole(role);
}
I can provide a patch for that if you agree with.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]