use of org.apache.shiro.subject.PrincipalCollection 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");
}
use of org.apache.shiro.subject.PrincipalCollection in project perry by ca-cwds.
the class JwtRealmTest method testDoGetAuthorizationInfo.
@Test
public void testDoGetAuthorizationInfo() throws Exception {
PerryAccount perryAccount = perryAccount();
String jwtToken = generateToken(perryAccount.getUser());
List<Object> principals = Arrays.asList(perryAccount.getUser(), perryAccount, jwtToken);
PrincipalCollection principalCollection = new SimplePrincipalCollection(principals, "testRealm");
AuthorizationInfo authorizationInfo = jwtRealm.doGetAuthorizationInfo(principalCollection);
Assert.assertEquals(perryAccount.getRoles(), authorizationInfo.getRoles());
}
use of org.apache.shiro.subject.PrincipalCollection in project ART-TIME by Artezio.
the class ActiveDirectoryRealmTest method testDoGetAuthorizationInfo_ifPrincipalsCollectionNotEmpty.
@Test
public void testDoGetAuthorizationInfo_ifPrincipalsCollectionNotEmpty() throws Exception {
activeDirectoryRealm = PowerMock.createPartialMock(ActiveDirectoryRealm.class, "queryForAuthorizationInfo");
setField(activeDirectoryRealm, "projectRepository", projectRepository);
List<Project> projects = new ArrayList<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));
}
use of org.apache.shiro.subject.PrincipalCollection 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.PrincipalCollection 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));
}
Aggregations