Merge "Sonar fixes related to exceptions"
[aaf/authz.git] / auth / auth-locate / src / main / java / org / onap / aaf / auth / locate / api / API_AAFAccess.java
index 9de92d1..802c1b5 100644 (file)
@@ -21,6 +21,8 @@
 
 package org.onap.aaf.auth.locate.api;
 
+import static org.onap.aaf.auth.layer.Result.OK;
+
 import java.io.IOException;
 import java.net.ConnectException;
 import java.net.URI;
@@ -133,19 +135,27 @@ public class API_AAFAccess {
                                ,"text/plain","*/*","*");
 
                /**
-                * Query User Has Perm
+                * Query User Has Perm is DEPRECATED
+                * 
+                * Need to move towards NS declaration... is this even being used?
+                * @deprecated
                 */
                gwAPI.route(HttpMethods.GET,"/ask/:user/has/:type/:instance/:action",API.VOID,new LocateCode(facade,USER_HAS_PERM, true) {
                        @Override
                        public void handle(final AuthzTrans trans, final HttpServletRequest req, HttpServletResponse resp) throws Exception {
                                try {
+                                       String type = pathParam(req,":type");
+                                       int idx = type.lastIndexOf('.');
+                                       String ns = type.substring(0,idx);
+                                       type = type.substring(idx+1);
                                        resp.getOutputStream().print(
                                                        gwAPI.aafLurPerm.fish(new Principal() {
                                                                public String getName() {
                                                                        return pathParam(req,":user");
                                                                };
                                                        }, new AAFPermission(
-                                                               pathParam(req,":type"),
+                                                               ns,
+                                                               type,
                                                                pathParam(req,":instance"),
                                                                pathParam(req,":action"))));
                                        resp.setStatus(HttpStatus.OK_200);
@@ -222,6 +232,28 @@ public class API_AAFAccess {
                                }
                        }
                });
+               
+               /**
+                * Configuration 
+                */
+               gwAPI.route(HttpMethods.GET,"/configure/:id/:type",API.CONFIG,new LocateCode(facade,"Deliver Configuration Properties to AAF", true) {
+                       @Override
+                       public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
+                               try {
+                                       Result<Void> r = facade.getConfig(trans, req, resp, pathParam(req, ":id"),pathParam(req,":type"));
+                                       switch(r.status) {
+                                               case OK:
+                                                       resp.setStatus(HttpStatus.OK_200);
+                                                       break;
+                                               default:
+                                                       context.error(trans,resp,r);
+                                       }
+
+                               } catch (Exception e) {
+                                       context.error(trans, resp, Result.ERR_General, e.getMessage());
+                               }
+                       }
+               });
        }
 
        private static void redirect(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp, LocateFacade context, Locator<URI> loc, String path) throws IOException {