use of org.apache.shiro.subject.SimplePrincipalCollection 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.SimplePrincipalCollection in project tesla by linking12.
the class SessionService method list.
public List<UserOnline> list() {
List<UserOnline> list = new ArrayList<>();
Collection<Session> sessions = sessionDAO.getActiveSessions();
for (Session session : sessions) {
UserOnline userOnline = new UserOnline();
if (session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY) == null) {
continue;
} else {
SimplePrincipalCollection principalCollection = (SimplePrincipalCollection) session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY);
String userName = principalCollection.getRealmNames().iterator().next();
userOnline.setUsername(userName);
}
userOnline.setId((String) session.getId());
userOnline.setHost(session.getHost());
userOnline.setStartTimestamp(session.getStartTimestamp());
userOnline.setLastAccessTime(session.getLastAccessTime());
userOnline.setTimeout(session.getTimeout());
list.add(userOnline);
}
return list;
}
use of org.apache.shiro.subject.SimplePrincipalCollection in project moon by gentoo111.
the class ShiroRealm method getAuthorizationCacheKey.
/**
* 重写缓存key,否则集群下session共享时,会重复执行doGetAuthorizationInfo权限配置
*/
@Override
protected Object getAuthorizationCacheKey(PrincipalCollection principals) {
SimplePrincipalCollection principalCollection = (SimplePrincipalCollection) principals;
Object object = principalCollection.getPrimaryPrincipal();
if (object instanceof User) {
User user = (User) object;
return "authorization:cache:key:users:" + user.getId();
}
return super.getAuthorizationCacheKey(principals);
}
use of org.apache.shiro.subject.SimplePrincipalCollection 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.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);
}
Aggregations