X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=cadi%2Fservlet-sample%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Faaf%2Fsample%2Fcadi%2FMyServlet.java;h=f11d8f891290a1334b986fbdeaa5475ab545a255;hb=4b5a7d721d994a49057e9bfb403c7bff1b376660;hp=466c02da9d3646e3cbcbaf0727e59519282ec048;hpb=824dc7b5fc0e1ccdf7f460479aff344727f0f01e;p=aaf%2Fauthz.git
diff --git a/cadi/servlet-sample/src/test/java/org/onap/aaf/sample/cadi/MyServlet.java b/cadi/servlet-sample/src/test/java/org/onap/aaf/sample/cadi/MyServlet.java
index 466c02da..f11d8f89 100644
--- a/cadi/servlet-sample/src/test/java/org/onap/aaf/sample/cadi/MyServlet.java
+++ b/cadi/servlet-sample/src/test/java/org/onap/aaf/sample/cadi/MyServlet.java
@@ -36,91 +36,91 @@ import org.onap.aaf.cadi.client.Future;
import org.onap.aaf.cadi.principal.TaggedPrincipal;
// Uncomment if you utilized the "MiniJASPIWrap" in the Servlet setup in "main()", and want to protect your service via Permission or mapped role
-// @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 {
- request = (HttpServletRequest)req;
- } catch (ClassCastException e) {
- throw new ServletException("Only serving HTTP today",e);
- }
-
- res.getOutputStream().println("
" + - request.getUserPrincipal()); - - String perm = request.getParameter("PERM"); - if(perm!=null) { - if(request.isUserInRole(perm)) { - if(perm.indexOf('|')<0) { - res.getOutputStream().println("\nCongrats!, You are in Role " + perm); - } else { - res.getOutputStream().println("\nCongrats!, You have Permission " + perm); - } - } else { - 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) { - try { - res.getOutputStream().println("----- Perms JSON from direct call -----"); - final Principal up = request.getUserPrincipal(); - TaggedPrincipal tp; - if(up instanceof TaggedPrincipal) { - tp = (TaggedPrincipal)up; - } else { - tp = new TaggedPrincipal() { - @Override - public String getName() { - return up.getName(); - } +// @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 { + request = (HttpServletRequest)req; + } catch (ClassCastException e) { + throw new ServletException("Only serving HTTP today",e); + } + + res.getOutputStream().println(""); + + } + + public String getServletInfo() { + return "MyServlet"; + } + + public void destroy() { + } + } \ No newline at end of fileCSP Servlet Test You're good to go!
" + + request.getUserPrincipal()); + + String perm = request.getParameter("PERM"); + if(perm!=null) { + if(request.isUserInRole(perm)) { + if(perm.indexOf('|')<0) { + res.getOutputStream().println("\nCongrats!, You are in Role " + perm); + } else { + res.getOutputStream().println("\nCongrats!, You have Permission " + perm); + } + } else { + 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) { + try { + res.getOutputStream().println("----- Perms JSON from direct call -----"); + final Principal up = request.getUserPrincipal(); + TaggedPrincipal tp; + if(up instanceof TaggedPrincipal) { + tp = (TaggedPrincipal)up; + } else { + tp = new TaggedPrincipal() { + @Override + public String getName() { + return up.getName(); + } - @Override - public String tag() { - return "Unknown"; - } - }; - } - // This call will be "as the user calling", but only if permission is set to trust. -// Future"); - - } - - public String getServletInfo() { - return "MyServlet"; - } - - public void destroy() { - } - } \ No newline at end of file + @Override + public String tag() { + return "Unknown"; + } + }; + } + // This call will be "as the user calling", but only if permission is set to trust. +// Futurefuture = aafcon.clientAs("2.0",tp).read("/authz/perms/user/"+request.getUserPrincipal().getName(),"application/Perms+json"); - Future future = aafcon.client("2.0").read("/authz/perms/user/"+request.getUserPrincipal().getName(),"application/Perms+json"); - if(future.get(4000 /* timeout */)) { - res.getOutputStream().print(future.value); - } else { - System.err.println(future.code() + ", " + future.body()); - res.getOutputStream().print(future.code() + ", " + future.body()); - } - } catch (Exception e) { - e.printStackTrace(); - } - } else { - res.getOutputStream().println("No AAFCon instantiated"); - } - res.getOutputStream().print(" future = aafcon.clientAs("2.0",tp).read("/authz/perms/user/"+request.getUserPrincipal().getName(),"application/Perms+json"); + Future future = aafcon.client("2.0").read("/authz/perms/user/"+request.getUserPrincipal().getName(),"application/Perms+json"); + if(future.get(4000 /* timeout */)) { + res.getOutputStream().print(future.value); + } else { + System.err.println(future.code() + ", " + future.body()); + res.getOutputStream().print(future.code() + ", " + future.body()); + } + } catch (Exception e) { + e.printStackTrace(); + } + } else { + res.getOutputStream().println("No AAFCon instantiated"); + } + res.getOutputStream().print("