How to check “hasRole” in Java Code with Spring Security?

From:http://stackoverflow.com/questions/3021200/how-to-check-hasrole-in-java-code-with-spring-security

 

1

public String createForm(HttpSession session, HttpServletRequest request,  ModelMap   modelMap) {


    if (request.isUserInRole("ROLE_ADMIN")) {
        // code here
    }
}

2

HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
SecurityContextHolderAwareRequestWrapper sc = new SecurityContextHolderAwareRequestWrapper(req, "");

SecurityContextHolderAwareRequestWrapper.isUserInRole(String role)

  

posted @ 2014-03-08 11:12  轻松  阅读(1745)  评论(0编辑  收藏  举报