use of org.apache.shiro.subject.SimplePrincipalCollection in project ddf by codice.
the class LoginFilterTest method setup.
@Before
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
SimplePrincipalCollection principalCollection = new SimplePrincipalCollection();
principalHolder = new PrincipalHolder();
principalHolder.setPrincipals(principalCollection);
loginFilter = new LoginFilter();
loginFilter.setSecurityManager(securityManagerMock);
loginFilter.setSessionFactory(sessionFactory);
loginFilter.setContextPolicyManager(contextPolicyManager);
loginFilter.init();
subject = new SubjectImpl(principalCollectionMock, true, null, mock(org.apache.shiro.mgt.SecurityManager.class));
when(securityAssertionMock.getToken()).thenReturn(goodSecurityTokenMock);
when(principalCollectionMock.byType(SecurityAssertion.class)).thenReturn(Collections.singletonList(securityAssertionMock));
when(principalCollectionMock.asList()).thenReturn(Arrays.asList(goodSecurityTokenMock));
when(securityManagerMock.getSubject(goodAuthenticationTokenMock)).thenReturn(subject);
when(securityManagerMock.getSubject(badAuthenticationTokenMock)).thenReturn(null);
when(sessionMock.getId()).thenReturn("sessionId");
when(requestMock.getSession(any(boolean.class))).thenReturn(sessionMock);
when(sessionFactory.getOrCreateSession(any())).thenReturn(sessionMock);
when(sessionMock.getAttribute(SECURITY_TOKEN_KEY)).thenReturn(principalHolder);
when(sessionFactory.getOrCreateSession(any())).thenReturn(sessionMock);
when(sessionMock.getAttribute(SECURITY_TOKEN_KEY)).thenReturn(principalHolder);
when(contextPolicyManager.getSessionAccess()).thenReturn(true);
}
use of org.apache.shiro.subject.SimplePrincipalCollection in project ddf by codice.
the class SamlAssertionValidatorImplTest method testValidateInvalidSignature.
@Test(expected = AuthenticationFailureException.class)
public void testValidateInvalidSignature() throws Exception {
Assertion assertion = createAssertion(false, false, "WRONG", new DateTime().minusSeconds(10));
Element securityToken = SAMLUtils.getInstance().getSecurityTokenFromSAMLAssertion(samlObjectToString(assertion));
SimplePrincipalCollection simplePrincipalCollection = new SimplePrincipalCollection();
simplePrincipalCollection.add(new SecurityAssertionSaml(securityToken), "default");
SAMLAuthenticationToken samlAuthenticationToken = new SAMLAuthenticationToken(simplePrincipalCollection, simplePrincipalCollection, "127.0.0.1");
samlAssertionValidator.validate(samlAuthenticationToken);
}
use of org.apache.shiro.subject.SimplePrincipalCollection in project ddf by codice.
the class SamlAssertionValidatorImplTest method testValidateIncorrectSamlVersion.
@Test(expected = AuthenticationFailureException.class)
public void testValidateIncorrectSamlVersion() throws Exception {
org.opensaml.saml.saml1.core.Assertion assertion = new org.opensaml.saml.saml1.core.impl.AssertionBuilder().buildObject();
Element securityToken = SAMLUtils.getInstance().getSecurityTokenFromSAMLAssertion(samlObjectToString(assertion));
SimplePrincipalCollection simplePrincipalCollection = new SimplePrincipalCollection();
simplePrincipalCollection.add(new SecurityAssertionSaml(securityToken), "default");
SAMLAuthenticationToken samlAuthenticationToken = new SAMLAuthenticationToken(simplePrincipalCollection, simplePrincipalCollection, "127.0.0.1");
samlAssertionValidator.validate(samlAuthenticationToken);
}
use of org.apache.shiro.subject.SimplePrincipalCollection in project ddf by codice.
the class SamlAssertionValidatorImplTest method testValidateBearerAssertion.
@Test
public void testValidateBearerAssertion() throws Exception {
Assertion assertion = createAssertion(true, true, ISSUER, new DateTime().plusDays(3));
Element securityToken = SAMLUtils.getInstance().getSecurityTokenFromSAMLAssertion(samlObjectToString(assertion));
SimplePrincipalCollection simplePrincipalCollection = new SimplePrincipalCollection();
simplePrincipalCollection.add(new SecurityAssertionSaml(securityToken), "default");
SAMLAuthenticationToken samlAuthenticationToken = new SAMLAuthenticationToken(simplePrincipalCollection, simplePrincipalCollection, "127.0.0.1");
X509Certificate[] certs = { certificate };
samlAuthenticationToken.setX509Certs(certs);
samlAssertionValidator.validate(samlAuthenticationToken);
}
use of org.apache.shiro.subject.SimplePrincipalCollection in project ddf by codice.
the class SamlAssertionValidatorImplTest method testValidateInvalidIssuer.
@Test(expected = AuthenticationFailureException.class)
public void testValidateInvalidIssuer() throws Exception {
Assertion assertion = createAssertion(false, true, "WRONG", new DateTime().minusSeconds(10));
Element securityToken = SAMLUtils.getInstance().getSecurityTokenFromSAMLAssertion(samlObjectToString(assertion));
SimplePrincipalCollection simplePrincipalCollection = new SimplePrincipalCollection();
simplePrincipalCollection.add(new SecurityAssertionSaml(securityToken), "default");
SAMLAuthenticationToken samlAuthenticationToken = new SAMLAuthenticationToken(simplePrincipalCollection, simplePrincipalCollection, "127.0.0.1");
samlAssertionValidator.validate(samlAuthenticationToken);
}
Aggregations