return userPrincipal != null ? userPrincipal.getName() : null;
}
@Override
public boolean isUserInRole(final String role) {
final RoleMappingManager roleMappings = exchange.getAttachment(ServletAttachments.SERVLET_ROLE_MAPPINGS);
if (roleMappings == null) {
return false;
}
SecurityContext sc = exchange.getAttachment(SecurityContext.ATTACHMENT_KEY);
final ServletChain servlet = exchange.getAttachment(ServletAttachments.CURRENT_SERVLET);
//TODO: a more efficient imple
for (SecurityRoleRef ref : servlet.getManagedServlet().getServletInfo().getSecurityRoleRefs()) {
if (ref.getRole().equals(role)) {
return roleMappings.isUserInRole(ref.getLinkedRole(), sc);
}
}
return roleMappings.isUserInRole(role, sc);
}