Search in sources :

Example 11 with AuthenticationToken

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());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) STSClientConfiguration(ddf.security.sts.client.configuration.STSClientConfiguration) AuthenticationToken(org.apache.shiro.authc.AuthenticationToken) AttributePrincipal(org.jasig.cas.client.authentication.AttributePrincipal) Test(org.junit.Test)

Example 12 with AuthenticationToken

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));
}
Also used : BSTAuthenticationToken(org.codice.ddf.security.handler.api.BSTAuthenticationToken) AuthenticationToken(org.apache.shiro.authc.AuthenticationToken) BaseAuthenticationToken(org.codice.ddf.security.handler.api.BaseAuthenticationToken) BSTAuthenticationToken(org.codice.ddf.security.handler.api.BSTAuthenticationToken) SAMLAuthenticationToken(org.codice.ddf.security.handler.api.SAMLAuthenticationToken) BaseAuthenticationToken(org.codice.ddf.security.handler.api.BaseAuthenticationToken) Test(org.junit.Test)

Example 13 with AuthenticationToken

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());
}
Also used : SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) AuthenticationToken(org.apache.shiro.authc.AuthenticationToken) BaseAuthenticationToken(org.codice.ddf.security.handler.api.BaseAuthenticationToken) BSTAuthenticationToken(org.codice.ddf.security.handler.api.BSTAuthenticationToken) SAMLAuthenticationToken(org.codice.ddf.security.handler.api.SAMLAuthenticationToken) Element(org.w3c.dom.Element) AuthenticationInfo(org.apache.shiro.authc.AuthenticationInfo) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

AuthenticationToken (org.apache.shiro.authc.AuthenticationToken)13 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)7 Test (org.junit.Test)6 AuthenticationException (org.apache.shiro.authc.AuthenticationException)4 AuthenticationInfo (org.apache.shiro.authc.AuthenticationInfo)4 Test (org.testng.annotations.Test)4 Subject (org.apache.shiro.subject.Subject)3 DelegatingSubject (org.apache.shiro.subject.support.DelegatingSubject)3 Subject (ddf.security.Subject)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)2 AuthorizationException (org.apache.shiro.authz.AuthorizationException)2 Realm (org.apache.shiro.realm.Realm)2 BSTAuthenticationToken (org.codice.ddf.security.handler.api.BSTAuthenticationToken)2 BaseAuthenticationToken (org.codice.ddf.security.handler.api.BaseAuthenticationToken)2 SAMLAuthenticationToken (org.codice.ddf.security.handler.api.SAMLAuthenticationToken)2 CatalogFramework (ddf.catalog.CatalogFramework)1 Attribute (ddf.catalog.data.Attribute)1 FederationException (ddf.catalog.federation.FederationException)1 FilterBuilder (ddf.catalog.filter.FilterBuilder)1