-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #147 from arjantijms/tck
Initial commit for Jakarta Authentication TCK
- Loading branch information
Showing
151 changed files
with
9,994 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2022, 2022 Contributors to Eclipse Foundation. All rights reserved. | ||
This program and the accompanying materials are made available under the | ||
terms of the Eclipse Public License v. 2.0, which is available at | ||
http://www.eclipse.org/legal/epl-2.0. | ||
This Source Code may also be made available under the following Secondary | ||
Licenses when the conditions for such availability set forth in the | ||
Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
version 2 with the GNU Classpath Exception, which is available at | ||
https://www.gnu.org/software/classpath/license.html. | ||
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.eclipse.ee4j.tck.authentication</groupId> | ||
<artifactId>jakarta-authentication-tck</artifactId> | ||
<version>3.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>async-authentication</artifactId> | ||
<packaging>war</packaging> | ||
|
||
<name>Jakarta Authentication TCK - async-authentication</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.jakartaee</groupId> | ||
<artifactId>jaspic-common</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<skipTests>${skipEJB}</skipTests> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
53 changes: 53 additions & 0 deletions
53
...c/main/java/ee/jakarta/tck/authentication/test/ejbasyncauthentication/bean/AsyncBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright (c) 2022-2022 Contributors to the Eclipse Foundation | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
package ee.jakarta.tck.authentication.test.ejbasyncauthentication.bean; | ||
|
||
import static java.lang.Thread.interrupted; | ||
import static java.lang.Thread.sleep; | ||
|
||
import java.io.IOException; | ||
|
||
import jakarta.ejb.Asynchronous; | ||
import jakarta.ejb.Stateless; | ||
import jakarta.servlet.AsyncContext; | ||
|
||
/** | ||
* | ||
* @author Arjan Tijms | ||
* | ||
*/ | ||
@Stateless | ||
public class AsyncBean { | ||
|
||
@Asynchronous | ||
public void doAsync(AsyncContext asyncContext) { | ||
|
||
try { | ||
sleep(1000); | ||
} catch (InterruptedException e) { | ||
interrupted(); | ||
} | ||
|
||
try { | ||
asyncContext.getResponse().getWriter().write("async response"); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
asyncContext.complete(); | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
...karta/tck/authentication/test/ejbasyncauthentication/sam/SamAutoRegistrationListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (c) 2022-2022 Contributors to the Eclipse Foundation | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
package ee.jakarta.tck.authentication.test.ejbasyncauthentication.sam; | ||
|
||
import jakarta.security.auth.message.config.AuthConfigFactory; | ||
import jakarta.servlet.ServletContextEvent; | ||
import jakarta.servlet.ServletContextListener; | ||
import jakarta.servlet.annotation.WebListener; | ||
|
||
/** | ||
* | ||
* @author Arjan Tijms | ||
* | ||
*/ | ||
@WebListener | ||
public class SamAutoRegistrationListener implements ServletContextListener { | ||
|
||
@Override | ||
public void contextInitialized(ServletContextEvent sce) { | ||
AuthConfigFactory.getFactory() | ||
.registerServerAuthModule(new TestServerAuthModule(), sce.getServletContext()); | ||
} | ||
|
||
} |
99 changes: 99 additions & 0 deletions
99
...a/ee/jakarta/tck/authentication/test/ejbasyncauthentication/sam/TestServerAuthModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright (c) 2022-2022 Contributors to the Eclipse Foundation | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
package ee.jakarta.tck.authentication.test.ejbasyncauthentication.sam; | ||
|
||
import static jakarta.security.auth.message.AuthStatus.SUCCESS; | ||
|
||
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 jakarta.security.auth.message.AuthException; | ||
import jakarta.security.auth.message.AuthStatus; | ||
import jakarta.security.auth.message.MessageInfo; | ||
import jakarta.security.auth.message.MessagePolicy; | ||
import jakarta.security.auth.message.callback.CallerPrincipalCallback; | ||
import jakarta.security.auth.message.callback.GroupPrincipalCallback; | ||
import jakarta.security.auth.message.module.ServerAuthModule; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
|
||
/** | ||
* Very basic SAM that returns a single hardcoded user named "test" with role "architect" when the request parameter | ||
* <code>doLogin</code> is present. | ||
* | ||
* @author Arjan Tijms | ||
* | ||
*/ | ||
public class TestServerAuthModule implements ServerAuthModule { | ||
|
||
private CallbackHandler handler; | ||
private Class<?>[] supportedMessageTypes = new Class[] { HttpServletRequest.class, HttpServletResponse.class }; | ||
|
||
@Override | ||
public void initialize(MessagePolicy requestPolicy, MessagePolicy responsePolicy, CallbackHandler handler, Map<String, Object> 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; | ||
|
||
if (request.getParameter("doLogin") != null) { | ||
|
||
// For the test perform a login by directly "returning" the details of the authenticated user. | ||
// Normally credentials would be checked and the details fetched from some repository | ||
|
||
callbacks = new Callback[] { | ||
// The name of the authenticated user | ||
new CallerPrincipalCallback(clientSubject, "test"), | ||
// the roles of the authenticated user | ||
new GroupPrincipalCallback(clientSubject, new String[] { "architect" }) | ||
}; | ||
} else { | ||
|
||
// The Jakarta Authentication protocol for "do nothing" | ||
callbacks = new Callback[] { new CallerPrincipalCallback(clientSubject, (Principal) null) }; | ||
} | ||
|
||
try { | ||
|
||
// Communicate the details of the authenticated user to the container. In many | ||
// cases the handler will just store the details and the container will actually handle | ||
// the login after we return from this method. | ||
handler.handle(callbacks); | ||
|
||
} catch (IOException | UnsupportedCallbackException e) { | ||
throw (AuthException) new AuthException().initCause(e); | ||
} | ||
|
||
return SUCCESS; | ||
} | ||
|
||
@Override | ||
public Class<?>[] getSupportedMessageTypes() { | ||
return supportedMessageTypes; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
.../java/ee/jakarta/tck/authentication/test/ejbasyncauthentication/servlet/AsyncServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (c) 2022-2022 Contributors to the Eclipse Foundation | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
package ee.jakarta.tck.authentication.test.ejbasyncauthentication.servlet; | ||
|
||
import java.io.IOException; | ||
|
||
import ee.jakarta.tck.authentication.test.ejbasyncauthentication.bean.AsyncBean; | ||
import jakarta.ejb.EJB; | ||
import jakarta.servlet.AsyncContext; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.annotation.WebServlet; | ||
import jakarta.servlet.http.HttpServlet; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
|
||
/** | ||
* | ||
* @author Arjan Tijms | ||
* | ||
*/ | ||
@WebServlet(urlPatterns = "/public/asyncServlet", asyncSupported = true) | ||
public class AsyncServlet extends HttpServlet { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
@EJB | ||
private AsyncBean asyncBean; | ||
|
||
@Override | ||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
|
||
AsyncContext asyncContext = request.startAsync(); | ||
asyncContext.setTimeout(5000); | ||
|
||
asyncBean.doAsync(asyncContext); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2022, 2022 Contributors to Eclipse Foundation. All rights reserved. | ||
This program and the accompanying materials are made available under the | ||
terms of the Eclipse Public License v. 2.0, which is available at | ||
http://www.eclipse.org/legal/epl-2.0. | ||
This Source Code may also be made available under the following Secondary | ||
Licenses when the conditions for such availability set forth in the | ||
Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
version 2 with the GNU Classpath Exception, which is available at | ||
https://www.gnu.org/software/classpath/license.html. | ||
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
--> | ||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" | ||
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" | ||
version="3.0"> | ||
|
||
<security-constraint> | ||
<web-resource-collection> | ||
<web-resource-name>Test</web-resource-name> | ||
<url-pattern>/protected/*</url-pattern> | ||
</web-resource-collection> | ||
<auth-constraint> | ||
<role-name>architect</role-name> | ||
</auth-constraint> | ||
</security-constraint> | ||
|
||
<security-role> | ||
<role-name>architect</role-name> | ||
</security-role> | ||
|
||
</web-app> |
Oops, something went wrong.