Search in sources :

Example 56 with SimplePrincipalCollection

use of org.apache.shiro.subject.SimplePrincipalCollection in project ddf by codice.

the class SubjectIdentityTest method testUniqueIdentifierNoEmail.

@Test
public void testUniqueIdentifierNoEmail() {
    org.apache.shiro.subject.Subject subject;
    org.apache.shiro.mgt.SecurityManager secManager = new DefaultSecurityManager();
    PrincipalCollection principals = new SimplePrincipalCollection(TEST_NAME, "testrealm");
    subject = new Subject.Builder(secManager).principals(principals).session(new SimpleSession()).buildSubject();
    assertThat(TEST_NAME, is(subjectIdentity.getUniqueIdentifier(subject)));
}
Also used : PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) DefaultSecurityManager(org.apache.shiro.mgt.DefaultSecurityManager) SimpleSession(org.apache.shiro.session.mgt.SimpleSession) Test(org.junit.Test)

Example 57 with SimplePrincipalCollection

use of org.apache.shiro.subject.SimplePrincipalCollection in project ddf by codice.

the class SubjectUtilsTest method testGetName.

@Test
public void testGetName() {
    org.apache.shiro.subject.Subject subject;
    org.apache.shiro.mgt.SecurityManager secManager = new DefaultSecurityManager();
    PrincipalCollection principals = new SimplePrincipalCollection(TEST_NAME, "testrealm");
    subject = new Subject.Builder(secManager).principals(principals).session(new SimpleSession()).authenticated(true).buildSubject();
    assertEquals(TEST_NAME, subjectUtils.getName(subject));
}
Also used : Subject(org.apache.shiro.subject.Subject) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) DefaultSecurityManager(org.apache.shiro.mgt.DefaultSecurityManager) SimpleSession(org.apache.shiro.session.mgt.SimpleSession) Subject(org.apache.shiro.subject.Subject) Test(org.junit.Test)

Example 58 with SimplePrincipalCollection

use of org.apache.shiro.subject.SimplePrincipalCollection in project ddf by codice.

the class PrincipalHolderTest method testSettingMultipleSecurityTokens.

@Test
public void testSettingMultipleSecurityTokens() {
    // given
    PrincipalHolder principalHolder = new PrincipalHolder();
    PrincipalCollection securityTokenOne = new SimplePrincipalCollection();
    PrincipalCollection securityTokenTwo = new SimplePrincipalCollection();
    // when
    principalHolder.setPrincipals(securityTokenOne);
    principalHolder.setPrincipals(securityTokenTwo);
    // then
    assertThat(principalHolder.getPrincipals(), is(securityTokenTwo));
}
Also used : PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) Test(org.junit.Test)

Example 59 with SimplePrincipalCollection

use of org.apache.shiro.subject.SimplePrincipalCollection in project ddf by codice.

the class PrincipalHolderTest method testRetrieveSecurityTokens.

@Test
public void testRetrieveSecurityTokens() {
    // given
    PrincipalHolder principalHolder = new PrincipalHolder();
    PrincipalCollection principalCollection = new SimplePrincipalCollection();
    // when
    principalHolder.setPrincipals(principalCollection);
    // then
    assertThat(principalHolder.getPrincipals(), is(principalCollection));
}
Also used : PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) Test(org.junit.Test)

Example 60 with SimplePrincipalCollection

use of org.apache.shiro.subject.SimplePrincipalCollection in project ddf by codice.

the class SessionManagementServiceImplTest method setup.

@Before
public void setup() throws ParserConfigurationException, SAXException, IOException, SecurityServiceException {
    request = mock(HttpServletRequest.class);
    principalCollection = new SimplePrincipalCollection();
    refreshedPrincipalCollection = mock(PrincipalCollection.class);
    principalHolderMock = mock(PrincipalHolder.class);
    manager = mock(SecurityManager.class);
    sessionFactory = mock(SessionFactory.class);
    session = mock(HttpSession.class);
    Subject subject = mock(Subject.class);
    when(request.getSession(false)).thenReturn(session);
    when(principalHolderMock.getPrincipals()).thenReturn(principalCollection);
    when(manager.getSubject(isA(BaseAuthenticationToken.class))).thenReturn(subject);
    when(sessionFactory.getOrCreateSession(any())).thenReturn(session);
    when(session.getAttribute(SecurityConstants.SECURITY_TOKEN_KEY)).thenReturn(principalHolderMock);
    when(session.getMaxInactiveInterval()).thenReturn(Integer.MAX_VALUE);
    when(subject.getPrincipals()).thenReturn(refreshedPrincipalCollection);
    sessionManagementServiceImpl = new SessionManagementServiceImpl();
    sessionManagementServiceImpl.setSessionFactory(sessionFactory);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SessionFactory(ddf.security.http.SessionFactory) SecurityManager(ddf.security.service.SecurityManager) HttpSession(javax.servlet.http.HttpSession) BaseAuthenticationToken(org.codice.ddf.security.handler.BaseAuthenticationToken) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) PrincipalHolder(ddf.security.common.PrincipalHolder) Subject(ddf.security.Subject) Before(org.junit.Before)

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