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);
}
Aggregations