From 4b5a7d721d994a49057e9bfb403c7bff1b376660 Mon Sep 17 00:00:00 2001 From: Instrumental Date: Fri, 7 Sep 2018 12:21:34 -0500 Subject: Mass removal of all Tabs (Style Warnings) Issue-ID: AAF-473 Change-Id: Iaf0ef8120882937959bb0065f2f6ba74a021940f Signed-off-by: Instrumental --- .../java/org/onap/aaf/auth/hello/AAF_Hello.java | 152 ++++++------ .../java/org/onap/aaf/auth/hello/API_Hello.java | 262 ++++++++++----------- .../org/onap/aaf/auth/hello/test/HelloTester.java | 76 +++--- 3 files changed, 245 insertions(+), 245 deletions(-) (limited to 'auth/auth-hello') diff --git a/auth/auth-hello/src/main/java/org/onap/aaf/auth/hello/AAF_Hello.java b/auth/auth-hello/src/main/java/org/onap/aaf/auth/hello/AAF_Hello.java index 9617f191..34371a1f 100644 --- a/auth/auth-hello/src/main/java/org/onap/aaf/auth/hello/AAF_Hello.java +++ b/auth/auth-hello/src/main/java/org/onap/aaf/auth/hello/AAF_Hello.java @@ -48,85 +48,85 @@ import org.onap.aaf.misc.env.APIException; import org.onap.aaf.misc.env.Env; public class AAF_Hello extends AbsService { - public enum API{TOKEN_REQ, TOKEN,INTROSPECT, ERROR,VOID}; - public Map cacheUser; - public AAFAuthn aafAuthn; - public AAFLurPerm aafLurPerm; - - /** - * Construct AuthzAPI with all the Context Supporting Routes that Authz needs - * - * @param env - * @param si - * @param dm - * @param decryptor - * @throws APIException - */ - public AAF_Hello(final AuthzEnv env) throws Exception { - super(env.access(), env); - - aafLurPerm = aafCon().newLur(); - // Note: If you need both Authn and Authz construct the following: - aafAuthn = aafCon().newAuthn(aafLurPerm); + public enum API{TOKEN_REQ, TOKEN,INTROSPECT, ERROR,VOID}; + public Map cacheUser; + public AAFAuthn aafAuthn; + public AAFLurPerm aafLurPerm; + + /** + * Construct AuthzAPI with all the Context Supporting Routes that Authz needs + * + * @param env + * @param si + * @param dm + * @param decryptor + * @throws APIException + */ + public AAF_Hello(final AuthzEnv env) throws Exception { + super(env.access(), env); + + aafLurPerm = aafCon().newLur(); + // Note: If you need both Authn and Authz construct the following: + aafAuthn = aafCon().newAuthn(aafLurPerm); - String aaf_env = env.getProperty(Config.AAF_ENV); - if(aaf_env==null) { - throw new APIException("aaf_env needs to be set"); - } - - // Initialize Facade for all uses - AuthzTrans trans = env.newTrans(); - StringBuilder sb = new StringBuilder(); - trans.auditTrail(2, sb); - trans.init().log(sb); - - API_Hello.init(this); + String aaf_env = env.getProperty(Config.AAF_ENV); + if(aaf_env==null) { + throw new APIException("aaf_env needs to be set"); + } + + // Initialize Facade for all uses + AuthzTrans trans = env.newTrans(); + StringBuilder sb = new StringBuilder(); + trans.auditTrail(2, sb); + trans.init().log(sb); + + API_Hello.init(this); } - - /** - * Setup XML and JSON implementations for each supported Version type - * - * We do this by taking the Code passed in and creating clones of these with the appropriate Facades and properties - * to do Versions and Content switches - * - */ - public void route(HttpMethods meth, String path, API api, HttpCode code) throws Exception { - String version = "1.0"; - // Get Correct API Class from Mapper - route(env,meth,path,code,"text/plain;version="+version,"*/*"); - } - - @Override - public Filter[] _filters(Object ... additionalTafLurs) throws CadiException, LocatorException { - try { - return new Filter[] { - new AuthzTransFilter(env,aafCon(), - new AAFTrustChecker((Env)env), - additionalTafLurs) - }; - } catch (NumberFormatException e) { - throw new CadiException("Invalid Property information", e); - } - } + + /** + * Setup XML and JSON implementations for each supported Version type + * + * We do this by taking the Code passed in and creating clones of these with the appropriate Facades and properties + * to do Versions and Content switches + * + */ + public void route(HttpMethods meth, String path, API api, HttpCode code) throws Exception { + String version = "1.0"; + // Get Correct API Class from Mapper + route(env,meth,path,code,"text/plain;version="+version,"*/*"); + } + + @Override + public Filter[] _filters(Object ... additionalTafLurs) throws CadiException, LocatorException { + try { + return new Filter[] { + new AuthzTransFilter(env,aafCon(), + new AAFTrustChecker((Env)env), + additionalTafLurs) + }; + } catch (NumberFormatException e) { + throw new CadiException("Invalid Property information", e); + } + } - @SuppressWarnings("unchecked") - @Override - public Registrant[] registrants(final int port) throws CadiException, LocatorException { - return new Registrant[] { - new RemoteRegistrant(aafCon(),app_name,app_version,port) - }; - } + @SuppressWarnings("unchecked") + @Override + public Registrant[] registrants(final int port) throws CadiException, LocatorException { + return new Registrant[] { + new RemoteRegistrant(aafCon(),app_name,app_version,port) + }; + } - public static void main(final String[] args) { - try { - Log4JLogIt logIt = new Log4JLogIt(args, "hello"); - PropAccess propAccess = new PropAccess(logIt,args); + public static void main(final String[] args) { + try { + Log4JLogIt logIt = new Log4JLogIt(args, "hello"); + PropAccess propAccess = new PropAccess(logIt,args); - AAF_Hello service = new AAF_Hello(new AuthzEnv(propAccess)); - JettyServiceStarter jss = new JettyServiceStarter(service); - jss.start(); - } catch (Exception e) { - e.printStackTrace(); - } - } + AAF_Hello service = new AAF_Hello(new AuthzEnv(propAccess)); + JettyServiceStarter jss = new JettyServiceStarter(service); + jss.start(); + } catch (Exception e) { + e.printStackTrace(); + } + } } diff --git a/auth/auth-hello/src/main/java/org/onap/aaf/auth/hello/API_Hello.java b/auth/auth-hello/src/main/java/org/onap/aaf/auth/hello/API_Hello.java index 97727abd..234dfe14 100644 --- a/auth/auth-hello/src/main/java/org/onap/aaf/auth/hello/API_Hello.java +++ b/auth/auth-hello/src/main/java/org/onap/aaf/auth/hello/API_Hello.java @@ -43,146 +43,146 @@ import org.onap.aaf.misc.env.TimeTaken; public class API_Hello { - private static final String APPLICATION_JSON = "application/json"; - protected static final byte[] NOT_JSON = "Data does not look like JSON".getBytes(); + private static final String APPLICATION_JSON = "application/json"; + protected static final byte[] NOT_JSON = "Data does not look like JSON".getBytes(); - // Hide Public Constructor - private API_Hello() {} - - /** - * Normal Init level APIs - * - * @param oauthHello - * @param facade - * @throws Exception - */ - public static void init(final AAF_Hello oauthHello) throws Exception { - //////// - // Simple "GET" API - /////// - - oauthHello.route(HttpMethods.GET,"/hello/:perm*",API.TOKEN,new HttpCode(oauthHello,"Hello OAuth"){ - @Override - public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { - resp.setStatus(200 /* OK */); - ServletOutputStream os = resp.getOutputStream(); - os.print("Hello AAF "); - String perm = pathParam(req, "perm"); - if(perm!=null && perm.length()>0) { - os.print('('); - os.print(req.getUserPrincipal().getName()); - TimeTaken tt = trans.start("Authorize perm", Env.REMOTE); - try { - if(req.isUserInRole(perm)) { - os.print(" has "); - } else { - os.print(" does not have "); - } - } finally { - tt.done(); - } - os.print("Permission: "); - os.print(perm); - os.print(')'); - } - os.println(); - - trans.info().printf("Said 'Hello' to %s, Authentication type: %s",trans.getUserPrincipal().getName(),trans.getUserPrincipal().getClass().getSimpleName()); - } - }); + // Hide Public Constructor + private API_Hello() {} + + /** + * Normal Init level APIs + * + * @param oauthHello + * @param facade + * @throws Exception + */ + public static void init(final AAF_Hello oauthHello) throws Exception { + //////// + // Simple "GET" API + /////// + + oauthHello.route(HttpMethods.GET,"/hello/:perm*",API.TOKEN,new HttpCode(oauthHello,"Hello OAuth"){ + @Override + public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { + resp.setStatus(200 /* OK */); + ServletOutputStream os = resp.getOutputStream(); + os.print("Hello AAF "); + String perm = pathParam(req, "perm"); + if(perm!=null && perm.length()>0) { + os.print('('); + os.print(req.getUserPrincipal().getName()); + TimeTaken tt = trans.start("Authorize perm", Env.REMOTE); + try { + if(req.isUserInRole(perm)) { + os.print(" has "); + } else { + os.print(" does not have "); + } + } finally { + tt.done(); + } + os.print("Permission: "); + os.print(perm); + os.print(')'); + } + os.println(); + + trans.info().printf("Said 'Hello' to %s, Authentication type: %s",trans.getUserPrincipal().getName(),trans.getUserPrincipal().getClass().getSimpleName()); + } + }); //////////////// // REST APIs //////////////// - //////////////// - // CREATE/POST - //////////////// - oauthHello.route(oauthHello.env,HttpMethods.POST,"/resthello/:id",new HttpCode(oauthHello,"REST Hello Create") { - @Override - public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { - BufferedReader br = new BufferedReader(new InputStreamReader(req.getInputStream())); - StringBuilder sb = new StringBuilder(); - while(br.ready()) { - sb.append(br.readLine()); - } - String content = sb.toString(); - trans.info().printf("Content from %s: %s\n", pathParam(req, ":id"),content); - if(content.startsWith("{") && content.endsWith("}")) { - resp.setStatus(201 /* OK */); - } else { - resp.getOutputStream().write(NOT_JSON); - resp.setStatus(406); - } - } - },APPLICATION_JSON); + //////////////// + // CREATE/POST + //////////////// + oauthHello.route(oauthHello.env,HttpMethods.POST,"/resthello/:id",new HttpCode(oauthHello,"REST Hello Create") { + @Override + public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(req.getInputStream())); + StringBuilder sb = new StringBuilder(); + while(br.ready()) { + sb.append(br.readLine()); + } + String content = sb.toString(); + trans.info().printf("Content from %s: %s\n", pathParam(req, ":id"),content); + if(content.startsWith("{") && content.endsWith("}")) { + resp.setStatus(201 /* OK */); + } else { + resp.getOutputStream().write(NOT_JSON); + resp.setStatus(406); + } + } + },APPLICATION_JSON); - //////////////// - // READ/GET - //////////////// - oauthHello.route(oauthHello.env,HttpMethods.GET,"/resthello/:id",new HttpCode(oauthHello,"REST Hello Read") { - @Override - public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { - resp.setStatus(200 /* OK */); - StringBuilder sb = new StringBuilder("{\"resp\": \"Hello REST AAF\",\"principal\": \""); - sb.append(req.getUserPrincipal().getName()); - sb.append('"'); - String perm = pathParam(req, "perm"); - trans.info().printf("Read request from %s: %s\n", pathParam(req, ":id"),perm); - if(perm!=null && perm.length()>0) { - TimeTaken tt = trans.start("Authorize perm", Env.REMOTE); - try { - sb.append(",\"validation\": { \"permission\" : \""); - sb.append(perm); - sb.append("\",\"has\" : \""); - sb.append(req.isUserInRole(perm)); - sb.append("\"}"); - } finally { - tt.done(); - } - } - sb.append("}"); - ServletOutputStream os = resp.getOutputStream(); - os.println(sb.toString()); - trans.info().printf("Said 'RESTful Hello' to %s, Authentication type: %s",trans.getUserPrincipal().getName(),trans.getUserPrincipal().getClass().getSimpleName()); - } - },APPLICATION_JSON); - - //////////////// - // UPDATE/PUT - //////////////// - oauthHello.route(oauthHello.env,HttpMethods.PUT,"/resthello/:id",new HttpCode(oauthHello,"REST Hello Update") { - @Override - public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { - BufferedReader br = new BufferedReader(new InputStreamReader(req.getInputStream())); - StringBuilder sb = new StringBuilder(); - while(br.ready()) { - sb.append(br.readLine()); - } - String content = sb.toString(); - trans.info().printf("Content from %s: %s\n", pathParam(req, ":id"),content); - if(content.startsWith("{") && content.endsWith("}")) { - resp.setStatus(200 /* OK */); - resp.getOutputStream().print(content); - } else { - resp.getOutputStream().write(NOT_JSON); - resp.setStatus(406); - } - } - },APPLICATION_JSON); + //////////////// + // READ/GET + //////////////// + oauthHello.route(oauthHello.env,HttpMethods.GET,"/resthello/:id",new HttpCode(oauthHello,"REST Hello Read") { + @Override + public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { + resp.setStatus(200 /* OK */); + StringBuilder sb = new StringBuilder("{\"resp\": \"Hello REST AAF\",\"principal\": \""); + sb.append(req.getUserPrincipal().getName()); + sb.append('"'); + String perm = pathParam(req, "perm"); + trans.info().printf("Read request from %s: %s\n", pathParam(req, ":id"),perm); + if(perm!=null && perm.length()>0) { + TimeTaken tt = trans.start("Authorize perm", Env.REMOTE); + try { + sb.append(",\"validation\": { \"permission\" : \""); + sb.append(perm); + sb.append("\",\"has\" : \""); + sb.append(req.isUserInRole(perm)); + sb.append("\"}"); + } finally { + tt.done(); + } + } + sb.append("}"); + ServletOutputStream os = resp.getOutputStream(); + os.println(sb.toString()); + trans.info().printf("Said 'RESTful Hello' to %s, Authentication type: %s",trans.getUserPrincipal().getName(),trans.getUserPrincipal().getClass().getSimpleName()); + } + },APPLICATION_JSON); + + //////////////// + // UPDATE/PUT + //////////////// + oauthHello.route(oauthHello.env,HttpMethods.PUT,"/resthello/:id",new HttpCode(oauthHello,"REST Hello Update") { + @Override + public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(req.getInputStream())); + StringBuilder sb = new StringBuilder(); + while(br.ready()) { + sb.append(br.readLine()); + } + String content = sb.toString(); + trans.info().printf("Content from %s: %s\n", pathParam(req, ":id"),content); + if(content.startsWith("{") && content.endsWith("}")) { + resp.setStatus(200 /* OK */); + resp.getOutputStream().print(content); + } else { + resp.getOutputStream().write(NOT_JSON); + resp.setStatus(406); + } + } + },APPLICATION_JSON); - //////////////// - // DELETE - //////////////// - oauthHello.route(oauthHello.env,HttpMethods.DELETE,"/resthello/:id",new HttpCode(oauthHello,"REST Hello Delete") { - @Override - public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { - trans.info().printf("Delete requested on %s\n", pathParam(req, ":id")); - resp.setStatus(200 /* OK */); - } - },APPLICATION_JSON); + //////////////// + // DELETE + //////////////// + oauthHello.route(oauthHello.env,HttpMethods.DELETE,"/resthello/:id",new HttpCode(oauthHello,"REST Hello Delete") { + @Override + public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { + trans.info().printf("Delete requested on %s\n", pathParam(req, ":id")); + resp.setStatus(200 /* OK */); + } + },APPLICATION_JSON); - } + } } diff --git a/auth/auth-hello/src/test/java/org/onap/aaf/auth/hello/test/HelloTester.java b/auth/auth-hello/src/test/java/org/onap/aaf/auth/hello/test/HelloTester.java index 84625281..f41826d9 100644 --- a/auth/auth-hello/src/test/java/org/onap/aaf/auth/hello/test/HelloTester.java +++ b/auth/auth-hello/src/test/java/org/onap/aaf/auth/hello/test/HelloTester.java @@ -40,42 +40,42 @@ import org.onap.aaf.misc.env.APIException; public class HelloTester { - public static void main(String[] args) { - // Do Once and ONLY once - PropAccess access = new PropAccess(args); - try { - Define.set(access); - String uriPrefix = access.getProperty("locatorURI","https://aaftest.test.att.com"); - - SecurityInfoC si = SecurityInfoC.instance(access, HttpURLConnection.class); - AAFLocator loc = new AAFLocator(si,new URI(uriPrefix+"/locate/"+Define.ROOT_NS()+".hello:1.0")); - AAFConHttp aafcon = new AAFConHttp(access,loc,si); - - // - String pathinfo = "/hello"; - final int iterations = Integer.parseInt(access.getProperty("iterations","5")); - System.out.println("Calling " + loc + " with Path " + pathinfo + ' ' + iterations + " time" + (iterations==1?"":"s")); - for(int i=0;i () { - @Override - public Void code(Rcli client) throws CadiException, ConnectException, APIException { - Future fs = client.read("/hello","text/plain"); - if(fs.get(5000)) { - System.out.print(fs.body()); - } else { - System.err.println("Ooops, missed one: " + fs.code() + ": " + fs.body()); - } - return null; - - } - }); - Thread.sleep(500L); - } - } catch (CadiException | LocatorException | URISyntaxException | APIException | InterruptedException e) { - e.printStackTrace(); - } - - - } - + public static void main(String[] args) { + // Do Once and ONLY once + PropAccess access = new PropAccess(args); + try { + Define.set(access); + String uriPrefix = access.getProperty("locatorURI",null); + if(uriPrefix==null) { + System.out.println("You must add \"locatorURI=\" to the command line or VM_Args"); + } else { + SecurityInfoC si = SecurityInfoC.instance(access, HttpURLConnection.class); + AAFLocator loc = new AAFLocator(si,new URI(uriPrefix+"/locate/"+Define.ROOT_NS()+".hello:1.0")); + AAFConHttp aafcon = new AAFConHttp(access,loc,si); + + // + String pathinfo = "/hello"; + final int iterations = Integer.parseInt(access.getProperty("iterations","5")); + System.out.println("Calling " + loc + " with Path " + pathinfo + ' ' + iterations + " time" + (iterations==1?"":"s")); + for(int i=0;i () { + @Override + public Void code(Rcli client) throws CadiException, ConnectException, APIException { + Future fs = client.read("/hello","text/plain"); + if(fs.get(5000)) { + System.out.print(fs.body()); + } else { + System.err.println("Ooops, missed one: " + fs.code() + ": " + fs.body()); + } + return null; + + } + }); + Thread.sleep(500L); + } + } + } catch (CadiException | LocatorException | URISyntaxException | APIException | InterruptedException e) { + e.printStackTrace(); + } + } } -- cgit 1.2.3-korg