Search in sources :

Example 1 with OAuth2UserPrincipal

use of org.apache.qpid.server.security.auth.manager.oauth2.OAuth2UserPrincipal in project qpid-broker-j by apache.

the class CloudFoundryDashboardManagementGroupProviderImpl method getGroupPrincipalsForUser.

@Override
public Set<Principal> getGroupPrincipalsForUser(Principal userPrincipal) {
    if (!(userPrincipal instanceof OAuth2UserPrincipal)) {
        return Collections.emptySet();
    }
    if (_serviceToManagementGroupMapping == null) {
        throw new IllegalConfigurationException("CloudFoundryDashboardManagementGroupProvider serviceToManagementGroupMapping may not be null");
    }
    OAuth2UserPrincipal oauth2UserPrincipal = (OAuth2UserPrincipal) userPrincipal;
    String accessToken = oauth2UserPrincipal.getAccessToken();
    Set<Principal> groupPrincipals = new HashSet<>();
    for (Map.Entry<String, String> entry : _serviceToManagementGroupMapping.entrySet()) {
        String serviceInstanceId = entry.getKey();
        String managementGroupName = entry.getValue();
        if (mayManageServiceInstance(serviceInstanceId, accessToken)) {
            LOGGER.debug("Adding group '{}' to the set of Principals", managementGroupName);
            groupPrincipals.add(new GroupPrincipal(managementGroupName, this));
        } else {
            LOGGER.debug("CloudFoundryDashboardManagementEndpoint denied management permission for service instance '{}'", serviceInstanceId);
        }
    }
    return groupPrincipals;
}
Also used : OAuth2UserPrincipal(org.apache.qpid.server.security.auth.manager.oauth2.OAuth2UserPrincipal) GroupPrincipal(org.apache.qpid.server.security.group.GroupPrincipal) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) Map(java.util.Map) GroupPrincipal(org.apache.qpid.server.security.group.GroupPrincipal) OAuth2UserPrincipal(org.apache.qpid.server.security.auth.manager.oauth2.OAuth2UserPrincipal) Principal(java.security.Principal) HashSet(java.util.HashSet)

Aggregations

Principal (java.security.Principal)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)1 OAuth2UserPrincipal (org.apache.qpid.server.security.auth.manager.oauth2.OAuth2UserPrincipal)1 GroupPrincipal (org.apache.qpid.server.security.group.GroupPrincipal)1