summaryrefslogtreecommitdiffstats
path: root/cadi/servlet-sample
diff options
context:
space:
mode:
Diffstat (limited to 'cadi/servlet-sample')
-rw-r--r--cadi/servlet-sample/src/main/java/org/onap/aaf/sample/cadi/MyServlet.java28
-rw-r--r--cadi/servlet-sample/src/main/java/org/onap/aaf/sample/cadi/jetty/Config.java8
-rw-r--r--cadi/servlet-sample/src/main/java/org/onap/aaf/sample/cadi/jetty/JettyServletServer.java22
-rw-r--r--cadi/servlet-sample/src/main/java/org/onap/aaf/sample/cadi/jetty/JettyStandalone.java8
-rw-r--r--cadi/servlet-sample/src/main/java/org/onap/aaf/sample/cadi/jetty/MiniJASPIWrap.java18
5 files changed, 42 insertions, 42 deletions
diff --git a/cadi/servlet-sample/src/main/java/org/onap/aaf/sample/cadi/MyServlet.java b/cadi/servlet-sample/src/main/java/org/onap/aaf/sample/cadi/MyServlet.java
index adb95d9b..8c3a1336 100644
--- a/cadi/servlet-sample/src/main/java/org/onap/aaf/sample/cadi/MyServlet.java
+++ b/cadi/servlet-sample/src/main/java/org/onap/aaf/sample/cadi/MyServlet.java
@@ -7,9 +7,9 @@
* 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.
@@ -40,15 +40,15 @@ import org.onap.aaf.cadi.principal.TaggedPrincipal;
// @RolesAllowed({"com.att.aaf.myPerm|myInstance|myAction"})
public class MyServlet implements Servlet {
private ServletConfig servletConfig;
-
+
public void init(ServletConfig config) throws ServletException {
servletConfig = config;
}
-
+
public ServletConfig getServletConfig() {
return servletConfig;
}
-
+
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
HttpServletRequest request;
try {
@@ -56,27 +56,27 @@ import org.onap.aaf.cadi.principal.TaggedPrincipal;
} catch (ClassCastException e) {
throw new ServletException("Only serving HTTP today",e);
}
-
+
res.getOutputStream().println("<html><header><title>CSP Servlet Test</title></header><body><h1>You're good to go!</h1><pre>" +
request.getUserPrincipal());
-
+
String perm = request.getParameter("PERM");
if (perm!=null) {
if (request.isUserInRole(perm)) {
- if (perm.indexOf('|')<0) {
+ if (perm.indexOf('|')<0) {
res.getOutputStream().println("\nCongrats!, You are in Role " + perm);
- } else {
+ } else {
res.getOutputStream().println("\nCongrats!, You have Permission " + perm);
}
} else {
- if (perm.indexOf('|')<0) {
+ if (perm.indexOf('|')<0) {
res.getOutputStream().println("\nSorry, you are NOT in Role " + perm);
} else {
res.getOutputStream().println("\nSorry, you do NOT have Permission " + perm);
}
}
}
-
+
// You can get the working AAFCon from Trans
AAFCon<?> aafcon = AAFCon.obtain(req);
if (aafcon!=null) {
@@ -115,13 +115,13 @@ import org.onap.aaf.cadi.principal.TaggedPrincipal;
res.getOutputStream().println("No AAFCon instantiated");
}
res.getOutputStream().print("</pre></body></html>");
-
+
}
-
+
public String getServletInfo() {
return "MyServlet";
}
-
+
public void destroy() {
}
} \ No newline at end of file
diff --git a/cadi/servlet-sample/src/main/java/org/onap/aaf/sample/cadi/jetty/Config.java b/cadi/servlet-sample/src/main/java/org/onap/aaf/sample/cadi/jetty/Config.java
index a45725d7..9f1c450f 100644
--- a/cadi/servlet-sample/src/main/java/org/onap/aaf/sample/cadi/jetty/Config.java
+++ b/cadi/servlet-sample/src/main/java/org/onap/aaf/sample/cadi/jetty/Config.java
@@ -7,9 +7,9 @@
* 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.
@@ -33,13 +33,13 @@ import org.onap.aaf.cadi.filter.CadiFilter;
public class Config {
/**
* Method to make jetty configurations (others?) with more complex function possible
- *
+ *
* @param sc
*/
public static final void addToContext(WebAppContext sc, String propFile) {
sc.addFilter(CadiFilter.class,"/*",EnumSet.of(DispatcherType.REQUEST));
sc.setInitParameter(org.onap.aaf.cadi.config.Config.CADI_PROP_FILES, propFile);
}
-
+
}
diff --git a/cadi/servlet-sample/src/main/java/org/onap/aaf/sample/cadi/jetty/JettyServletServer.java b/cadi/servlet-sample/src/main/java/org/onap/aaf/sample/cadi/jetty/JettyServletServer.java
index 165acffb..4800e133 100644
--- a/cadi/servlet-sample/src/main/java/org/onap/aaf/sample/cadi/jetty/JettyServletServer.java
+++ b/cadi/servlet-sample/src/main/java/org/onap/aaf/sample/cadi/jetty/JettyServletServer.java
@@ -7,9 +7,9 @@
* 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.
@@ -43,7 +43,7 @@ import org.onap.aaf.cadi.config.SecurityInfo;
import org.onap.aaf.cadi.filter.CadiFilter;
public abstract class JettyServletServer implements Servlet {
-
+
public static Server run(PropAccess access, String context, Class<? extends Servlet> servletCls, int port, String ...args) throws Exception {
// Defaults:
int blockingQueueSize = 10;
@@ -54,12 +54,12 @@ public abstract class JettyServletServer implements Servlet {
if (hostname==null) {
hostname = Inet4Address.getLocalHost().getHostName();
}
-
+
// Add your own Properties to override defaults
ArrayBlockingQueue<Runnable> queue = new ArrayBlockingQueue<Runnable>(blockingQueueSize);
QueuedThreadPool pool = new QueuedThreadPool(maxPoolSize,corePoolSize,keepAliveTime,queue);
- Server server = new Server(pool);
+ Server server = new Server(pool);
String protocol;
if (access.getProperty(Config.CADI_KEYSTORE_PASSWORD,null)==null) {
@@ -74,26 +74,26 @@ public abstract class JettyServletServer implements Servlet {
SslContextFactory scf = new SslContextFactory();
scf.setSslContext(securityInfo.getSSLContext());
scf.setWantClientAuth(true);
- ServerConnector sslConnector = new ServerConnector(server,scf);
+ ServerConnector sslConnector = new ServerConnector(server,scf);
sslConnector.setHost(hostname);
sslConnector.setPort(port);
server.addConnector(sslConnector);
protocol = "https";
}
-
+
// Setup Sample Servlet
CadiFilter cf = new CadiFilter(true,access);
FilterHolder cfh = new FilterHolder(cf);
-
+
ServletHandler shand = new ServletHandler();
shand.addFilterWithMapping(cfh, "/*", FilterMapping.ALL);
// To use normal Servlets, just add the class here... Actually, bug in Jetty... need to add with ServletHolder
ServletHolder sh = new ServletHolder();
sh.setServlet(servletCls.newInstance());
shand.addServletWithMapping(sh,"/*");
-
+
// To use JASPI Authorization Style to protect the servlet, wrap the Servlet
- // with the "MiniJSAPIWrap class, as shown here. Then add "@RolesAllowed" on your
+ // with the "MiniJSAPIWrap class, as shown here. Then add "@RolesAllowed" on your
// servlet (see sample). Use Pipe delimited Permissions, not AAF Roles in the line
// shand.addServletWithMapping(new MiniJASPIWrap(MyServlet.class),"/*");
// call initialize after start
@@ -104,7 +104,7 @@ public abstract class JettyServletServer implements Servlet {
// Startup the Server
server.setStopAtShutdown(true);
server.start();
-
+
access.log(Level.INFO,"TestServlet is running at " + protocol + "://"+hostname+':'+port+context);
return server;
}
diff --git a/cadi/servlet-sample/src/main/java/org/onap/aaf/sample/cadi/jetty/JettyStandalone.java b/cadi/servlet-sample/src/main/java/org/onap/aaf/sample/cadi/jetty/JettyStandalone.java
index 6edd6f5b..81b8f20b 100644
--- a/cadi/servlet-sample/src/main/java/org/onap/aaf/sample/cadi/jetty/JettyStandalone.java
+++ b/cadi/servlet-sample/src/main/java/org/onap/aaf/sample/cadi/jetty/JettyStandalone.java
@@ -7,9 +7,9 @@
* 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.
@@ -40,7 +40,7 @@ public class JettyStandalone {
} finally {
access.log(Level.INFO,"Stopping Service");
}
-
- }
+
+ }
}
diff --git a/cadi/servlet-sample/src/main/java/org/onap/aaf/sample/cadi/jetty/MiniJASPIWrap.java b/cadi/servlet-sample/src/main/java/org/onap/aaf/sample/cadi/jetty/MiniJASPIWrap.java
index 4d170f3f..2d34fa4c 100644
--- a/cadi/servlet-sample/src/main/java/org/onap/aaf/sample/cadi/jetty/MiniJASPIWrap.java
+++ b/cadi/servlet-sample/src/main/java/org/onap/aaf/sample/cadi/jetty/MiniJASPIWrap.java
@@ -7,9 +7,9 @@
* 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.
@@ -39,11 +39,11 @@ import org.onap.aaf.cadi.filter.RolesAllowed;
/**
* MiniJASPIWrap
- *
+ *
* Support the ability to check JASPI Annotation Style Authorizations.
- *
+ *
* This can be a clean way to enforce API Authorization without mistakes in code.
- *
+ *
* @author JonathanGathman
*
*/
@@ -67,9 +67,9 @@ public class MiniJASPIWrap extends ServletHolder {
/**
* handle
- *
+ *
* When utilized, this class authorizes the transaction by first calling the standard J2EE API call
- * "isUserInRole" with the role(s) found in the class Annotations (JASPI Style)
+ * "isUserInRole" with the role(s) found in the class Annotations (JASPI Style)
*/
@Override
public void handle(Request baseRequest, ServletRequest request, ServletResponse response) throws ServletException, UnavailableException, IOException {
@@ -77,7 +77,7 @@ public class MiniJASPIWrap extends ServletHolder {
super.handle(baseRequest, request, response);
} else { // Validate
try {
-
+
HttpServletRequest hreq = (HttpServletRequest)request;
boolean proceed = false;
for (String role : rolesAllowed.value()) {
@@ -95,7 +95,7 @@ public class MiniJASPIWrap extends ServletHolder {
} catch (ClassCastException e) {
throw new ServletException("JASPIWrap only supports HTTPServletRequest/HttpServletResponse");
}
- }
+ }
}
}