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");
}
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));
}
Aggregations