Search in sources :

Example 46 with PrincipalCollection

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

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());
}
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 PrincipalCollection

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

Example 49 with PrincipalCollection

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);
}
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) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 50 with PrincipalCollection

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));
}
Also used : SimpleAccount(org.apache.shiro.authc.SimpleAccount) Project(com.artezio.arttime.datamodel.Project) 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

PrincipalCollection (org.apache.shiro.subject.PrincipalCollection)88 SimplePrincipalCollection (org.apache.shiro.subject.SimplePrincipalCollection)40 Test (org.junit.Test)36 SecurityAssertion (ddf.security.assertion.SecurityAssertion)23 Subject (ddf.security.Subject)15 Subject (org.apache.shiro.subject.Subject)15 Principal (java.security.Principal)14 ArrayList (java.util.ArrayList)10 DefaultSecurityManager (org.apache.shiro.mgt.DefaultSecurityManager)10 AuthorizationInfo (org.apache.shiro.authz.AuthorizationInfo)9 Permission (org.apache.shiro.authz.Permission)8 Session (org.apache.shiro.session.Session)8 SimpleSession (org.apache.shiro.session.mgt.SimpleSession)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 Attribute (ddf.security.assertion.Attribute)5 Map (java.util.Map)5 AuthenticationToken (org.apache.shiro.authc.AuthenticationToken)5 CollectionPermission (ddf.security.permission.CollectionPermission)4