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-securityjava

 

1spring

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


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

2session

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

SecurityContextHolderAwareRequestWrapper.isUserInRole(String role)
相关文章
相关标签/搜索