Search in sources :

Example 21 with AuthenticationInfo

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

the class AuthenticationInfoTest method testSetUser.

@Test
public void testSetUser() {
    final AuthenticationInfo info = new AuthenticationInfo("test", "user");
    Assert.assertEquals("user", info.getUser());
    info.setUser(null);
    Assert.assertEquals("user", info.getUser());
    info.setUser("dummy");
    Assert.assertEquals("dummy", info.getUser());
    info.setUser("");
    Assert.assertEquals("", info.getUser());
}
Also used : AuthenticationInfo(org.apache.sling.auth.core.spi.AuthenticationInfo) Test(org.junit.Test)

Example 22 with AuthenticationInfo

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

the class AuthenticationInfoTest method testGetPassword.

@Test
public void testGetPassword() {
    final char[] pwd = new char[6];
    final AuthenticationInfo info = new AuthenticationInfo("test", "name", pwd);
    assertSame(pwd, info.getPassword());
    assertEquals(pwd, (char[]) info.get(ResourceResolverFactory.PASSWORD));
    Assert.assertEquals(info.get(ResourceResolverFactory.PASSWORD), info.getPassword());
}
Also used : AuthenticationInfo(org.apache.sling.auth.core.spi.AuthenticationInfo) Test(org.junit.Test)

Example 23 with AuthenticationInfo

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

the class AuthenticationInfoTest method testSetPassword.

@Test
public void testSetPassword() {
    final char[] pwd = new char[6];
    final AuthenticationInfo info = new AuthenticationInfo("test", "name");
    assertFalse(info.containsKey(ResourceResolverFactory.PASSWORD));
    info.setPassword(pwd);
    assertSame(pwd, info.get(ResourceResolverFactory.PASSWORD));
    info.setPassword(null);
    assertSame(pwd, info.get(ResourceResolverFactory.PASSWORD));
}
Also used : AuthenticationInfo(org.apache.sling.auth.core.spi.AuthenticationInfo) Test(org.junit.Test)

Example 24 with AuthenticationInfo

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

the class EngineAuthenticationHandlerHolder method doExtractCredentials.

public AuthenticationInfo doExtractCredentials(HttpServletRequest request, HttpServletResponse response) {
    org.apache.sling.engine.auth.AuthenticationInfo engineAuthInfo = handler.authenticate(request, response);
    if (engineAuthInfo == null) {
        return null;
    } else if (engineAuthInfo == org.apache.sling.engine.auth.AuthenticationInfo.DOING_AUTH) {
        return AuthenticationInfo.DOING_AUTH;
    }
    // backwards compatibility support for JCR credentials and workspace
    // name now encapsulated in the JCR Resource bundle
    AuthenticationInfo info = new AuthenticationInfo(engineAuthInfo.getAuthType());
    info.put("user.jcr.credentials", engineAuthInfo.getCredentials());
    info.put("user.jcr.workspace", engineAuthInfo.getWorkspaceName());
    return info;
}
Also used : AuthenticationInfo(org.apache.sling.auth.core.spi.AuthenticationInfo)

Example 25 with AuthenticationInfo

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

the class SlingAuthenticatorTest method test_childNodeShouldHaveAuthenticationInfo2.

/**
     * Test is OK for same node;
     * @throws Throwable
     */
@Test
public void test_childNodeShouldHaveAuthenticationInfo2() 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)

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