Search in sources :

Example 46 with SimplePrincipalCollection

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");
}
Also used : SimpleAuthenticationInfo(org.apache.shiro.authc.SimpleAuthenticationInfo) ArrayList(java.util.ArrayList) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection)

Example 47 with SimplePrincipalCollection

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());
}
Also used : PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) AuthorizationInfo(org.apache.shiro.authz.AuthorizationInfo) Test(org.junit.Test) AbstractApiSecurityTest(gov.ca.cwds.security.AbstractApiSecurityTest)

Example 48 with SimplePrincipalCollection

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;
}
Also used : UserOnline(io.github.tesla.authz.domain.UserOnline) ArrayList(java.util.ArrayList) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) Session(org.apache.shiro.session.Session)

Example 49 with SimplePrincipalCollection

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);
}
Also used : User(com.moon.admin.domain.User) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection)

Example 50 with SimplePrincipalCollection

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));
}
Also used : SimpleAccount(org.apache.shiro.authc.SimpleAccount) Project(com.artezio.arttime.datamodel.Project) ArrayList(java.util.ArrayList) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) AuthorizationInfo(org.apache.shiro.authz.AuthorizationInfo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

SimplePrincipalCollection (org.apache.shiro.subject.SimplePrincipalCollection)87 Test (org.junit.Test)38 PrincipalCollection (org.apache.shiro.subject.PrincipalCollection)34 SimpleAuthenticationInfo (org.apache.shiro.authc.SimpleAuthenticationInfo)12 Element (org.w3c.dom.Element)12 SecurityAssertion (ddf.security.assertion.SecurityAssertion)11 AuthorizationInfo (org.apache.shiro.authz.AuthorizationInfo)11 DefaultSecurityManager (org.apache.shiro.mgt.DefaultSecurityManager)11 SecurityAssertionSaml (ddf.security.assertion.saml.impl.SecurityAssertionSaml)10 Principal (java.security.Principal)10 SAMLAuthenticationToken (org.codice.ddf.security.handler.SAMLAuthenticationToken)10 ArrayList (java.util.ArrayList)9 Subject (org.apache.shiro.subject.Subject)9 AuthenticationInfo (org.apache.shiro.authc.AuthenticationInfo)8 Subject (ddf.security.Subject)7 AuthenticationException (org.apache.shiro.authc.AuthenticationException)7 Realm (org.apache.shiro.realm.Realm)7 SimpleSession (org.apache.shiro.session.mgt.SimpleSession)7 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)6 Assertion (org.opensaml.saml.saml2.core.Assertion)6