use of org.apache.shiro.subject.SimplePrincipalCollection in project ddf by codice.
the class SubjectImplTest method createTestCollection.
private PrincipalCollection createTestCollection() {
SimplePrincipalCollection collection = new SimplePrincipalCollection();
collection.add(TEST_SUBJECT_NAME, TEST_REALM_NAME);
return collection;
}
use of org.apache.shiro.subject.SimplePrincipalCollection in project ddf by codice.
the class SecurityManagerImplTest method testSecToken.
/**
* Creates mock objects and uses those to pass through the system when a security token is used.
*
* @throws SecurityServiceException
*/
@Test
public void testSecToken() throws SecurityServiceException {
// mock setup
SimplePrincipalCollection principals = new SimplePrincipalCollection();
SecurityToken secToken = new SecurityToken();
principals.add(secToken, REALM_NAME);
// realm
Realm realm = mock(Realm.class);
when(realm.getName()).thenReturn(REALM_NAME);
SecurityManagerImpl manager = new SecurityManagerImpl();
manager.setRealms(Arrays.asList(new Realm[] { realm }));
Subject subject = manager.getSubject(secToken);
assertNotNull(subject);
}
use of org.apache.shiro.subject.SimplePrincipalCollection in project ddf by codice.
the class SecurityManagerImpl method createPrincipalFromToken.
/**
* Creates a new principal object from an incoming security token.
*
* @param token SecurityToken that contains the principals.
* @return new SimplePrincipalCollection
*/
private SimplePrincipalCollection createPrincipalFromToken(SecurityToken token) {
SimplePrincipalCollection principals = new SimplePrincipalCollection();
for (Realm curRealm : realms) {
LOGGER.debug("Configuring settings for realm name: {} type: {}", curRealm.getName(), curRealm.getClass().toString());
LOGGER.debug("Is authorizer: {}, is AuthorizingRealm: {}", curRealm instanceof Authorizer, curRealm instanceof AuthorizingRealm);
SecurityAssertion securityAssertion = null;
try {
securityAssertion = new SecurityAssertionImpl(token, usernameAttributeList);
Principal principal = securityAssertion.getPrincipal();
if (principal != null) {
principals.add(principal.getName(), curRealm.getName());
}
} catch (Exception e) {
LOGGER.warn("Encountered error while trying to get the Principal for the SecurityToken. Security functions may not work properly.", e);
}
if (securityAssertion != null) {
principals.add(securityAssertion, curRealm.getName());
}
}
return principals;
}
use of org.apache.shiro.subject.SimplePrincipalCollection in project ddf by codice.
the class FilterPluginTest method setup.
@Before
public void setup() {
AuthorizingRealm realm = mock(AuthorizingRealm.class);
when(realm.getName()).thenReturn("mockRealm");
when(realm.isPermitted(any(PrincipalCollection.class), any(Permission.class))).then(makeDecision());
Collection<org.apache.shiro.realm.Realm> realms = new ArrayList<>();
realms.add(realm);
DefaultSecurityManager manager = new DefaultSecurityManager();
manager.setRealms(realms);
SimplePrincipalCollection principalCollection = new SimplePrincipalCollection(new Principal() {
@Override
public String getName() {
return "testuser";
}
}, realm.getName());
Subject systemSubject = new MockSubject(manager, principalCollection);
plugin = new FilterPlugin() {
@Override
protected Subject getSystemSubject() {
return systemSubject;
}
};
QueryRequestImpl request = getSampleRequest();
Map<String, Serializable> properties = new HashMap<>();
Subject subject = new MockSubject(manager, principalCollection);
properties.put(SecurityConstants.SECURITY_SUBJECT, subject);
request.setProperties(properties);
incomingResponse = new QueryResponseImpl(request);
ResourceRequest resourceRequest = mock(ResourceRequest.class);
when(resourceRequest.getProperties()).thenReturn(properties);
resourceResponse = new ResourceResponseImpl(resourceRequest, mock(Resource.class));
resourceResponse.setProperties(properties);
DeleteRequest deleteRequest = mock(DeleteRequest.class);
when(deleteRequest.getProperties()).thenReturn(properties);
List<Metacard> deletedMetacards = new ArrayList<>();
deletedMetacards.add(getExactRolesMetacard());
deleteResponse = new DeleteResponseImpl(deleteRequest, properties, deletedMetacards);
List<Metacard> badDeletedMetacards = new ArrayList<>();
badDeletedMetacards.add(getMoreRolesMetacard());
badDeleteResponse = new DeleteResponseImpl(deleteRequest, properties, badDeletedMetacards);
createRequest = new CreateRequestImpl(getExactRolesMetacard());
createRequest.setProperties(properties);
badCreateRequest = new CreateRequestImpl(getMoreRolesMetacard());
badCreateRequest.setProperties(properties);
updateRequest = new UpdateRequestImpl(getExactRolesMetacard().getId(), getExactRolesMetacard());
updateRequest.setProperties(properties);
ResultImpl result1 = new ResultImpl(getMoreRolesMetacard());
ResultImpl result2 = new ResultImpl(getMissingRolesMetacard());
ResultImpl result3 = new ResultImpl(getExactRolesMetacard());
ResultImpl result4 = new ResultImpl(getNoRolesMetacard());
ResultImpl result5 = new ResultImpl(getNoSecurityAttributeMetacard());
incomingResponse.addResult(result1, false);
incomingResponse.addResult(result2, false);
incomingResponse.addResult(result3, false);
incomingResponse.addResult(result4, false);
incomingResponse.addResult(result5, true);
}
use of org.apache.shiro.subject.SimplePrincipalCollection in project perry by ca-cwds.
the class AbstractRealm method getAuthenticationInfo.
private AuthenticationInfo getAuthenticationInfo(PerryAccount perryAccount, String token) {
List<Object> principals = new ArrayList<>();
principals.add(perryAccount.getUser());
principals.add(perryAccount);
principals.add(token);
PrincipalCollection principalCollection = new SimplePrincipalCollection(principals, getName());
return new SimpleAuthenticationInfo(principalCollection, "N/A");
}
Aggregations