Hi All,
in jsp I use "<authz:authorize ifAllGranted="ROLE_ADMIN">"
could somebody tell me how can I do same check in servlet?
thanks.
Hi All,
in jsp I use "<authz:authorize ifAllGranted="ROLE_ADMIN">"
could somebody tell me how can I do same check in servlet?
thanks.
The following method can be used to see if a person has a permission.
jhCode:/** * Returns true if the current user has been granted the given permission, else false. * @param permToken * @return */ public boolean isAuthorized(String permToken) { // find the permission in the user's list of permissions SecurityContext context = SecurityContextHolder.getContext(); Authentication auth = context.getAuthentication(); GrantedAuthority[] auths = auth.getAuthorities(); for (int i = 0; i < auths.length; i++) { if (auths[i].getAuthority().equals(permToken)) { return true; } } // no permission found with the given name return false; }
Or Consider adding a SecurityContextHolderAwareRequestFilter to your filterChainProxy config.
http://www.acegisecurity.org/multipr...estFilter.html
Then you can simply use request.isUserInRole("YOUR_ROLE_HERE");
thanks! I've added SecurityContextHolderAwareRequestFilter and ... sometimes it works! the problem is - sometimes it doesn't .
sometimes request.isUserInRole returns false and I get nullpointerexception at the same time in this peace of code:
SecurityContext context = SecurityContextHolder.getContext();
Authentication auth = context.getAuthentication();
GrantedAuthority[] auths = auth.getAuthorities();
Originally Posted by RayKrueger