代码如下:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
public class UserRealm extends Pac4jRealm(){
  
  @Override
  public AuthorizationInfo  doGetAuthorizationInfo(PrincipalCollection principals) {
    
    System.out.println("Onece");
    Set<String> roles=new HashSet()<>;
    roles.add("admin");
    SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
    authorizationInfo.setRoles(roles);
    return authorizationInfo ;
}
1
2
3
4
5
6
    @RequestMapping("/hello2")
    @ResponseBody
    public String hello2() {
        SecurityUtils.getSubject().checkRoles("user");
        return "success";
    }