Author: markt
Date: Wed Jun 17 09:04:26 2015
New Revision: 1685958

URL: http://svn.apache.org/r1685958
Log:
Add initial JASPIC unit tests
Patch by fjodorver

Added:
    tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/
    
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestJaspicAuthenticator.java
   (with props)
    
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestJaspicCallbackHandler.java
   (with props)
    
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestPrincipalGroupCallback.java
   (with props)
    tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/sam/
    
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/sam/TestAuthConfig.java
   (with props)
    
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/sam/TestAuthConfigProvider.java
   (with props)
    
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/sam/TestAuthModule.java
   (with props)
    
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/sam/TestServerAuthContext.java
   (with props)

Added: 
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestJaspicAuthenticator.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestJaspicAuthenticator.java?rev=1685958&view=auto
==============================================================================
--- 
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestJaspicAuthenticator.java
 (added)
+++ 
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestJaspicAuthenticator.java
 Wed Jun 17 09:04:26 2015
@@ -0,0 +1,109 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.catalina.authenticator.jaspic;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.List;
+
+import javax.security.auth.message.config.AuthConfigFactory;
+import javax.servlet.http.HttpServletResponse;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import org.apache.catalina.Context;
+import org.apache.catalina.authenticator.jaspic.sam.TestAuthConfigProvider;
+import org.apache.catalina.startup.TesterServlet;
+import org.apache.catalina.startup.Tomcat;
+import org.apache.catalina.startup.TomcatBaseTest;
+import org.apache.tomcat.util.buf.ByteChunk;
+import org.apache.tomcat.util.descriptor.web.LoginConfig;
+import org.apache.tomcat.util.descriptor.web.SecurityCollection;
+import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
+
+public class TestJaspicAuthenticator extends TomcatBaseTest {
+
+    private static String CONTEXT_PATH = "/foo";
+    private static final String URI_PROTECTED = "/protected";
+    private static final String ROLE = "group";
+    private Context context;
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+
+        Tomcat tomcat = getTomcatInstance();
+        this.context = tomcat.addContext(CONTEXT_PATH, null);
+
+        // Add protected servlet
+        Tomcat.addServlet(context, "TesterServlet3", new TesterServlet());
+        context.addServletMapping(URI_PROTECTED, "TesterServlet3");
+        SecurityCollection collection = new SecurityCollection();
+        collection.addPattern(URI_PROTECTED);
+
+        SecurityConstraint constraint = new SecurityConstraint();
+        constraint.addAuthRole(ROLE);
+        constraint.addCollection(collection);
+        context.addConstraint(constraint);
+
+        // Configure the authenticator
+        LoginConfig loginConfig = new LoginConfig();
+        loginConfig.setAuthMethod("JASPIC-BASIC");
+        context.setLoginConfig(loginConfig);
+        context.getPipeline().addValve(new JaspicAuthenticator());
+
+        AuthConfigFactory factory = AuthConfigFactory.getFactory();
+        factory.registerConfigProvider(new TestAuthConfigProvider(), 
"HttpServlet", null,
+                "Description");
+        getTomcatInstance().start();
+    }
+
+    @Test
+    public void shouldAuthenticateUsingRegistredJaspicProvider() throws 
Exception {
+        // given
+        String url = getUrl() + URI_PROTECTED + "?doLogin=true";
+        ByteChunk byteChunk = new ByteChunk();
+
+        // when
+        int result = getUrl(url, byteChunk, new HashMap<String, 
List<String>>());
+
+        // then
+        assertEquals(HttpServletResponse.SC_OK, result);
+        assertEquals("OK", byteChunk.toString());
+    }
+
+    @Test
+    public void shouldFailAuthenticationUsingRegistredJaspicProvider() throws 
Exception {
+        // given
+        String url = getUrl() + URI_PROTECTED;
+        ByteChunk byteChunk = new ByteChunk();
+
+        // when
+        int result = getUrl(url, byteChunk, new HashMap<String, 
List<String>>());
+
+        // then
+        assertEquals(HttpServletResponse.SC_FORBIDDEN, result);
+    }
+
+    private String getUrl() throws MalformedURLException {
+        return new URL("http", "localhost", getPort(), 
CONTEXT_PATH).toString();
+    }
+
+}

Propchange: 
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestJaspicAuthenticator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestJaspicCallbackHandler.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestJaspicCallbackHandler.java?rev=1685958&view=auto
==============================================================================
--- 
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestJaspicCallbackHandler.java
 (added)
