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)

  

原文地址:https://www.cnblogs.com/sun_moon_earth/p/3587667.html