use of org.apache.qpid.server.security.group.GroupPrincipal in project qpid-broker-j by apache.
the class UserPreferencesTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
_configuredObject = mock(ConfiguredObject.class);
_preferenceStore = mock(PreferenceStore.class);
_preferenceTaskExecutor = new CurrentThreadTaskExecutor();
_preferenceTaskExecutor.start();
_userPreferences = new UserPreferencesImpl(_preferenceTaskExecutor, _configuredObject, _preferenceStore, Collections.<Preference>emptyList());
_groupPrincipal = new GroupPrincipal(MYGROUP, (GroupProvider) null);
_owner = new AuthenticatedPrincipal(new UsernamePrincipal(MYUSER, null));
_subject = new Subject(true, Sets.newHashSet(_owner, _groupPrincipal), Collections.emptySet(), Collections.emptySet());
_testId = UUID.randomUUID();
}
use of org.apache.qpid.server.security.group.GroupPrincipal in project qpid-broker-j by apache.
the class SimpleLDAPAuthenticationManagerImpl method findGroups.
private Set<Principal> findGroups(DirContext context, String userDN) throws NamingException {
Set<Principal> groupPrincipals = new HashSet<>();
if (getGroupAttributeName() != null && !"".equals(getGroupAttributeName())) {
Attributes attributes = context.getAttributes(userDN, new String[] { getGroupAttributeName() });
NamingEnumeration<? extends Attribute> namingEnum = attributes.getAll();
while (namingEnum.hasMore()) {
Attribute attribute = namingEnum.next();
if (attribute != null) {
NamingEnumeration<?> attributeValues = attribute.getAll();
while (attributeValues.hasMore()) {
Object attributeValue = attributeValues.next();
if (attributeValue != null) {
String groupDN = String.valueOf(attributeValue);
groupPrincipals.add(new GroupPrincipal(groupDN, this));
}
}
}
}
}
if (getGroupSearchContext() != null && !"".equals(getGroupSearchContext()) && getGroupSearchFilter() != null && !"".equals(getGroupSearchFilter())) {
SearchControls searchControls = new SearchControls();
searchControls.setReturningAttributes(new String[] {});
searchControls.setSearchScope(isGroupSubtreeSearchScope() ? SearchControls.SUBTREE_SCOPE : SearchControls.ONELEVEL_SCOPE);
NamingEnumeration<?> groupEnumeration = context.search(getGroupSearchContext(), getGroupSearchFilter(), new String[] { encode(userDN) }, searchControls);
while (groupEnumeration.hasMore()) {
SearchResult result = (SearchResult) groupEnumeration.next();
String groupDN = result.getNameInNamespace();
groupPrincipals.add(new GroupPrincipal(groupDN, this));
}
}
return groupPrincipals;
}
use of org.apache.qpid.server.security.group.GroupPrincipal 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;
}
use of org.apache.qpid.server.security.group.GroupPrincipal 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);
}
use of org.apache.qpid.server.security.group.GroupPrincipal in project qpid-broker-j by apache.
the class TestPrincipalUtils method createTestSubject.
/**
* Creates a test subject, with exactly one {@link AuthenticatedPrincipal} and zero or more GroupPrincipals.
*/
public static Subject createTestSubject(final String username, final String... groups) {
final Set<Principal> principals = new HashSet<Principal>(1 + groups.length);
principals.add(new AuthenticatedPrincipal(new UsernamePrincipal(username, TEST_AUTH_PROVIDER)));
for (String group : groups) {
principals.add(new GroupPrincipal(group, TEST_AUTH_PROVIDER));
}
return new Subject(false, principals, Collections.EMPTY_SET, Collections.EMPTY_SET);
}
Aggregations