diff options
author | Instrumental <jonathan.gathman@att.com> | 2018-09-07 12:21:34 -0500 |
---|---|---|
committer | Instrumental <jonathan.gathman@att.com> | 2018-09-07 12:22:50 -0500 |
commit | 4b5a7d721d994a49057e9bfb403c7bff1b376660 (patch) | |
tree | a36d03227b63a3e60346d6c3ca87b061087dae85 /auth/auth-hello/src | |
parent | 824dc7b5fc0e1ccdf7f460479aff344727f0f01e (diff) |
Mass removal of all Tabs (Style Warnings)
Issue-ID: AAF-473
Change-Id: Iaf0ef8120882937959bb0065f2f6ba74a021940f
Signed-off-by: Instrumental <jonathan.gathman@att.com>
Diffstat (limited to 'auth/auth-hello/src')
3 files changed, 245 insertions, 245 deletions
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<AuthzEnv,AuthzTrans> { - public enum API{TOKEN_REQ, TOKEN,INTROSPECT, ERROR,VOID}; - public Map<String, Dated> 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<String, Dated> 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<AuthzTrans, AAF_Hello> 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<AuthzTrans, AAF_Hello> 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<AuthzEnv>[] registrants(final int port) throws CadiException, LocatorException { - return new Registrant[] { - new RemoteRegistrant<AuthzEnv>(aafCon(),app_name,app_version,port) - }; - } + @SuppressWarnings("unchecked") + @Override + public Registrant<AuthzEnv>[] registrants(final int port) throws CadiException, LocatorException { + return new Registrant[] { + new RemoteRegistrant<AuthzEnv>(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<AuthzEnv,AuthzTrans> jss = new JettyServiceStarter<AuthzEnv,AuthzTrans>(service); - jss.start(); - } catch (Exception e) { - e.printStackTrace(); - } - } + AAF_Hello service = new AAF_Hello(new AuthzEnv(propAccess)); + JettyServiceStarter<AuthzEnv,AuthzTrans> jss = new JettyServiceStarter<AuthzEnv,AuthzTrans>(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<AuthzTrans, AAF_Hello>(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<AuthzTrans, AAF_Hello>(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<AuthzTrans, AAF_Hello>(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<AuthzTrans, AAF_Hello>(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<AuthzTrans, AAF_Hello>(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<AuthzTrans, AAF_Hello>(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<AuthzTrans, AAF_Hello>(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<AuthzTrans, AAF_Hello>(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<AuthzTrans, AAF_Hello>(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<AuthzTrans, AAF_Hello>(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<HttpURLConnection> 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<iterations;++i) { - aafcon.best(new Retryable<Void> () { - @Override - public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException { - Future<String> 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=<uri>\" to the command line or VM_Args"); + } else { + SecurityInfoC<HttpURLConnection> 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<iterations;++i) { + aafcon.best(new Retryable<Void> () { + @Override + public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException { + Future<String> 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(); + } + } } |