Group and acl on Spring Security

后端 未结 3 1047
长情又很酷
长情又很酷 2021-01-31 06:53

I want to use Spring Security to manage user, group and permissions.

I want to use ACL to secure my domain objects but I can\'t find a way to assign a group to an acl.

3条回答
  •  庸人自扰
    2021-01-31 07:23

    I did something similar 'manually': i.e. I had my own code to determine which instances could be edited/deleted by a specific user and only relied on Spring security to ensure they had the right role to access the functionality and to provide role/authentication information for the current user.

    So in my code I determined the current principal (our own User class) and based on that I decided what rights this user had on a specific instance.

    public static User getCurrentUser() {
        User user = null;
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        if (auth != null) {
            Object principal = auth.getPrincipal();
            if (principal instanceof User) {
                user = (User)principal;
            }
        }
        return user;
    }
    

提交回复
热议问题