Search in sources :

Example 1 with QpidPrincipal

use of org.apache.qpid.server.security.QpidPrincipal in project qpid-broker-j by apache.

the class AuthIdentityConnectionPropertyEnricher method addConnectionProperties.

@Override
public Map<String, Object> addConnectionProperties(final AMQPConnection<?> connection, final Map<String, Object> existingProperties) {
    Map<String, Object> modifiedProperties = new LinkedHashMap<>(existingProperties);
    final Principal principal = connection.getAuthorizedPrincipal();
    if (principal != null) {
        GenericPrincipal genericPrincipal = new GenericPrincipal((QpidPrincipal) principal);
        Map<String, String> claims = new LinkedHashMap<>();
        claims.put("sub", genericPrincipal.toExternalForm());
        claims.put("preferred_username", genericPrincipal.getName());
        modifiedProperties.put("authenticated-identity", claims);
    }
    Set<GroupPrincipal> groups = connection.getSubject().getPrincipals(GroupPrincipal.class);
    List<String> groupNames = groups.stream().map(GroupPrincipal::getName).collect(Collectors.toList());
    modifiedProperties.put("groups", groupNames);
    return Collections.unmodifiableMap(modifiedProperties);
}
Also used : GenericPrincipal(org.apache.qpid.server.model.preferences.GenericPrincipal) GroupPrincipal(org.apache.qpid.server.security.group.GroupPrincipal) GroupPrincipal(org.apache.qpid.server.security.group.GroupPrincipal) GenericPrincipal(org.apache.qpid.server.model.preferences.GenericPrincipal) QpidPrincipal(org.apache.qpid.server.security.QpidPrincipal) Principal(java.security.Principal) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

Principal (java.security.Principal)1 LinkedHashMap (java.util.LinkedHashMap)1 GenericPrincipal (org.apache.qpid.server.model.preferences.GenericPrincipal)1 QpidPrincipal (org.apache.qpid.server.security.QpidPrincipal)1 GroupPrincipal (org.apache.qpid.server.security.group.GroupPrincipal)1