aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/music/rest
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/onap/music/rest')
-rwxr-xr-xsrc/main/java/org/onap/music/rest/RestMusicAdminAPI.java127
-rwxr-xr-xsrc/main/java/org/onap/music/rest/RestMusicDataAPI.java193
-rwxr-xr-xsrc/main/java/org/onap/music/rest/RestMusicQAPI.java3
3 files changed, 129 insertions, 194 deletions
diff --git a/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java b/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java
index 6ad6c03b..0bca1f99 100755
--- a/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java
+++ b/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java
@@ -46,7 +46,9 @@ import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;
import org.mindrot.jbcrypt.BCrypt;
+import org.onap.music.authentication.CachingUtil;
import org.onap.music.authentication.MusicAuthentication;
+import org.onap.music.authentication.MusicAuthenticator;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.datastore.jsonobjects.JsonOnboard;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
@@ -54,8 +56,6 @@ import org.onap.music.eelf.logging.format.AppMessages;
import org.onap.music.eelf.logging.format.ErrorSeverity;
import org.onap.music.eelf.logging.format.ErrorTypes;
import org.onap.music.exceptions.MusicServiceException;
-//import org.onap.music.main.CacheAccess;
-import org.onap.music.main.CachingUtil;
import org.onap.music.main.MusicCore;
import org.onap.music.main.MusicUtil;
import org.onap.music.main.ResultType;
@@ -80,6 +80,8 @@ public class RestMusicAdminAPI {
EELFLoggerDelegate.getLogger(RestMusicAdminAPI.class);
// Set to true in env like ONAP. Where access to creating and dropping keyspaces exist.
private static final boolean KEYSPACE_ACTIVE = false;
+
+ private MusicAuthenticator authenticator = new MusicAuthentication();
/*
* API to onboard an application with MUSIC. This is the mandatory first step.
@@ -95,27 +97,22 @@ public class RestMusicAdminAPI {
logger.info(EELFLoggerDelegate.errorLogger, "oboarding app");
ResponseBuilder response =
Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
+ if (!authenticator.authenticateAdmin(authorization)) {
+ logger.error(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check admin username,password and try again", AppMessages.AUTHENTICATIONERROR, ErrorSeverity.CRITICAL,
+ ErrorTypes.AUTHENTICATIONERROR);
+ return response.status(Status.UNAUTHORIZED)
+ .entity(new JsonResponse(ResultType.FAILURE)
+ .setError("Unauthorized: Please check admin username,password and try again").toMap())
+ .build();
+ }
+
Map<String, Object> resultMap = new HashMap<>();
String appName = jsonObj.getAppname();
String userId = jsonObj.getUserId();
String isAAF = jsonObj.getIsAAF();
String password = jsonObj.getPassword();
String keyspace_name = jsonObj.getKeyspace();
- try {
- if (!MusicAuthentication.authenticateAdmin(authorization)) {
- logger.error(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check admin username,password and try again", AppMessages.MISSINGDATA, ErrorSeverity.CRITICAL,
- ErrorTypes.AUTHENTICATIONERROR);
- response.status(Status.UNAUTHORIZED);
- return response
- .entity(new JsonResponse(ResultType.FAILURE)
- .setError("Unauthorized: Please check admin username,password and try again").toMap())
- .build();
- }
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, "Unable to authenticate", e);
- response.status(Status.UNAUTHORIZED);
- return response.entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
- }
+
if (appName == null || userId == null || isAAF == null || password == null) {
logger.error(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check the request parameters. Some of the required values appName(ns), userId, password, isAAF are missing.", AppMessages.MISSINGINFO,
ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
@@ -137,7 +134,7 @@ public class RestMusicAdminAPI {
* " has already been onboarded. Please contact admin.").toMap()).build(); }
*/
//pQuery = new PreparedQueryObject();
- String uuid = CachingUtil.generateUUID();
+ String uuid = MusicUtil.generateUUID();
pQuery.appendQueryString(
"INSERT INTO admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
+ "password, username, is_aaf) VALUES (?,?,?,?,?,?,?)");
@@ -171,24 +168,20 @@ public class RestMusicAdminAPI {
public Response getOnboardedInfoSearch(JsonOnboard jsonObj,
@ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization) throws Exception {
ResponseBuilder response = Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
+
+ if (!authenticator.authenticateAdmin(authorization)) {
+ logger.error(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check admin username,password and try again", AppMessages.AUTHENTICATIONERROR, ErrorSeverity.CRITICAL,
+ ErrorTypes.AUTHENTICATIONERROR);
+ return response.status(Status.UNAUTHORIZED)
+ .entity(new JsonResponse(ResultType.FAILURE)
+ .setError("Unauthorized: Please check admin username,password and try again").toMap())
+ .build();
+ }
+
Map<String, Object> resultMap = new HashMap<>();
String appName = jsonObj.getAppname();
String uuid = jsonObj.getAid();
String isAAF = jsonObj.getIsAAF();
-
- try {
- if (!MusicAuthentication.authenticateAdmin(authorization)) {
- logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGDATA, ErrorSeverity.CRITICAL,
- ErrorTypes.AUTHENTICATIONERROR);
- response.status(Status.UNAUTHORIZED);
- return response
- .entity(new JsonResponse(ResultType.FAILURE)
- .setError("Unauthorized: Please check admin username,password and try again").toMap())
- .build();
- }
- } catch (Exception e) {
- return response.entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
- }
if (appName == null && uuid == null && isAAF == null) {
logger.error(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check the request parameters. Enter atleast one of the following parameters: appName(ns), aid, isAAF.", AppMessages.MISSINGINFO,
ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
@@ -248,24 +241,21 @@ public class RestMusicAdminAPI {
public Response deleteOnboardApp(JsonOnboard jsonObj,
@ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization) throws Exception {
ResponseBuilder response = Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
+
+ if (!authenticator.authenticateAdmin(authorization)) {
+ logger.error(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check admin username,password and try again", AppMessages.AUTHENTICATIONERROR, ErrorSeverity.CRITICAL,
+ ErrorTypes.AUTHENTICATIONERROR);
+ return response.status(Status.UNAUTHORIZED)
+ .entity(new JsonResponse(ResultType.FAILURE)
+ .setError("Unauthorized: Please check admin username,password and try again").toMap())
+ .build();
+ }
+
Map<String, Object> resultMap = new HashMap<>();
String appName = jsonObj.getAppname();
String aid = jsonObj.getAid();
PreparedQueryObject pQuery = new PreparedQueryObject();
- String consistency = MusicUtil.EVENTUAL;;
- try {
- if (!MusicAuthentication.authenticateAdmin(authorization)) {
- logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGDATA, ErrorSeverity.CRITICAL,
- ErrorTypes.AUTHENTICATIONERROR);
- response.status(Status.UNAUTHORIZED);
- return response
- .entity(new JsonResponse(ResultType.FAILURE)
- .setError("Unauthorized: Please check admin username,password and try again").toMap())
- .build();
- }
- } catch (Exception e) {
- return response.entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
- }
+ String consistency = MusicUtil.EVENTUAL;
if (appName == null && aid == null) {
logger.error(EELFLoggerDelegate.errorLogger, "Please make sure either appName(ns) or Aid is present", AppMessages.MISSINGINFO,
ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
@@ -358,6 +348,15 @@ public class RestMusicAdminAPI {
public Response updateOnboardApp(JsonOnboard jsonObj,
@ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization) throws Exception {
ResponseBuilder response = Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
+ if (!authenticator.authenticateAdmin(authorization)) {
+ logger.error(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check admin username,password and try again", AppMessages.AUTHENTICATIONERROR, ErrorSeverity.CRITICAL,
+ ErrorTypes.AUTHENTICATIONERROR);
+ return response.status(Status.UNAUTHORIZED)
+ .entity(new JsonResponse(ResultType.FAILURE)
+ .setError("Unauthorized: Please check admin username,password and try again").toMap())
+ .build();
+ }
+
Map<String, Object> resultMap = new HashMap<>();
String aid = jsonObj.getAid();
String appName = jsonObj.getAppname();
@@ -366,19 +365,7 @@ public class RestMusicAdminAPI {
String password = jsonObj.getPassword();
String consistency = "eventual";
PreparedQueryObject pQuery;
- try {
- if (!MusicAuthentication.authenticateAdmin(authorization)) {
- logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGDATA, ErrorSeverity.CRITICAL,
- ErrorTypes.AUTHENTICATIONERROR);
- response.status(Status.UNAUTHORIZED);
- return response
- .entity(new JsonResponse(ResultType.FAILURE)
- .setError("Unauthorized: Please check admin username,password and try again").toMap())
- .build();
- }
- } catch (Exception e) {
- return response.entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
- }
+
if (aid == null) {
resultMap.put("Exception", "Please make sure Aid is present");
logger.error(EELFLoggerDelegate.errorLogger, "Please make sure Aid is present", AppMessages.MISSINGDATA,
@@ -458,6 +445,12 @@ public class RestMusicAdminAPI {
List<Application> appList = new ArrayList<>();
ResponseBuilder response =
Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
+ if (!authenticator.authenticateAdmin(authorization)) {
+ logger.error(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check admin username,password and try again", AppMessages.AUTHENTICATIONERROR, ErrorSeverity.CRITICAL,
+ ErrorTypes.AUTHENTICATIONERROR);
+ return appList;
+ }
+
PreparedQueryObject queryObject = new PreparedQueryObject();
queryObject.appendQueryString("SELECT * FROM " + "admin" + "." + "keyspace_master" + ";");
ResultSet results = MusicCore.get(queryObject);
@@ -484,6 +477,11 @@ public class RestMusicAdminAPI {
@ApiParam(value = "uuid", required = true) @HeaderParam("uuid") String uuid) throws Exception {
ResponseBuilder response =
Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
+ if (!authenticator.authenticateAdmin(authorization)) {
+ logger.error(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check admin username,password and try again", AppMessages.AUTHENTICATIONERROR, ErrorSeverity.CRITICAL,
+ ErrorTypes.AUTHENTICATIONERROR);
+ return false;
+ }
PreparedQueryObject queryObject = new PreparedQueryObject();
queryObject.appendQueryString("delete from admin.keyspace_master where uuid=?");
queryObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),uuid));
@@ -495,15 +493,4 @@ public class RestMusicAdminAPI {
}
return true;
}
-
-
- @GET
- @Path("/login")
- @Produces(MediaType.APPLICATION_JSON)
- @Consumes(MediaType.APPLICATION_JSON)
- public boolean login(@ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization) throws Exception {
-
- boolean result = MusicAuthentication.authenticateAdmin(authorization);
- return result;
- }
}
diff --git a/src/main/java/org/onap/music/rest/RestMusicDataAPI.java b/src/main/java/org/onap/music/rest/RestMusicDataAPI.java
index 80654935..ff44abf7 100755
--- a/src/main/java/org/onap/music/rest/RestMusicDataAPI.java
+++ b/src/main/java/org/onap/music/rest/RestMusicDataAPI.java
@@ -48,7 +48,10 @@ import javax.ws.rs.core.UriInfo;
import org.apache.commons.lang3.StringUtils;
import org.mindrot.jbcrypt.BCrypt;
+import org.onap.music.authentication.CachingUtil;
import org.onap.music.authentication.MusicAuthentication;
+import org.onap.music.authentication.MusicAuthenticator;
+import org.onap.music.authentication.MusicAuthenticator.Operation;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.datastore.jsonobjects.JsonDelete;
import org.onap.music.datastore.jsonobjects.JsonInsert;
@@ -62,7 +65,6 @@ import org.onap.music.eelf.logging.format.AppMessages;
import org.onap.music.eelf.logging.format.ErrorSeverity;
import org.onap.music.eelf.logging.format.ErrorTypes;
import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.main.CachingUtil;
import org.onap.music.main.MusicCore;
import org.onap.music.datastore.Condition;
import org.onap.music.datastore.MusicDataStoreHandle;
@@ -115,6 +117,7 @@ public class RestMusicDataAPI {
private static final String XPATCHVERSION = "X-patchVersion";
private static final String NS = "ns";
private static final String VERSION = "v2";
+ private MusicAuthenticator authenticator = new MusicAuthentication();
// Set to true in env like ONAP. Where access to creating and dropping keyspaces exist.
private static final boolean KEYSPACE_ACTIVE = false;
@@ -147,7 +150,6 @@ public class RestMusicDataAPI {
@ApiOperation(value = "Create Keyspace", response = String.class,hidden = true)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- //public Map<String, Object> createKeySpace(
public Response createKeySpace(
@ApiParam(value = "Major Version",required = true) @PathParam("version") String version,
@ApiParam(value = "Minor Version",required = false) @HeaderParam(XMINORVERSION) String minorVersion,
@@ -409,17 +411,13 @@ public class RestMusicDataAPI {
.toMap()).build();
}
EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspace+" ) ");
- Map<String,String> userCredentials = MusicUtil.extractBasicAuthentication(authorization);
- String userId = userCredentials.get(MusicUtil.USERID);
- String password = userCredentials.get(MusicUtil.PASSWORD);
- Map<String, Object> authMap = MusicAuthentication.autheticateUser(ns, userId, password, keyspace,
- aid, "createTable");
- if (authMap.containsKey("aid"))
- authMap.remove("aid");
- if (!authMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,authMap.get("Exception").toString(), AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
- return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
- }
+ if (!authenticator.authenticateUser(ns, authorization, keyspace, aid, Operation.CREATE_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 consistency = MusicUtil.EVENTUAL;
// for now this needs only eventual consistency
@@ -640,17 +638,13 @@ public class RestMusicDataAPI {
.toMap()).build();
}
EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspace+" ) ");
- Map<String,String> userCredentials = MusicUtil.extractBasicAuthentication(authorization);
- String userId = userCredentials.get(MusicUtil.USERID);
- String password = userCredentials.get(MusicUtil.PASSWORD);
- Map<String, Object> authMap = MusicAuthentication.autheticateUser(ns, userId, password, keyspace,aid, "createIndex");
- if (authMap.containsKey("aid"))
- authMap.remove("aid");
- if (!authMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,authMap.get("Exception").toString(), AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
- response.status(Status.UNAUTHORIZED);
- return response.entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
- }
+ if (!authenticator.authenticateUser(ns, authorization, keyspace, aid, Operation.CREATE_INDEX)) {
+ 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();
+ }
+
MultivaluedMap<String, String> rowParams = info.getQueryParameters();
String indexName = "";
if (rowParams.getFirst("index_name") != null)
@@ -710,23 +704,11 @@ public class RestMusicDataAPI {
.toMap()).build();
}
EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspace+" ) ");
- Map<String,String> userCredentials = MusicUtil.extractBasicAuthentication(authorization);
- String userId = userCredentials.get(MusicUtil.USERID);
- String password = userCredentials.get(MusicUtil.PASSWORD);
- Map<String, Object> authMap = null;
-
- try {
- authMap = MusicAuthentication.autheticateUser(ns, userId, password, keyspace,
- aid, "insertIntoTable");
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), 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,authMap.get("Exception").toString(), AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
- return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
+ 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();
}
Map<String, Object> valuesMap = insObj.getValues();
@@ -738,7 +720,7 @@ public class RestMusicDataAPI {
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Table name doesn't exists. Please check the table name.").toMap()).build();
}
} catch (MusicServiceException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ logger.error(EELFLoggerDelegate.errorLogger, e, AppMessages.UNKNOWNERROR ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
}
String primaryKeyName = tableInfo.getPrimaryKey().get(0).getName();
@@ -769,7 +751,7 @@ public class RestMusicDataAPI {
try {
formattedValue = MusicUtil.convertToActualDataType(colType, valueObj);
} catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
+ logger.error(EELFLoggerDelegate.errorLogger,e);
}
valueString.append("?");
@@ -942,23 +924,13 @@ public class RestMusicDataAPI {
.toMap()).build();
}
EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspace+" ) ");
- Map<String,String> userCredentials = MusicUtil.extractBasicAuthentication(authorization);
- String userId = userCredentials.get(MusicUtil.USERID);
- String password = userCredentials.get(MusicUtil.PASSWORD);
- Map<String, Object> authMap;
- try {
- authMap = MusicAuthentication.autheticateUser(ns, userId, password, keyspace,
- aid, "updateTable");
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, 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,authMap.get("Exception").toString(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
+ if (!authenticator.authenticateUser(ns, authorization, keyspace, aid, Operation.UPDATE_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();
}
+
long startTime = System.currentTimeMillis();
String operationId = UUID.randomUUID().toString();// just for infoging
// purposes.
@@ -975,7 +947,7 @@ public class RestMusicDataAPI {
try {
tableInfo = MusicDataStoreHandle.returnColumnMetadata(keyspace, tablename);
} catch (MusicServiceException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ logger.error(EELFLoggerDelegate.errorLogger,e, AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
}
if (tableInfo == null) {
@@ -995,14 +967,14 @@ public class RestMusicDataAPI {
try {
colType = tableInfo.getColumn(entry.getKey()).getType();
} catch(NullPointerException ex) {
- logger.error(EELFLoggerDelegate.errorLogger, "Invalid column name : "+entry.getKey());
+ logger.error(EELFLoggerDelegate.errorLogger, ex, "Invalid column name : "+entry.getKey());
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Invalid column name : "+entry.getKey()).toMap()).build();
}
Object valueString = null;
try {
valueString = MusicUtil.convertToActualDataType(colType, valueObj);
} catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
+ logger.error(EELFLoggerDelegate.errorLogger,e);
}
fieldValueString.append(entry.getKey() + "= ?");
queryObject.addValue(valueString);
@@ -1042,7 +1014,7 @@ public class RestMusicDataAPI {
.setError("Mandatory WHERE clause is missing. Please check the input request.").toMap()).build();
}
} catch (MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ logger.error(EELFLoggerDelegate.errorLogger,ex, AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
}
@@ -1090,7 +1062,7 @@ public class RestMusicDataAPI {
operationResult = MusicCore.atomicPutWithDeleteLock(keyspace, tablename,
rowId.primarKeyValue, queryObject, conditionInfo);
} catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ logger.error(EELFLoggerDelegate.errorLogger,e, AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
}
} else if (consistency.equalsIgnoreCase(MusicUtil.ATOMIC)) {
@@ -1098,7 +1070,7 @@ public class RestMusicDataAPI {
operationResult = MusicCore.atomicPut(keyspace, tablename, rowId.primarKeyValue,
queryObject, conditionInfo);
} catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ logger.error(EELFLoggerDelegate.errorLogger,e, AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
}
}else if(consistency.equalsIgnoreCase(MusicUtil.EVENTUAL_NB)) {
@@ -1175,23 +1147,13 @@ public class RestMusicDataAPI {
.toMap()).build();
}
EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspace+" ) ");
- Map<String,String> userCredentials = MusicUtil.extractBasicAuthentication(authorization);
- String userId = userCredentials.get(MusicUtil.USERID);
- String password = userCredentials.get(MusicUtil.PASSWORD);
- Map<String, Object> authMap = null;
- try {
- authMap = MusicAuthentication.autheticateUser(ns, userId, password, keyspace,
- aid, "deleteFromTable");
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, 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,authMap.get("Exception").toString(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
+ if (!authenticator.authenticateUser(ns, authorization, keyspace, aid, Operation.DELETE_FROM_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();
}
+
if(delObj == null) {
logger.error(EELFLoggerDelegate.errorLogger,"Required HTTP Request body is missing.", AppMessages.MISSINGDATA ,ErrorSeverity.WARN, ErrorTypes.DATAERROR);
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Required HTTP Request body is missing.").toMap()).build();
@@ -1215,7 +1177,7 @@ public class RestMusicDataAPI {
try {
rowId = getRowIdentifier(keyspace, tablename, info.getQueryParameters(), queryObject);
} catch (MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ logger.error(EELFLoggerDelegate.errorLogger,ex, AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
}
String rowSpec = rowId.rowIdString.toString();
@@ -1285,7 +1247,7 @@ public class RestMusicDataAPI {
operationResult = MusicCore.eventualPut_nb(queryObject, keyspace, tablename, rowId.primarKeyValue);
}
} catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ logger.error(EELFLoggerDelegate.errorLogger,e, AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE)
.setError("Unable to perform Delete operation. Exception from music").toMap()).build();
}
@@ -1338,17 +1300,13 @@ public class RestMusicDataAPI {
.toMap()).build();
}
EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspace+" ) ");
- Map<String,String> userCredentials = MusicUtil.extractBasicAuthentication(authorization);
- String userId = userCredentials.get(MusicUtil.USERID);
- String password = userCredentials.get(MusicUtil.PASSWORD);
- Map<String, Object> authMap =
- MusicAuthentication.autheticateUser(ns, userId, password, keyspace, aid, "dropTable");
- if (authMap.containsKey("aid"))
- authMap.remove("aid");
- if (!authMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,authMap.get("Exception").toString(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
+ if (!authenticator.authenticateUser(ns, authorization, keyspace, aid, Operation.DROP_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 consistency = "eventual";// for now this needs only eventual
// consistency
PreparedQueryObject query = new PreparedQueryObject();
@@ -1356,7 +1314,7 @@ public class RestMusicDataAPI {
try {
return response.status(Status.OK).entity(new JsonResponse(MusicCore.nonKeyRelatedPut(query, consistency)).toMap()).build();
} catch (MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ logger.error(EELFLoggerDelegate.errorLogger,ex, AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
}
} finally {
@@ -1402,16 +1360,13 @@ public class RestMusicDataAPI {
.toMap()).build();
}
EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspace+" ) ");
- Map<String,String> userCredentials = MusicUtil.extractBasicAuthentication(authorization);
- String userId = userCredentials.get(MusicUtil.USERID);
- String password = userCredentials.get(MusicUtil.PASSWORD);
- Map<String, Object> authMap = MusicAuthentication.autheticateUser(ns, userId, password, keyspace,aid, "selectCritical");
- if (authMap.containsKey("aid"))
- authMap.remove("aid");
- if (!authMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,authMap.get("Exception").toString(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
+ if (!authenticator.authenticateUser(ns, authorization, keyspace, aid, Operation.SELECT_CRITICAL)) {
+ 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 lockId = selObj.getConsistencyInfo().get("lockId");
PreparedQueryObject queryObject = new PreparedQueryObject();
@@ -1420,7 +1375,7 @@ public class RestMusicDataAPI {
try {
rowId = getRowIdentifier(keyspace, tablename, info.getQueryParameters(), queryObject);
} catch (MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ logger.error(EELFLoggerDelegate.errorLogger,ex, AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
}
queryObject.appendQueryString(
@@ -1492,17 +1447,13 @@ public class RestMusicDataAPI {
.toMap()).build();
}
EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspace+" ) ");
- Map<String,String> userCredentials = MusicUtil.extractBasicAuthentication(authorization);
- String userId = userCredentials.get(MusicUtil.USERID);
- String password = userCredentials.get(MusicUtil.PASSWORD);
- Map<String, Object> authMap =
- MusicAuthentication.autheticateUser(ns, userId, password, keyspace, aid, "select");
- if (authMap.containsKey("aid"))
- authMap.remove("aid");
- if (!authMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,authMap.get("Exception").toString(), AppMessages.AUTHENTICATIONERROR ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
+ if (!authenticator.authenticateUser(ns, authorization, keyspace, aid, Operation.SELECT)) {
+ 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();
}
+
PreparedQueryObject queryObject = new PreparedQueryObject();
if (info.getQueryParameters().isEmpty())// select all
@@ -1510,10 +1461,9 @@ public class RestMusicDataAPI {
else {
int limit = -1; // do not limit the number of results
try {
- queryObject = selectSpecificQuery(VERSION, minorVersion, patchVersion, aid, ns,
- userId, password, keyspace, tablename, info, limit);
+ queryObject = selectSpecificQuery(keyspace, tablename, info, limit);
} catch (MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ logger.error(EELFLoggerDelegate.errorLogger, ex, AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
}
}
@@ -1525,7 +1475,7 @@ public class RestMusicDataAPI {
}
return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setDataResult(MusicDataStoreHandle.marshallResults(results)).setError("No data found").toMap()).build();
} catch (MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.ERROR, ErrorTypes.MUSICSERVICEERROR);
+ logger.error(EELFLoggerDelegate.errorLogger, ex, AppMessages.UNKNOWNERROR ,ErrorSeverity.ERROR, ErrorTypes.MUSICSERVICEERROR);
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
}
} finally {
@@ -1542,9 +1492,8 @@ public class RestMusicDataAPI {
* @return
* @throws MusicServiceException
*/
- public PreparedQueryObject selectSpecificQuery(String version, String minorVersion,
- String patchVersion, String aid, String ns, String userId, String password,
- String keyspace, String tablename, UriInfo info, int limit)
+ public PreparedQueryObject selectSpecificQuery(String keyspace,
+ String tablename, UriInfo info, int limit)
throws MusicServiceException {
PreparedQueryObject queryObject = new PreparedQueryObject();
@@ -1597,7 +1546,7 @@ public class RestMusicDataAPI {
colType = tableInfo.getColumn(entry.getKey()).getType();
formattedValue = MusicUtil.convertToActualDataType(colType, indValue);
} catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
+ logger.error(EELFLoggerDelegate.errorLogger,e);
}
if(tableInfo.getPrimaryKey().get(0).getName().equals(entry.getKey()))
primaryKey.append(indValue);
diff --git a/src/main/java/org/onap/music/rest/RestMusicQAPI.java b/src/main/java/org/onap/music/rest/RestMusicQAPI.java
index 4164f27f..800dad71 100755
--- a/src/main/java/org/onap/music/rest/RestMusicQAPI.java
+++ b/src/main/java/org/onap/music/rest/RestMusicQAPI.java
@@ -377,8 +377,7 @@ public class RestMusicQAPI {
else {
try {
- queryObject = new RestMusicDataAPI().selectSpecificQuery(version, minorVersion,
- patchVersion, aid, ns, userId, password, keyspace, tablename, info, limit);
+ queryObject = new RestMusicDataAPI().selectSpecificQuery(keyspace, tablename, info, limit);
} catch (MusicServiceException ex) {
logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.UNKNOWNERROR,
ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);