diff --git a/simple-webapp-okta/.gitignore b/simple-webapp-okta/.gitignore new file mode 100644 index 0000000..b393cfd --- /dev/null +++ b/simple-webapp-okta/.gitignore @@ -0,0 +1,4 @@ +.classpath +.project +.settings +/target/ diff --git a/simple-webapp-okta/charts/helm.yaml b/simple-webapp-okta/charts/helm.yaml new file mode 100644 index 0000000..8fb5b62 --- /dev/null +++ b/simple-webapp-okta/charts/helm.yaml @@ -0,0 +1,8 @@ +build: + uri: https://github.com/wildfly-security-incubator/elytron-examples.git + contextDir: simple-webapp-okta +deploy: + replicas: 1 + env: + - name: OIDC_PROVIDER_URL + value: \ No newline at end of file diff --git a/simple-webapp-okta/pom.xml b/simple-webapp-okta/pom.xml new file mode 100644 index 0000000..eeff35a --- /dev/null +++ b/simple-webapp-okta/pom.xml @@ -0,0 +1,107 @@ + + 4.0.0 + org.wildfly.security.examples + simple-webapp-okta + war + 2.0.0.Alpha1-SNAPSHOT + simple-webapp Maven Webapp + http://maven.apache.org + + + 11 + 11 + 4.2.0.Final + 3.3.2 + 30.0.0.Final + 4.0.0.Final + + + + + + org.wildfly.bom + wildfly-ee-with-tools + ${version.wildfly} + pom + import + + + + + + + jakarta.servlet + jakarta.servlet-api + provided + + + + junit + junit + 4.13.1 + test + + + org.wildfly.security + wildfly-elytron-http-oidc + 2.0.0.Final + compile + + + + + simple-webapp-okta + + + org.wildfly.plugins + wildfly-maven-plugin + ${version.wildfly.maven.plugin} + + + + org.apache.maven.plugins + maven-war-plugin + ${version.maven.war.plugin} + + + + + + + openshift + + + + org.wildfly.plugins + wildfly-maven-plugin + ${version.wildfly.maven.plugin} + + + + org.wildfly:wildfly-galleon-pack:${version.wildfly} + + + org.wildfly.cloud:wildfly-cloud-galleon-pack:${version.wildfly.cloud.galleon.pack} + + + + cloud-server + elytron-oidc-client + + simple-webapp-okta.war + + + + + package + + + + + + + + + + diff --git a/simple-webapp-okta/src/main/java/org/wildfly/security/examples/SecuredServlet.java b/simple-webapp-okta/src/main/java/org/wildfly/security/examples/SecuredServlet.java new file mode 100644 index 0000000..db32bcd --- /dev/null +++ b/simple-webapp-okta/src/main/java/org/wildfly/security/examples/SecuredServlet.java @@ -0,0 +1,60 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2017 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed 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.wildfly.security.examples; + +import java.io.IOException; +import java.io.PrintWriter; +import java.security.Principal; + +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.HttpMethodConstraint; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import org.jose4j.jwt.consumer.InvalidJwtException; +import org.jose4j.jwt.consumer.JwtConsumerBuilder; +import org.jose4j.jwt.JwtClaims; +import org.wildfly.security.http.oidc.OidcSecurityContext; + +/** + * A simple secured HTTP servlet. + * + * @author Darran Lofthouse + */ +@WebServlet("/secured") +public class SecuredServlet extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + try (PrintWriter writer = resp.getWriter()) { + writer.println(""); + writer.println(" Secured Servlet"); + writer.println(" "); + writer.println("

Secured Servlet

"); + writer.println("

"); + writer.print(" Current Principal '"); + OidcSecurityContext context = (OidcSecurityContext) req.getAttribute(OidcSecurityContext.class.getName()); + writer.print(context != null ? context.getIDToken().getClaimValueAsString("IDTClaim") : "NO AUTHENTICATED USER"); + writer.print("'"); + writer.println("

"); + writer.println(" "); + writer.println(""); + } + } +} diff --git a/simple-webapp-okta/src/main/webapp/WEB-INF/oidc.json b/simple-webapp-okta/src/main/webapp/WEB-INF/oidc.json new file mode 100644 index 0000000..339bce1 --- /dev/null +++ b/simple-webapp-okta/src/main/webapp/WEB-INF/oidc.json @@ -0,0 +1,10 @@ +{ + "client-id" : "CLIENT_ID", + "provider-url" : "${env.OIDC_PROVIDER_URL:CUSTOM_AUTH_SERVER}", + "public-client" : "false", + "principal-attribute" : "IDTClaim", + "ssl-required" : "EXTERNAL", + "credentials" : { + "secret" : "CLIENT_SECRET" + } +} diff --git a/simple-webapp-okta/src/main/webapp/WEB-INF/web.xml b/simple-webapp-okta/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..9c341e6 --- /dev/null +++ b/simple-webapp-okta/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,25 @@ + + + + + + + secured + /secured + + + * + + + + + OIDC + + + + * + + diff --git a/simple-webapp-okta/src/main/webapp/index.html b/simple-webapp-okta/src/main/webapp/index.html new file mode 100644 index 0000000..0331adb --- /dev/null +++ b/simple-webapp-okta/src/main/webapp/index.html @@ -0,0 +1,6 @@ + + +

Hello World!

+ Access Secured Servlet + +