use of org.apache.shiro.authc.AuthenticationToken in project ddf by codice.
the class CASTokenRequestHandlerTest method testDefaultAddress.
/**
* Tests that with no setting changes the ticket is returned.
*
* @throws SecurityServiceException
*/
@Test
public void testDefaultAddress() throws SecurityServiceException {
// setup mock classes
AttributePrincipal principal = mock(AttributePrincipal.class);
when(principal.getProxyTicketFor(anyString())).thenReturn(SAMPLE_TICKET);
HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getUserPrincipal()).thenReturn(principal);
CASTokenRequestHandler handler = new CASTokenRequestHandler();
handler.setStsClientConfiguration(mock(STSClientConfiguration.class));
Object token = handler.createToken(request);
assertTrue(token instanceof AuthenticationToken);
assertEquals(SAMPLE_TICKET, ((AuthenticationToken) token).getCredentials());
}
use of org.apache.shiro.authc.AuthenticationToken in project ddf by codice.
the class TestStsRealm method testSupports.
@Test
public void testSupports() {
StsRealm realm = new StsRealm();
AuthenticationToken authenticationToken = mock(SAMLAuthenticationToken.class);
when(authenticationToken.getCredentials()).thenReturn("creds");
boolean supports = realm.supports(authenticationToken);
assertEquals(true, supports);
authenticationToken = mock(BSTAuthenticationToken.class);
when(authenticationToken.getCredentials()).thenReturn("creds");
supports = realm.supports(authenticationToken);
assertEquals(true, supports);
authenticationToken = mock(BaseAuthenticationToken.class);
when(authenticationToken.getCredentials()).thenReturn("creds");
supports = realm.supports(authenticationToken);
assertEquals(true, supports);
authenticationToken = mock(BaseAuthenticationToken.class);
when(authenticationToken.getCredentials()).thenReturn(null);
supports = realm.supports(authenticationToken);
assertEquals(false, supports);
supports = realm.supports(null);
assertEquals(false, supports);
WssStsRealm wssStsRealm = new WssStsRealm();
BaseAuthenticationToken baseAuthTok = mock(BaseAuthenticationToken.class);
when(baseAuthTok.isUseWssSts()).thenReturn(false);
when(baseAuthTok.getCredentials()).thenReturn("creds");
assertEquals(true, realm.supports(baseAuthTok));
assertEquals(false, wssStsRealm.supports(baseAuthTok));
when(baseAuthTok.isUseWssSts()).thenReturn(true);
assertEquals(false, realm.supports(baseAuthTok));
assertEquals(true, wssStsRealm.supports(baseAuthTok));
}
use of org.apache.shiro.authc.AuthenticationToken in project ddf by codice.
the class TestStsRealm method testDoGetAuthenticationInfoSAML.
@Ignore
@Test
public void testDoGetAuthenticationInfoSAML() throws ParserConfigurationException, SAXException, IOException {
StsRealm realm = new StsRealm() {
protected SecurityToken renewSecurityToken(SecurityToken securityToken) {
return securityToken;
}
protected STSClient configureStsClient() {
return null;
}
};
Element issuedAssertion = this.readDocument("/saml.xml").getDocumentElement();
String assertionId = issuedAssertion.getAttributeNodeNS(null, "ID").getNodeValue();
SecurityToken token = new SecurityToken(assertionId, issuedAssertion, null);
AuthenticationToken authenticationToken = mock(SAMLAuthenticationToken.class);
when(authenticationToken.getCredentials()).thenReturn(token);
AuthenticationInfo authenticationInfo = realm.doGetAuthenticationInfo(authenticationToken);
assertNotNull(authenticationInfo.getCredentials());
assertNotNull(authenticationInfo.getPrincipals());
}
Aggregations