Search in sources :

Example 6 with AuthenticationInfo

use of org.apache.sling.auth.core.spi.AuthenticationInfo in project sling by apache.

the class SlingAuthenticatorTest method test_childNodeShouldHaveAuthenticationInfo3.

/**
     * Test is OK for same node with ending slash;
     * @throws Throwable
     */
@Test
public void test_childNodeShouldHaveAuthenticationInfo3() throws Throwable {
    final String AUTH_TYPE = "AUTH_TYPE_TEST";
    final String PROTECTED_PATH = "/content/en/test";
    final String REQUEST_CHILD_NODE = "/content/en/test/";
    SlingAuthenticator slingAuthenticator = new SlingAuthenticator();
    PathBasedHolderCache<AbstractAuthenticationHandlerHolder> authRequiredCache = new PathBasedHolderCache<AbstractAuthenticationHandlerHolder>();
    authRequiredCache.addHolder(buildAuthHolderForAuthTypeAndPath(AUTH_TYPE, PROTECTED_PATH));
    PrivateAccessor.setField(slingAuthenticator, "authHandlerCache", authRequiredCache);
    final HttpServletRequest request = context.mock(HttpServletRequest.class);
    buildExpectationsForRequestPathAndAuthPath(request, REQUEST_CHILD_NODE, PROTECTED_PATH);
    AuthenticationInfo authInfo = (AuthenticationInfo) PrivateAccessor.invoke(slingAuthenticator, "getAuthenticationInfo", new Class[] { HttpServletRequest.class, HttpServletResponse.class }, new Object[] { request, context.mock(HttpServletResponse.class) });
    /**
         * The AUTH TYPE defined aboved should  be used for the path /test and his children: eg /test/childnode.
         */
    Assert.assertTrue(AUTH_TYPE.equals(authInfo.getAuthType()));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) AuthenticationInfo(org.apache.sling.auth.core.spi.AuthenticationInfo) Test(org.junit.Test)

Example 7 with AuthenticationInfo

use of org.apache.sling.auth.core.spi.AuthenticationInfo in project sling by apache.

the class SlingAuthenticatorTest method test_childNodeShouldHaveAuthenticationInfo.

/**
     * Test is OK for child node;
     * @throws Throwable
     */
@Test
public void test_childNodeShouldHaveAuthenticationInfo() throws Throwable {
    final String AUTH_TYPE = "AUTH_TYPE_TEST";
    final String PROTECTED_PATH = "/content/en/test";
    final String REQUEST_CHILD_NODE = "/content/en/test/childnodetest";
    SlingAuthenticator slingAuthenticator = new SlingAuthenticator();
    PathBasedHolderCache<AbstractAuthenticationHandlerHolder> authRequiredCache = new PathBasedHolderCache<AbstractAuthenticationHandlerHolder>();
    authRequiredCache.addHolder(buildAuthHolderForAuthTypeAndPath(AUTH_TYPE, PROTECTED_PATH));
    PrivateAccessor.setField(slingAuthenticator, "authHandlerCache", authRequiredCache);
    final HttpServletRequest request = context.mock(HttpServletRequest.class);
    buildExpectationsForRequestPathAndAuthPath(request, REQUEST_CHILD_NODE, PROTECTED_PATH);
    AuthenticationInfo authInfo = (AuthenticationInfo) PrivateAccessor.invoke(slingAuthenticator, "getAuthenticationInfo", new Class[] { HttpServletRequest.class, HttpServletResponse.class }, new Object[] { request, context.mock(HttpServletResponse.class) });
    /**
         * The AUTH TYPE defined aboved should  be used for the path /test and his children: eg /test/childnode.
         */
    Assert.assertTrue(AUTH_TYPE.equals(authInfo.getAuthType()));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) AuthenticationInfo(org.apache.sling.auth.core.spi.AuthenticationInfo) Test(org.junit.Test)

Example 8 with AuthenticationInfo

use of org.apache.sling.auth.core.spi.AuthenticationInfo in project sling by apache.

the class AuthenticationInfoTest method testGetAuthType.

@Test
public void testGetAuthType() {
    final AuthenticationInfo info = new AuthenticationInfo("test");
    Assert.assertEquals("test", info.getAuthType());
    Assert.assertEquals("test", info.get(AuthenticationInfo.AUTH_TYPE));
    Assert.assertEquals(info.get(AuthenticationInfo.AUTH_TYPE), info.getAuthType());
}
Also used : AuthenticationInfo(org.apache.sling.auth.core.spi.AuthenticationInfo) Test(org.junit.Test)

Example 9 with AuthenticationInfo

use of org.apache.sling.auth.core.spi.AuthenticationInfo in project sling by apache.

the class AuthenticationInfoTest method testDOING_AUTH.

@Test
public void testDOING_AUTH() {
    final AuthenticationInfo da = AuthenticationInfo.DOING_AUTH;
    Assert.assertEquals("DOING_AUTH", da.getAuthType());
    da.clear();
    Assert.assertEquals("DOING_AUTH", da.getAuthType());
    da.put("test", "test");
    assertFalse(da.containsKey("test"));
}
Also used : AuthenticationInfo(org.apache.sling.auth.core.spi.AuthenticationInfo) Test(org.junit.Test)

Example 10 with AuthenticationInfo

use of org.apache.sling.auth.core.spi.AuthenticationInfo in project sling by apache.

the class AuthenticationInfoTest method testGetCredentials.

@Test
public void testGetCredentials() {
    final AuthenticationInfo info = new AuthenticationInfo("test");
    assertNull(info.get(CREDENTIALS));
    assertFalse(info.containsKey(CREDENTIALS));
    final Credentials creds = new SimpleCredentials("user", new char[0]);
    info.put(CREDENTIALS, creds);
    assertSame(creds, info.get(CREDENTIALS));
    final String user = "user";
    final char[] pwd = new char[5];
    final AuthenticationInfo infoCred = new AuthenticationInfo("TEST", user, pwd);
    // credentials not stored in the object
    assertFalse(infoCred.containsKey(CREDENTIALS));
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) AuthenticationInfo(org.apache.sling.auth.core.spi.AuthenticationInfo) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials) Test(org.junit.Test)

Aggregations

AuthenticationInfo (org.apache.sling.auth.core.spi.AuthenticationInfo)36 Test (org.junit.Test)25 HttpServletRequest (javax.servlet.http.HttpServletRequest)8 HttpServletResponse (javax.servlet.http.HttpServletResponse)8 SimpleCredentials (javax.jcr.SimpleCredentials)4 IOException (java.io.IOException)3 Collection (java.util.Collection)2 Credentials (javax.jcr.Credentials)2 LoginException (org.apache.sling.api.resource.LoginException)2 Method (java.lang.reflect.Method)1 AccountLockedException (javax.security.auth.login.AccountLockedException)1 AccountNotFoundException (javax.security.auth.login.AccountNotFoundException)1 CredentialExpiredException (javax.security.auth.login.CredentialExpiredException)1 Cookie (javax.servlet.http.Cookie)1 HttpSession (javax.servlet.http.HttpSession)1 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1 FormCredentials (org.apache.sling.auth.form.impl.jaas.FormCredentials)1 XingUser (org.apache.sling.auth.xing.api.XingUser)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 Token (org.scribe.model.Token)1