use of org.apache.shiro.subject.SimplePrincipalCollection in project ART-TIME by Artezio.
the class ActiveDirectoryRealmTest method testDoGetAuthorizationInfo_ifPrincipalsCollectionNotContainsLdapRealm.
@Test
public void testDoGetAuthorizationInfo_ifPrincipalsCollectionNotContainsLdapRealm() throws NamingException, NoSuchFieldException {
activeDirectoryRealm = createMockBuilder(ActiveDirectoryRealm.class).addMockedMethod("queryForAuthorizationInfo").createMock();
PrincipalCollection principals = new SimplePrincipalCollection("principals", "jdbcRealm");
replay(activeDirectoryRealm);
AuthorizationInfo actual = activeDirectoryRealm.doGetAuthorizationInfo(principals);
verify(activeDirectoryRealm);
assertNull(actual);
}
use of org.apache.shiro.subject.SimplePrincipalCollection in project ART-TIME by Artezio.
the class ActiveDirectoryRealmTest method testDoGetAuthorizationInfo_ifExistManagedProjects.
@Test
public void testDoGetAuthorizationInfo_ifExistManagedProjects() throws Exception {
activeDirectoryRealm = PowerMock.createPartialMock(ActiveDirectoryRealm.class, "queryForAuthorizationInfo");
setField(activeDirectoryRealm, "projectRepository", projectRepository);
List<Project> projects = Arrays.asList(new Project());
PrincipalCollection principals = new SimplePrincipalCollection("principal", "ldapRealm");
AuthorizationInfo info = new SimpleAccount(principals, "credential", new HashSet<String>());
PowerMock.expectPrivate(activeDirectoryRealm, "queryForAuthorizationInfo", anyObject(PrincipalCollection.class), anyObject(LdapContextFactory.class)).andReturn(info);
expect(projectRepository.getProjectsByManager("principal")).andReturn(projects);
PowerMock.replayAll(projectRepository, activeDirectoryRealm);
AuthorizationInfo actual = activeDirectoryRealm.doGetAuthorizationInfo(principals);
PowerMock.verifyAll();
assertTrue(actual.getRoles().contains(UserRoles.EMPLOYEE_ROLE));
assertTrue(actual.getRoles().contains(UserRoles.PM_ROLE));
}
use of org.apache.shiro.subject.SimplePrincipalCollection in project ddf by codice.
the class CswEndpointTest method addSecurity.
private void addSecurity() {
org.apache.shiro.mgt.SecurityManager secManager = new DefaultSecurityManager();
PrincipalCollection principals = new SimplePrincipalCollection(USER_ID, "testrealm");
Subject subject = new Subject.Builder(secManager).principals(principals).session(new SimpleSession()).authenticated(true).buildSubject();
ThreadContext.bind(secManager);
ThreadContext.bind(subject);
}
use of org.apache.shiro.subject.SimplePrincipalCollection in project ddf by codice.
the class SubjectUtilsTest method testGetDefaultName.
@Test
public void testGetDefaultName() {
org.apache.shiro.subject.Subject subject;
org.apache.shiro.mgt.SecurityManager secManager = new DefaultSecurityManager();
PrincipalCollection principals = new SimplePrincipalCollection();
subject = new ddf.security.Subject.Builder(secManager).principals(principals).session(new SimpleSession()).authenticated(true).buildSubject();
assertEquals(DEFAULT_NAME, subjectUtils.getName(subject, DEFAULT_NAME));
assertEquals(DEFAULT_NAME, subjectUtils.getName(null, DEFAULT_NAME));
}
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;
}
Aggregations