SpelEvaluationException: EL1004E:(pos 0): Method call: Method hasPermission(java.lang.String) cannot be found on MethodSecurityExpressionRoot type

后端 未结 4 655
隐瞒了意图╮
隐瞒了意图╮ 2020-12-19 18:20

I add to my project a class CustomPermissionEvaluator, configured by a configuration class MethodSecurityConfig, but when I try run my application, after I inform my login c

4条回答
  •  天涯浪人
    2020-12-19 18:53

    Ok, finally I get to work done this part of my project. The final code for the CustomPermissionEvaluator is:

    @Component
    public class CustomPermissionEvaluator implements PermissionEvaluator {
    
        public CustomPermissionEvaluator() {
        }
    
        public boolean hasPermission(Authentication arg0, Object arg1) {
            System.out.println("CustomPermissionEvaluator.hasPermission");
            System.out.println("arg0 = "+arg0);
            System.out.println("arg1 = "+arg1);
    
            if (arg0 == null || !arg0.isAuthenticated()) {
                System.out.println("false");
                return false;
            }
            else {
                System.out.println("true");
                for(GrantedAuthority authority: arg0.getAuthorities()) {
                    if(authority.getAuthority().equals(arg1))
                        return true;
                }
                return false;
            }
        }
    
        @Override
        public boolean hasPermission(Authentication arg0, Object arg1, Object arg2) {
            System.out.println("CustomPermissionEvaluator.hasPermission");
            System.out.println("arg0 = "+arg0);
            System.out.println("arg1 = "+arg1);
            System.out.println("arg2 = "+arg2);
    
            if (arg0 == null || !arg0.isAuthenticated()) {
                System.out.println("false");
                return false;
            }
            else {
                System.out.println("true");
                for(GrantedAuthority authority: arg0.getAuthorities()) {
                    if(authority.getAuthority().equals(arg2))
                        return true;
                }
                return false;
            }
        }
    
        @Override
        public boolean hasPermission(Authentication arg0, Serializable arg1, String arg2, Object arg3) {
            throw new RuntimeException("Id-based permission evaluation not currently supported.");
        }
    
    }
    

提交回复
热议问题