Skip to content
This repository was archived by the owner on Dec 12, 2018. It is now read-only.
This repository was archived by the owner on Dec 12, 2018. It is now read-only.

expose a bean containing a map of Group name key and href value pairs #757

Open
@dogeared

Description

@dogeared

In order to assist users with creating method level authorization, we can expose a bean containing name value pairs of Stormpath Group information to be used in SpringEL expressions.

A reference implementation is as follows:

StormpathSpringSecurityAutoConfiguration:

    @Bean
    @Override
    @ConditionalOnMissingBean(name="stormpathAuthorities")
    public Map<String, String> stormpathAuthorities() {
        return super.stormpathAuthorities();
    }

AbstractStormpathSpringSecurityConfiguration:

    public Map<String, String> stormpathAuthorities() {
        Map<String, String> ret = new HashMap<>();

        for (Group group : application.getGroups()) {
            ret.put(group.getName(), group.getHref());
        }

        return ret;
    }

With this setup, the following SpringEL would be valid:

    @PreAuthorize("hasAuthority(@stormpathAuthorities['admin'])")
    public void ensureAdmin() {}

PROVIDED that there was a Stormpath Group named admin in a Directory mapped to the Application.

The above would ensure that only authenticated Accounts that are members of the admin group would be granted access to the method.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions