Search in sources :

Example 1 with UsernameFunctionProcessor

use of org.apache.knox.gateway.identityasserter.common.function.UsernameFunctionProcessor in project knox by apache.

the class UsernameFunctionProcessorTest method testDestroy.

@Test
public void testDestroy() throws Exception {
    UsernameFunctionProcessor processor = new UsernameFunctionProcessor();
    // Shouldn't fail.
    processor.destroy();
}
Also used : UsernameFunctionProcessor(org.apache.knox.gateway.identityasserter.common.function.UsernameFunctionProcessor) Test(org.junit.Test)

Example 2 with UsernameFunctionProcessor

use of org.apache.knox.gateway.identityasserter.common.function.UsernameFunctionProcessor in project knox by apache.

the class UsernameFunctionProcessorTest method testResolve.

@Test
public void testResolve() throws Exception {
    final UsernameFunctionProcessor processor = new UsernameFunctionProcessor();
    assertThat(processor.resolve(null, null), nullValue());
    assertThat(processor.resolve(null, Arrays.asList("test-input")), contains("test-input"));
    Subject subject = new Subject();
    subject.getPrincipals().add(new PrimaryPrincipal("test-username"));
    subject.setReadOnly();
    Subject.doAs(subject, new PrivilegedExceptionAction<Object>() {

        @Override
        public Object run() throws Exception {
            assertThat(processor.resolve(null, null), contains("test-username"));
            assertThat(processor.resolve(null, Arrays.asList("test-ignored")), contains("test-username"));
            return null;
        }
    });
}
Also used : PrimaryPrincipal(org.apache.knox.gateway.security.PrimaryPrincipal) UsernameFunctionProcessor(org.apache.knox.gateway.identityasserter.common.function.UsernameFunctionProcessor) Subject(javax.security.auth.Subject) ServletException(javax.servlet.ServletException) URISyntaxException(java.net.URISyntaxException) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with UsernameFunctionProcessor

use of org.apache.knox.gateway.identityasserter.common.function.UsernameFunctionProcessor in project knox by apache.

the class UsernameFunctionProcessorTest method testInitialize.

@Test
public void testInitialize() throws Exception {
    UsernameFunctionProcessor processor = new UsernameFunctionProcessor();
    // Shouldn't fail.
    processor.initialize(null, null);
}
Also used : UsernameFunctionProcessor(org.apache.knox.gateway.identityasserter.common.function.UsernameFunctionProcessor) Test(org.junit.Test)

Example 4 with UsernameFunctionProcessor

use of org.apache.knox.gateway.identityasserter.common.function.UsernameFunctionProcessor in project knox by apache.

the class UsernameFunctionProcessorTest method testServiceLoader.

@Test
public void testServiceLoader() throws Exception {
    ServiceLoader loader = ServiceLoader.load(UrlRewriteFunctionProcessor.class);
    Iterator iterator = loader.iterator();
    while (iterator.hasNext()) {
        Object object = iterator.next();
        if (object instanceof UsernameFunctionProcessor) {
            return;
        }
    }
    fail("Failed to find UsernameFunctionProcessor via service loader.");
}
Also used : ServiceLoader(java.util.ServiceLoader) Iterator(java.util.Iterator) UsernameFunctionProcessor(org.apache.knox.gateway.identityasserter.common.function.UsernameFunctionProcessor) Test(org.junit.Test)

Aggregations

UsernameFunctionProcessor (org.apache.knox.gateway.identityasserter.common.function.UsernameFunctionProcessor)4 Test (org.junit.Test)4 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 PrivilegedActionException (java.security.PrivilegedActionException)1 Iterator (java.util.Iterator)1 ServiceLoader (java.util.ServiceLoader)1 Subject (javax.security.auth.Subject)1 ServletException (javax.servlet.ServletException)1 PrimaryPrincipal (org.apache.knox.gateway.security.PrimaryPrincipal)1