X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fmusic%2Fconductor%2Fconditionals%2FRestMusicConditionalAPI.java;h=20fd315045d38f81fc40976360fbabbbd039530e;hb=4d6e2a982cc0ee48aca9d8531424d795e44842c9;hp=6ea05c7b037abf0cf16ac548612fcb0ffbb43de2;hpb=24accb9cb8000591cc22a5d98d2c079b8084b123;p=music.git diff --git a/src/main/java/org/onap/music/conductor/conditionals/RestMusicConditionalAPI.java b/src/main/java/org/onap/music/conductor/conditionals/RestMusicConditionalAPI.java index 6ea05c7b..20fd3150 100644 --- a/src/main/java/org/onap/music/conductor/conditionals/RestMusicConditionalAPI.java +++ b/src/main/java/org/onap/music/conductor/conditionals/RestMusicConditionalAPI.java @@ -52,7 +52,9 @@ import org.onap.music.main.ResultType; import org.onap.music.main.ReturnType; import org.onap.music.response.jsonobjects.JsonResponse; import org.onap.music.rest.RestMusicAdminAPI; -import org.onap.music.authentication.MusicAuthentication; +import org.onap.music.authentication.MusicAAFAuthentication; +import org.onap.music.authentication.MusicAuthenticator; +import org.onap.music.authentication.MusicAuthenticator.Operation; import org.onap.music.conductor.*; import com.datastax.driver.core.DataType; @@ -69,6 +71,8 @@ public class RestMusicConditionalAPI { private static final String XPATCHVERSION = "X-patchVersion"; private static final String NS = "ns"; private static final String VERSION = "v2"; + + private MusicAuthenticator authenticator = new MusicAAFAuthentication(); @POST @Path("/insert/keyspaces/{keyspace}/tables/{tablename}") @@ -85,6 +89,14 @@ public class RestMusicConditionalAPI { @ApiParam(value = "Table Name", required = true) @PathParam("tablename") String tablename, JsonConditional jsonObj) throws Exception { ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion); + + if (!authenticator.authenticateUser(ns, authorization, keyspace, aid, Operation.INSERT_INTO_TABLE)) { + return response.status(Status.UNAUTHORIZED) + .entity(new JsonResponse(ResultType.FAILURE) + .setError("Unauthorized: Please check username, password and make sure your app is onboarded") + .toMap()).build(); + } + String primaryKey = jsonObj.getPrimaryKey(); String primaryKeyValue = jsonObj.getPrimaryKeyValue(); String casscadeColumnName = jsonObj.getCasscadeColumnName(); @@ -100,28 +112,6 @@ public class RestMusicConditionalAPI { .setError(String.valueOf("One or more input values missing")).toMap()).build(); } - Map userCredentials = MusicUtil.extractBasicAuthentication(authorization); - String userId = userCredentials.get(MusicUtil.USERID); - String password = userCredentials.get(MusicUtil.PASSWORD); - - Map authMap = null; - try { - authMap = MusicAuthentication.autheticateUser(ns, userId, password, keyspace, aid, "insertIntoTable"); - } catch (Exception e) { - logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGINFO, ErrorSeverity.CRITICAL, - ErrorTypes.AUTHENTICATIONERROR); - return response.status(Status.UNAUTHORIZED) - .entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build(); - } - if (authMap.containsKey("aid")) - authMap.remove("aid"); - if (!authMap.isEmpty()) { - logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGINFO, ErrorSeverity.CRITICAL, - ErrorTypes.AUTHENTICATIONERROR); - return response.status(Status.UNAUTHORIZED).entity( - new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()) - .build(); - } Map valuesMap = new LinkedHashMap<>(); for (Map.Entry entry : tableValues.entrySet()) { @@ -156,7 +146,14 @@ public class RestMusicConditionalAPI { @ApiParam(value = "Major Version", required = true) @PathParam("tablename") String tablename, JsonConditional upObj) throws Exception { ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion); - + + if (!authenticator.authenticateUser(ns, authorization, keyspace, aid, Operation.INSERT_INTO_TABLE)) { + return response.status(Status.UNAUTHORIZED) + .entity(new JsonResponse(ResultType.FAILURE) + .setError("Unauthorized: Please check username, password and make sure your app is onboarded") + .toMap()).build(); + } + String primaryKey = upObj.getPrimaryKey(); String primaryKeyValue = upObj.getPrimaryKeyValue(); String casscadeColumnName = upObj.getCasscadeColumnName(); @@ -171,28 +168,6 @@ public class RestMusicConditionalAPI { .setError(String.valueOf("One or more input values missing")).toMap()).build(); } - Map userCredentials = MusicUtil.extractBasicAuthentication(authorization); - String userId = userCredentials.get(MusicUtil.USERID); - String password = userCredentials.get(MusicUtil.PASSWORD); - - Map authMap = null; - try { - authMap = MusicAuthentication.autheticateUser(ns, userId, password, keyspace, aid, "updateTable"); - } catch (Exception e) { - logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGINFO, ErrorSeverity.CRITICAL, - ErrorTypes.AUTHENTICATIONERROR); - return response.status(Status.UNAUTHORIZED) - .entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build(); - } - if (authMap.containsKey("aid")) - authMap.remove("aid"); - if (!authMap.isEmpty()) { - logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGINFO, ErrorSeverity.CRITICAL, - ErrorTypes.AUTHENTICATIONERROR); - return response.status(Status.UNAUTHORIZED).entity( - new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()) - .build(); - } String planId = casscadeColumnData.get("key").toString(); Map casscadeColumnValueMap = (Map) casscadeColumnData.get("value");