use of org.apache.shiro.subject.PrincipalCollection in project ddf by codice.
the class SubjectUtilsTest method getSubjectWithAttributes.
private ddf.security.Subject getSubjectWithAttributes(Map<String, List<String>> attributes) {
ddf.security.Subject subject = mock(ddf.security.Subject.class);
PrincipalCollection principalCollection = mock(PrincipalCollection.class);
SecurityAssertion securityAssertion = mock(SecurityAssertion.class);
AttributeStatement attributeStatement = mock(AttributeStatement.class);
List<Attribute> attrs = attributes.entrySet().stream().map(this::getAttribute).collect(Collectors.toList());
doReturn(principalCollection).when(subject).getPrincipals();
doReturn(Collections.singletonList(securityAssertion)).when(principalCollection).byType(SecurityAssertion.class);
doReturn(ImmutableList.of(securityAssertion)).when(principalCollection).byType(SecurityAssertion.class);
doReturn(Collections.singletonList(attributeStatement)).when(securityAssertion).getAttributeStatements();
doReturn(attrs).when(attributeStatement).getAttributes();
return subject;
}
use of org.apache.shiro.subject.PrincipalCollection in project ddf by codice.
the class PrincipalHolderTest method testRemoveSecurityToken.
@Test
public void testRemoveSecurityToken() {
// given
PrincipalHolder principalHolder = new PrincipalHolder();
PrincipalCollection securityToken = new SimplePrincipalCollection();
principalHolder.setPrincipals(securityToken);
// when
principalHolder.remove();
// then
assertNull(principalHolder.getPrincipals());
}
use of org.apache.shiro.subject.PrincipalCollection in project ddf by codice.
the class SubjectIdentityTest method getSubjectWithAttributes.
private Subject getSubjectWithAttributes(Map<String, List<String>> attributes) {
Subject subject = mock(Subject.class);
PrincipalCollection pc = mock(PrincipalCollection.class);
SecurityAssertion assertion = mock(SecurityAssertion.class);
AttributeStatement as = mock(AttributeStatement.class);
List<Attribute> attrs = attributes.entrySet().stream().map(this::getAttribute).collect(Collectors.toList());
doReturn(pc).when(subject).getPrincipals();
doReturn(Collections.singletonList(assertion)).when(pc).byType(SecurityAssertion.class);
doReturn(ImmutableList.of(assertion)).when(pc).byType(SecurityAssertion.class);
doReturn(Collections.singletonList(as)).when(assertion).getAttributeStatements();
doReturn(attrs).when(as).getAttributes();
return subject;
}
use of org.apache.shiro.subject.PrincipalCollection in project ddf by codice.
the class OperationPluginTest method setup.
@Before
public void setup() {
plugin = new OperationPlugin();
plugin.setPermissions(new PermissionsImpl());
AuthorizingRealm realm = mock(AuthorizingRealm.class);
when(realm.getName()).thenReturn("mockRealm");
when(realm.isPermitted(any(PrincipalCollection.class), any(Permission.class))).then(makeDecision());
Collection<Realm> realms = new ArrayList<Realm>();
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 = new MockSubject(manager, principalCollection);
}
use of org.apache.shiro.subject.PrincipalCollection in project ddf by codice.
the class SecurityPluginTest method setupMockSubject.
private Subject setupMockSubject() {
List<String> listOfAttributeValues = Arrays.asList(TEST_USER);
Attribute mockAttribute = mock(Attribute.class);
when(mockAttribute.getName()).thenReturn(SubjectOperations.EMAIL_ADDRESS_CLAIM_URI);
when(mockAttribute.getValues()).thenReturn(listOfAttributeValues);
List<Attribute> listOfAttributes = Arrays.asList(mockAttribute);
AttributeStatement mockAttributeStatement = mock(AttributeStatement.class);
when(mockAttributeStatement.getAttributes()).thenReturn(listOfAttributes);
List<AttributeStatement> listOfAttributeStatements = Arrays.asList(mockAttributeStatement);
Subject mockSubject = mock(Subject.class);
PrincipalCollection mockPrincipals = mock(PrincipalCollection.class);
SecurityAssertion mockSecurityAssertion = mock(SecurityAssertion.class);
when(mockSecurityAssertion.getAttributeStatements()).thenReturn(listOfAttributeStatements);
when(mockPrincipals.byType(SecurityAssertion.class)).thenReturn(Collections.singletonList(mockSecurityAssertion));
when(mockSubject.getPrincipals()).thenReturn(mockPrincipals);
return mockSubject;
}
Aggregations