+++ 
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestJaspicCallbackHandler.java
 Wed Jun 17 09:04:26 2015
@@ -0,0 +1,68 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.catalina.authenticator.jaspic;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.message.callback.CallerPrincipalCallback;
+import javax.security.auth.message.callback.GroupPrincipalCallback;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+
+import org.apache.catalina.realm.GenericPrincipal;
+
+public class TestJaspicCallbackHandler {
+    private static final String USER = "user";
+
+    private JaspicCallbackHandler jaspicCallbackHandler = new 
JaspicCallbackHandler(null);
+
+    @Test
+    public void shouldConvertCallbackToTomcatPrincipal() throws Exception {
+        // given
+        CallerPrincipalCallback callerCallback = new 
CallerPrincipalCallback(new Subject(), USER);
+        String[] groups = new String[] { "group" };
+
+        GroupPrincipalCallback groupCallback = new GroupPrincipalCallback(new 
Subject(), groups);
+        Callback[] callbacks = new Callback[] { callerCallback, groupCallback 
};
+
+        // when
+        jaspicCallbackHandler.handle(callbacks);
+        GenericPrincipal principal = jaspicCallbackHandler.getPrincipal();
+
+        // then
+        assertEquals(USER, principal.getName());
+        assertArrayEquals(groups, principal.getRoles());
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void shouldHandleUnknowCallback() throws Exception {
+        // given
+        Callback[] callbacks = new Callback[] { new Callback() {
+        } };
+
+        // when
+        jaspicCallbackHandler.handle(callbacks);
+
+        // then
+        fail("Should throw exception");
+    }
+
+}
\ No newline at end of file

Propchange: 
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestJaspicCallbackHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestPrincipalGroupCallback.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestPrincipalGroupCallback.java?rev=1685958&view=auto
==============================================================================
--- 
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestPrincipalGroupCallback.java
 (added)
+++ 
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestPrincipalGroupCallback.java
 Wed Jun 17 09:04:26 2015
@@ -0,0 +1,111 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.catalina.authenticator.jaspic;
+
+import java.security.Principal;
+
+import javax.security.auth.Subject;
+import javax.security.auth.message.callback.CallerPrincipalCallback;
+import javax.security.auth.message.callback.GroupPrincipalCallback;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Test;
+
+import org.apache.catalina.realm.GenericPrincipal;
+
+public class TestPrincipalGroupCallback {
+
+    private static final String USER_NAME = "user";
+
+    @Test
+    public void shouldAddUserPrincipal() throws Exception {
+        // given
+        PrincipalGroupCallback principalGroupCallback = new 
PrincipalGroupCallback();
+        UserPrincipal userPrincipal = new UserPrincipal(USER_NAME);
+        Subject subject = new Subject();
+        CallerPrincipalCallback callerCallback = new 
CallerPrincipalCallback(subject, userPrincipal);
+        principalGroupCallback.setCallerPrincipalCallback(callerCallback);
+        // when
+        GenericPrincipal principal = principalGroupCallback.getPrincipal();
+
+        // then
+        assertEquals(USER_NAME, principal.getName());
+        assertEquals(userPrincipal, principal.getUserPrincipal());
+    }
+
+    @Test
+    public void shouldCreatePrincipalWithUsername() throws Exception {
+        // given
+        PrincipalGroupCallback principalGroupCallback = new 
PrincipalGroupCallback();
+        Subject subject = new Subject();
+        CallerPrincipalCallback callerCallback = new 
CallerPrincipalCallback(subject, USER_NAME);
+        principalGroupCallback.setCallerPrincipalCallback(callerCallback);
+        // when
+        GenericPrincipal principal = principalGroupCallback.getPrincipal();
+
+        // then
+        assertEquals(USER_NAME, principal.getName());
+    }
+
+    @Test
+    public void shouldAddGroupsToPrincipal() throws Exception {
+        // given
+        PrincipalGroupCallback principalGroupCallback = new 
PrincipalGroupCallback();
+        Subject subject = new Subject();
+
+        CallerPrincipalCallback callerCallback = new 
CallerPrincipalCallback(subject, USER_NAME);
+        principalGroupCallback.setCallerPrincipalCallback(callerCallback);
+
+        String[] groups = new String[] { "group1" };
+        GroupPrincipalCallback groupCallback = new 
GroupPrincipalCallback(subject, groups);
+        principalGroupCallback.setCallerPrincipalCallback(groupCallback);
+
+        // when
+        GenericPrincipal principal = principalGroupCallback.getPrincipal();
+
+        // then
+        assertArrayEquals(principal.getRoles(), groups);
+    }
+
+    @Test
+    public void shouldReturnNullIfNoCallbackDefined() throws Exception {
+        // given
+        PrincipalGroupCallback principalGroupCallback = new 
PrincipalGroupCallback();
+
+        // when
+        GenericPrincipal principal = principalGroupCallback.getPrincipal();
+
+        // then
+        assertNull(principal);
+    }
+
+    private static class UserPrincipal implements Principal {
+        private String name;
+
+        public UserPrincipal(String name) {
+            this.name = name;
+        }
+
+        @Override
+        public String getName() {
+            return name;
+        }
+    }
+}
\ No newline at end of file

Propchange: 
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/TestPrincipalGroupCallback.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/sam/TestAuthConfig.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/sam/TestAuthConfig.java?rev=1685958&view=auto
==============================================================================
--- 
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/sam/TestAuthConfig.java
 (added)
+++ 
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/sam/TestAuthConfig.java
 Wed Jun 17 09:04:26 2015
@@ -0,0 +1,70 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.catalina.authenticator.jaspic.sam;
+
+import java.util.Map;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.message.AuthException;
+import javax.security.auth.message.MessageInfo;
+import javax.security.auth.message.config.ServerAuthConfig;
+import javax.security.auth.message.config.ServerAuthContext;
+import javax.security.auth.message.module.ServerAuthModule;
+
+public class TestAuthConfig implements ServerAuthConfig {
+    private CallbackHandler callbackHandler;
+    private ServerAuthModule authModule;
+
+    public TestAuthConfig(CallbackHandler callbackHandler, ServerAuthModule 
authModule) {
+        this.callbackHandler = callbackHandler;
+        this.authModule = authModule;
+    }
+
+    @Override
+    public String getMessageLayer() {
+        return "HttpServlet";
+    }
+
+    @Override
+    public String getAppContext() {
+        return null;
+    }
+
+    @Override
+    public String getAuthContextID(MessageInfo messageInfo) {
+        return null;
+    }
+
+    @Override
+    public void refresh() {
+
+    }
+
+    @Override
+    public boolean isProtected() {
+        return false;
+    }
+
+    @Override
+    @SuppressWarnings("rawtypes")
+    public ServerAuthContext getAuthContext(String authContextID, Subject 
serviceSubject,
+            Map properties) throws AuthException {
+        return new TestServerAuthContext(callbackHandler, authModule);
+    }
+
+}
\ No newline at end of file

Propchange: 
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/sam/TestAuthConfig.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/sam/TestAuthConfigProvider.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/sam/TestAuthConfigProvider.java?rev=1685958&view=auto
==============================================================================
--- 
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/sam/TestAuthConfigProvider.java
 (added)
+++ 
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/sam/TestAuthConfigProvider.java
 Wed Jun 17 09:04:26 2015
@@ -0,0 +1,42 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.catalina.authenticator.jaspic.sam;
+
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.message.AuthException;
+import javax.security.auth.message.config.AuthConfigProvider;
+import javax.security.auth.message.config.ClientAuthConfig;
+import javax.security.auth.message.config.ServerAuthConfig;
+
+public class TestAuthConfigProvider implements AuthConfigProvider {
+
+    @Override
+    public ClientAuthConfig getClientAuthConfig(String layer, String 
appContext,
+            CallbackHandler handler) throws AuthException {
+        return null;
+    }
+
+    @Override
+    public ServerAuthConfig getServerAuthConfig(String layer, String 
appContext,
+            CallbackHandler handler) throws AuthException {
+        return new TestAuthConfig(handler, new TestAuthModule());
+    }
+
+    @Override
+    public void refresh() {
+    }
+}
\ No newline at end of file

Propchange: 
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/sam/TestAuthConfigProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/sam/TestAuthModule.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/sam/TestAuthModule.java?rev=1685958&view=auto
==============================================================================
--- 
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/sam/TestAuthModule.java
 (added)
+++ 
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/sam/TestAuthModule.java
 Wed Jun 17 09:04:26 2015
@@ -0,0 +1,95 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.catalina.authenticator.jaspic.sam;
+
+import java.io.IOException;
+import java.security.Principal;
+import java.util.Map;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.security.auth.message.AuthException;
+import javax.security.auth.message.AuthStatus;
+import javax.security.auth.message.MessageInfo;
+import javax.security.auth.message.MessagePolicy;
+import javax.security.auth.message.callback.CallerPrincipalCallback;
+import javax.security.auth.message.callback.GroupPrincipalCallback;
+import javax.security.auth.message.module.ServerAuthModule;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public class TestAuthModule implements ServerAuthModule {
+
+    private CallbackHandler handler;
+    private Class<?>[] supportedMessageTypes = new Class[] { 
HttpServletRequest.class,
+            HttpServletResponse.class };
+
+    @Override
+    @SuppressWarnings("rawtypes")
+    public void initialize(MessagePolicy requestPolicy, MessagePolicy 
responsePolicy,
+            CallbackHandler handler, Map options) throws AuthException {
+        this.handler = handler;
+    }
+
+    @Override
+    public AuthStatus validateRequest(MessageInfo messageInfo, Subject 
clientSubject,
+            Subject serviceSubject) throws AuthException {
+        HttpServletRequest request = (HttpServletRequest) 
messageInfo.getRequestMessage();
+
+        Callback[] callbacks = getAuthenticationCallbacks(clientSubject, 
request);
+
+        try {
+            handler.handle(callbacks);
+        } catch (IOException | UnsupportedCallbackException e) {
+            throw (AuthException) new AuthException().initCause(e);
+        }
+
+        return AuthStatus.SUCCESS;
+    }
+
+    private Callback[] getAuthenticationCallbacks(Subject clientSubject, 
HttpServletRequest request) {
+        Callback[] callbacks;
+
+        if (request.getParameter("doLogin") != null) {
+            callbacks = new Callback[] { new 
CallerPrincipalCallback(clientSubject, "user"),
+                    new GroupPrincipalCallback(clientSubject, new String[] { 
"group" }) };
+        } else {
+            callbacks = new Callback[] { new 
CallerPrincipalCallback(clientSubject,
+                    (Principal) null) };
+        }
+        return callbacks;
+    }
+
+    @Override
+    public AuthStatus secureResponse(MessageInfo messageInfo, Subject 
serviceSubject)
+            throws AuthException {
+        return AuthStatus.SEND_SUCCESS;
+    }
+
+    @Override
+    public void cleanSubject(MessageInfo messageInfo, Subject subject) throws 
AuthException {
+
+    }
+
+    @Override
+    public Class<?>[] getSupportedMessageTypes() {
+        return supportedMessageTypes;
+    }
+
+}

Propchange: 
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/sam/TestAuthModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/sam/TestServerAuthContext.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/sam/TestServerAuthContext.java?rev=1685958&view=auto
==============================================================================
--- 
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/sam/TestServerAuthContext.java
 (added)
+++ 
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/sam/TestServerAuthContext.java
 Wed Jun 17 09:04:26 2015
@@ -0,0 +1,56 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.catalina.authenticator.jaspic.sam;
+
+import java.util.Collections;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.message.AuthException;
+import javax.security.auth.message.AuthStatus;
+import javax.security.auth.message.MessageInfo;
+import javax.security.auth.message.config.ServerAuthContext;
+import javax.security.auth.message.module.ServerAuthModule;
+
+public class TestServerAuthContext implements ServerAuthContext {
+
+    private final ServerAuthModule authModule;
+
+    public TestServerAuthContext(CallbackHandler handler, ServerAuthModule 
authModule)
+            throws AuthException {
+        this.authModule = authModule;
+        authModule.initialize(null, null, handler, Collections.emptyMap());
+    }
+
+    @Override
+    public AuthStatus validateRequest(MessageInfo messageInfo, Subject 
clientSubject,
+            Subject serviceSubject) throws AuthException {
+        return authModule.validateRequest(messageInfo, clientSubject, 
serviceSubject);
+    }
+
+    @Override
+    public AuthStatus secureResponse(MessageInfo messageInfo, Subject 
serviceSubject)
+            throws AuthException {
+        return authModule.secureResponse(messageInfo, serviceSubject);
+    }
+
+    @Override
+    public void cleanSubject(MessageInfo messageInfo, Subject subject) throws 
AuthException {
+        authModule.cleanSubject(messageInfo, subject);
+    }
+
+}

Propchange: 
tomcat/trunk/test/org/apache/catalina/authenticator/jaspic/sam/TestServerAuthContext.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to