Log stack traces with logger
[music.git] / src / main / java / org / onap / music / rest / RestMusicDataAPI.java
index 507bcd4..8500298 100755 (executable)
@@ -4,6 +4,8 @@
  * ===================================================================
  *  Copyright (c) 2017 AT&T Intellectual Property
  * ===================================================================
+ *  Modifications Copyright (c) 2019 Samsung
+ * ===================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
  *  You may obtain a copy of the License at
 package org.onap.music.rest;
 
 import java.nio.ByteBuffer;
-import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 
-import javax.servlet.http.HttpServletResponse;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
@@ -39,7 +39,6 @@ import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.Context;
-import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
@@ -49,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.MusicAuthentication;
+import org.onap.music.authentication.CachingUtil;
+import org.onap.music.authentication.MusicAAFAuthentication;
+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;
@@ -63,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;
@@ -71,7 +72,6 @@ import org.onap.music.main.MusicUtil;
 import org.onap.music.main.ResultType;
 import org.onap.music.main.ReturnType;
 import org.onap.music.response.jsonobjects.JsonResponse;
-import org.onap.music.service.impl.MusicZKCore;
 
 import com.datastax.driver.core.DataType;
 import com.datastax.driver.core.ResultSet;
@@ -117,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 MusicAAFAuthentication();
     // Set to true in env like ONAP. Where access to creating and dropping keyspaces exist.    
     private static final boolean KEYSPACE_ACTIVE = false;
 
@@ -149,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,
@@ -174,34 +174,21 @@ public class RestMusicDataAPI {
                 response.status(Status.UNAUTHORIZED);
                 return response.entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
             }
-            if(kspObject == null || kspObject.getReplicationInfo() == null) {
-                response.status(Status.BAD_REQUEST);
-                return response.entity(new JsonResponse(ResultType.FAILURE).setError(ResultType.BODYMISSING.getResult()).toMap()).build();
-            }
     
-    
-            try {
-                authMap = MusicAuthentication.autheticateUser(ns, userId, password, keyspaceName, aid,
-                                "createKeySpace");
-            } catch (Exception e) {
-                logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.MISSINGDATA  ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
-                response.status(Status.BAD_REQUEST);
-                return response.entity(new JsonResponse(ResultType.FAILURE).setError("Unable to authenticate.").toMap()).build();
-            }
-            String newAid = null;
-            if (!authMap.isEmpty()) {
-                if (authMap.containsKey("aid")) {
-                    newAid = (String) authMap.get("aid");
-                } else {
-                    logger.error(EELFLoggerDelegate.errorLogger,String.valueOf(authMap.get("Exception")), AppMessages.MISSINGDATA  ,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, keyspaceName, aid, Operation.CREATE_KEYSPACE)) {
+                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
     
+            if(kspObject == null || kspObject.getReplicationInfo() == null) {
+                response.status(Status.BAD_REQUEST);
+                return response.entity(new JsonResponse(ResultType.FAILURE).setError(ResultType.BODYMISSING.getResult()).toMap()).build();
+            }
             PreparedQueryObject queryObject = new PreparedQueryObject();
             if(consistency.equalsIgnoreCase(MusicUtil.EVENTUAL) && kspObject.getConsistencyInfo().get("consistency") != null) {
                 if(MusicUtil.isValidConsistency(kspObject.getConsistencyInfo().get("consistency")))
@@ -215,7 +202,8 @@ public class RestMusicDataAPI {
             try {
                 repString = "{" + MusicUtil.jsonMaptoSqlString(replicationInfo, ",") + "}";
             } catch (Exception e) {
-                logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.MISSINGDATA  ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
+                logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.MISSINGDATA  ,ErrorSeverity
+                    .CRITICAL, ErrorTypes.DATAERROR, e);
     
             }
             queryObject.appendQueryString(
@@ -235,7 +223,8 @@ public class RestMusicDataAPI {
                 result = MusicCore.nonKeyRelatedPut(queryObject, consistency);
                 logger.info(EELFLoggerDelegate.applicationLogger, "result = " + result);
             } catch ( MusicServiceException ex) {
-                logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR  ,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
+                logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR  ,ErrorSeverity
+                    .WARN, ErrorTypes.MUSICSERVICEERROR, ex);
                 return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("err:" + ex.getMessage()).toMap()).build();
             }
     
@@ -250,7 +239,8 @@ public class RestMusicDataAPI {
                 queryObject.appendQueryString(";");
                 MusicCore.nonKeyRelatedPut(queryObject, consistency);
             } catch (Exception e) {
-                logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
+                logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR,ErrorSeverity
+                    .WARN, ErrorTypes.MUSICSERVICEERROR, e);
             }
     
             try {
@@ -260,7 +250,7 @@ public class RestMusicDataAPI {
                 queryObject.appendQueryString(
                             "INSERT into admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
                                             + "password, username, is_aaf) values (?,?,?,?,?,?,?)");
-                queryObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), newAid));
+                queryObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), aid));
                 queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), keyspaceName));
                 queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), ns));
                 queryObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
@@ -271,7 +261,8 @@ public class RestMusicDataAPI {
                 CachingUtil.updateMusicValidateCache(ns, userId, hashedpwd);
                 MusicCore.eventualPut(queryObject);
             } catch (Exception e) {
-                logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
+                logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR,ErrorSeverity
+                    .WARN, ErrorTypes.MUSICSERVICEERROR, e);
                 return response.status(Response.Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
             }
     
@@ -312,17 +303,12 @@ public class RestMusicDataAPI {
         EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspaceName+" ) ");
         logger.info(EELFLoggerDelegate.applicationLogger,"In Drop Keyspace " + keyspaceName);
         if ( KEYSPACE_ACTIVE ) {
-            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,keyspaceName, aid, "dropKeySpace");
-            if (authMap.containsKey("aid"))
-                authMap.remove("aid");
-            if (!authMap.isEmpty()) {
-                logger.error(EELFLoggerDelegate.errorLogger,authMap.get("Exception").toString(), AppMessages.MISSINGDATA  ,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, keyspaceName, aid, Operation.DROP_KEYSPACE)) {
+                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
@@ -404,23 +390,20 @@ public class RestMusicDataAPI {
                     @ApiParam(value = "Table Name",required = true) @PathParam("tablename") String tablename) throws Exception {
         try {
         ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
-        if((keyspace == null || keyspace == null) || (tablename.isEmpty() || tablename.isEmpty())){
+        if(keyspace == null || keyspace.isEmpty() || tablename == null || tablename.isEmpty()){
             return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE)
-                    .setError("one or more path parameters are not set, please check and try again")
+                    .setError("One or more path parameters are not set, please check and try again."
+                        + "Parameter values: keyspace='" + keyspace + "' tablename='" + tablename + "'")
                           .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
 
@@ -447,90 +430,90 @@ public class RestMusicDataAPI {
                   else fieldsString.append("," + entry.getKey() + " " + entry.getValue() + "");
             }
 
-             if (counter != (fields.size() - 1) ) {
-              
-              counter = counter + 1; 
-             } else {
-        
-               if((primaryKey != null) && (partitionKey == null)) {
-                  primaryKey = primaryKey.trim();
-                  int count1 = StringUtils.countMatches(primaryKey, ')');
-                  int count2 = StringUtils.countMatches(primaryKey, '(');
-                  if (count1 != count2) {
+            if (counter != (fields.size() - 1) ) {
+
+                counter = counter + 1; 
+            } else {
+
+                if((primaryKey != null) && (partitionKey == null)) {
+                    primaryKey = primaryKey.trim();
+                    int count1 = StringUtils.countMatches(primaryKey, ')');
+                    int count2 = StringUtils.countMatches(primaryKey, '(');
+                    if (count1 != count2) {
                         return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE)
-                             .setError("Create Table Error: primary key '(' and ')' do not match, primary key=" + primaryKey)
-                                   .toMap()).build();
-                  }
+                                .setError("Create Table Error: primary key '(' and ')' do not match, primary key=" + primaryKey)
+                                .toMap()).build();
+                    }
 
-                if ( primaryKey.indexOf('(') == -1  || ( count2 == 1 && (primaryKey.lastIndexOf(')') +1) ==  primaryKey.length() ) )
-                  {
-                         if (primaryKey.contains(",") ) {
+                    if ( primaryKey.indexOf('(') == -1  || ( count2 == 1 && (primaryKey.lastIndexOf(')') +1) ==  primaryKey.length() ) )
+                    {
+                        if (primaryKey.contains(",") ) {
                             partitionKey= primaryKey.substring(0,primaryKey.indexOf(','));
-                             partitionKey=partitionKey.replaceAll("[\\(]+","");
-                             clusterKey=primaryKey.substring(primaryKey.indexOf(',')+1);  // make sure index
-                             clusterKey=clusterKey.replaceAll("[)]+", "");
-                         } else {
-                          partitionKey=primaryKey;
-                          partitionKey=partitionKey.replaceAll("[\\)]+","");
-                             partitionKey=partitionKey.replaceAll("[\\(]+","");
-                          clusterKey="";
+                            partitionKey=partitionKey.replaceAll("[\\(]+","");
+                            clusterKey=primaryKey.substring(primaryKey.indexOf(',')+1);  // make sure index
+                            clusterKey=clusterKey.replaceAll("[)]+", "");
+                        } else {
+                            partitionKey=primaryKey;
+                            partitionKey=partitionKey.replaceAll("[\\)]+","");
+                            partitionKey=partitionKey.replaceAll("[\\(]+","");
+                            clusterKey="";
+                        }
+                    } else {   // not null and has ) before the last char
+                        partitionKey= primaryKey.substring(0,primaryKey.indexOf(')'));
+                        partitionKey=partitionKey.replaceAll("[\\(]+","");
+                        partitionKey = partitionKey.trim();
+                        clusterKey= primaryKey.substring(primaryKey.indexOf(')'));
+                        clusterKey=clusterKey.replaceAll("[\\(]+","");
+                        clusterKey=clusterKey.replaceAll("[\\)]+","");
+                        clusterKey = clusterKey.trim();
+                        if (clusterKey.indexOf(',') == 0) clusterKey=clusterKey.substring(1);
+                        clusterKey = clusterKey.trim();
+                        if (clusterKey.equals(",") ) clusterKey=""; // print error if needed    ( ... ),)
                     }
-                } else {   // not null and has ) before the last char
-                       partitionKey= primaryKey.substring(0,primaryKey.indexOf(')'));
-                       partitionKey=partitionKey.replaceAll("[\\(]+","");
-                       partitionKey = partitionKey.trim();
-                       clusterKey= primaryKey.substring(primaryKey.indexOf(')'));
-                       clusterKey=clusterKey.replaceAll("[\\(]+","");
-                       clusterKey=clusterKey.replaceAll("[\\)]+","");
-                       clusterKey = clusterKey.trim();
-                       if (clusterKey.indexOf(',') == 0) clusterKey=clusterKey.substring(1);
-                       clusterKey = clusterKey.trim();
-                       if (clusterKey.equals(",") ) clusterKey=""; // print error if needed    ( ... ),)
-              }
-
-              if (!(partitionKey.isEmpty() || clusterKey.isEmpty())
-                    && (partitionKey.equalsIgnoreCase(clusterKey) ||
-                      clusterKey.contains(partitionKey) || partitionKey.contains(clusterKey)) )
-               {
-                  logger.error("DataAPI createTable partition/cluster key ERROR: partitionKey="+partitionKey+", clusterKey=" + clusterKey + " and primary key=" + primaryKey );
-                      return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(
-                            "Create Table primary key error: clusterKey(" + clusterKey + ") equals/contains/overlaps partitionKey(" +partitionKey+ ")  of"
-                                    + " primary key=" + primaryKey)
-                              .toMap()).build();
 
-            }
+                    if (!(partitionKey.isEmpty() || clusterKey.isEmpty())
+                            && (partitionKey.equalsIgnoreCase(clusterKey) ||
+                                    clusterKey.contains(partitionKey) || partitionKey.contains(clusterKey)) )
+                    {
+                        logger.error("DataAPI createTable partition/cluster key ERROR: partitionKey="+partitionKey+", clusterKey=" + clusterKey + " and primary key=" + primaryKey );
+                        return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(
+                                "Create Table primary key error: clusterKey(" + clusterKey + ") equals/contains/overlaps partitionKey(" +partitionKey+ ")  of"
+                                        + " primary key=" + primaryKey)
+                                .toMap()).build();
 
-            if (partitionKey.isEmpty() )  primaryKey="";
-            else  if (clusterKey.isEmpty() ) primaryKey=" (" + partitionKey  + ")";
-            else  primaryKey=" (" + partitionKey + ")," + clusterKey;
-
-            
-            if (primaryKey != null) fieldsString.append(", PRIMARY KEY (" + primaryKey + " )");
-
-      } // end of length > 0
-              else {
-                 if (!(partitionKey.isEmpty() || clusterKey.isEmpty())
-                        && (partitionKey.equalsIgnoreCase(clusterKey) ||
-                          clusterKey.contains(partitionKey) || partitionKey.contains(clusterKey)) )
-                   {
-                     logger.error("DataAPI createTable partition/cluster key ERROR: partitionKey="+partitionKey+", clusterKey=" + clusterKey);
-                     return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(
+                    }
+
+                    if (partitionKey.isEmpty() )  primaryKey="";
+                    else  if (clusterKey.isEmpty() ) primaryKey=" (" + partitionKey  + ")";
+                    else  primaryKey=" (" + partitionKey + ")," + clusterKey;
+
+
+                    if (primaryKey != null) fieldsString.append(", PRIMARY KEY (" + primaryKey + " )");
+
+                } // end of length > 0
+                else {
+                    if (!(partitionKey.isEmpty() || clusterKey.isEmpty())
+                            && (partitionKey.equalsIgnoreCase(clusterKey) ||
+                                    clusterKey.contains(partitionKey) || partitionKey.contains(clusterKey)) )
+                    {
+                        logger.error("DataAPI createTable partition/cluster key ERROR: partitionKey="+partitionKey+", clusterKey=" + clusterKey);
+                        return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(
                                 "Create Table primary key error: clusterKey(" + clusterKey + ") equals/contains/overlaps partitionKey(" +partitionKey+ ")")
                                 .toMap()).build();
-                }
+                    }
 
-                if (partitionKey.isEmpty() )  primaryKey="";
-                else  if (clusterKey.isEmpty() ) primaryKey=" (" + partitionKey  + ")";
-                else  primaryKey=" (" + partitionKey + ")," + clusterKey;
+                    if (partitionKey.isEmpty() )  primaryKey="";
+                    else  if (clusterKey.isEmpty() ) primaryKey=" (" + partitionKey  + ")";
+                    else  primaryKey=" (" + partitionKey + ")," + clusterKey;
 
-                
-                if (primaryKey != null) fieldsString.append(", PRIMARY KEY (" + primaryKey + " )");
-            }
-      fieldsString.append(")");
 
-     } // end of last field check
+                    if (primaryKey != null) fieldsString.append(", PRIMARY KEY (" + primaryKey + " )");
+                }
+                fieldsString.append(")");
+
+            } // end of last field check
 
-    } // end of for each
+        } // end of for each
         // information about the name-value style properties
         Map<String, Object> propertiesMap = tableObj.getProperties();
         StringBuilder propertiesString = new StringBuilder();
@@ -558,46 +541,47 @@ public class RestMusicDataAPI {
         String clusteringOrder = tableObj.getClusteringOrder();
 
         if (clusteringOrder != null && !(clusteringOrder.isEmpty())) {
-           String[] arrayClusterOrder = clusteringOrder.split("[,]+");
+            String[] arrayClusterOrder = clusteringOrder.split("[,]+");
 
-        for (int i = 0; i < arrayClusterOrder.length; i++) {
-        String[] clusterS = arrayClusterOrder[i].trim().split("[ ]+");
-        if ( (clusterS.length ==2)  && (clusterS[1].equalsIgnoreCase("ASC") || clusterS[1].equalsIgnoreCase("DESC"))) {
-            continue;
-        } else {
-            return response.status(Status.BAD_REQUEST)
-                .entity(new JsonResponse(ResultType.FAILURE)
-                .setError("createTable/Clustering Order vlaue ERROR: valid clustering order is ASC or DESC or expecting colname  order; please correct clusteringOrder:"+ clusteringOrder+".")
-                .toMap()).build();
-        }
+            for (int i = 0; i < arrayClusterOrder.length; i++) {
+                String[] clusterS = arrayClusterOrder[i].trim().split("[ ]+");
+                if ( (clusterS.length ==2)  && (clusterS[1].equalsIgnoreCase("ASC") || clusterS[1].equalsIgnoreCase("DESC"))) {
+                    continue;
+                } else {
+                    return response.status(Status.BAD_REQUEST)
+                            .entity(new JsonResponse(ResultType.FAILURE)
+                                    .setError("createTable/Clustering Order vlaue ERROR: valid clustering order is ASC or DESC or expecting colname  order; please correct clusteringOrder:"+ clusteringOrder+".")
+                                    .toMap()).build();
+                }
                 // add validation for column names in cluster key
-        }
+            }
 
-       if (!(clusterKey.isEmpty())) {
-            clusteringOrder = "CLUSTERING ORDER BY (" +clusteringOrder +")";
-            //cjc check if propertiesString.length() >0 instead propertiesMap
-            if (propertiesMap != null) {
-                propertiesString.append(" AND  "+ clusteringOrder);
+            if (!(clusterKey.isEmpty())) {
+                clusteringOrder = "CLUSTERING ORDER BY (" +clusteringOrder +")";
+                //cjc check if propertiesString.length() >0 instead propertiesMap
+                if (propertiesMap != null) {
+                    propertiesString.append(" AND  "+ clusteringOrder);
+                } else {
+                    propertiesString.append(clusteringOrder);
+                }
             } else {
-                propertiesString.append(clusteringOrder);
-            }
-       } else {
                 logger.warn("Skipping clustering order=("+clusteringOrder+ ") since clustering key is empty ");
-       }
-    } //if non empty
+            }
+        } //if non empty
 
-    queryObject.appendQueryString(
-        "CREATE TABLE " + keyspace + "." + tablename + " " + fieldsString);
+        queryObject.appendQueryString(
+                "CREATE TABLE " + keyspace + "." + tablename + " " + fieldsString);
 
 
-    if (propertiesString != null &&  propertiesString.length()>0 )
-        queryObject.appendQueryString(" WITH " + propertiesString);
+        if (propertiesString != null &&  propertiesString.length()>0 )
+            queryObject.appendQueryString(" WITH " + propertiesString);
         queryObject.appendQueryString(";");
         ResultType result = ResultType.FAILURE;
         try {
             result = MusicCore.createTable(keyspace, tablename, queryObject, consistency);
         } catch (MusicServiceException ex) {
-            logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR  ,ErrorSeverity.CRITICAL, ErrorTypes.MUSICSERVICEERROR);
+            logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR  ,ErrorSeverity
+                .CRITICAL, ErrorTypes.MUSICSERVICEERROR, ex);
             response.status(Status.BAD_REQUEST);
             return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
         }
@@ -641,17 +625,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)
@@ -664,7 +644,8 @@ public class RestMusicDataAPI {
         try {
             result = MusicCore.nonKeyRelatedPut(query, "eventual");
         } catch (MusicServiceException ex) {
-            logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR  ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+            logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR  ,ErrorSeverity
+                .CRITICAL, ErrorTypes.GENERALSERVICEERROR, ex);
             response.status(Status.BAD_REQUEST);
             return response.entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
         }
@@ -711,23 +692,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();
@@ -739,7 +708,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();
@@ -762,7 +731,8 @@ public class RestMusicDataAPI {
             try {
                 colType = tableInfo.getColumn(entry.getKey()).getType();
             } catch(NullPointerException ex) {
-                logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage() +" Invalid column name : "+entry.getKey(), AppMessages.INCORRECTDATA  ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
+                logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage() +" Invalid column name : "+entry.getKey
+                    (), AppMessages.INCORRECTDATA  ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR, ex);
                 return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Invalid column name : "+entry.getKey()).toMap()).build();
             }
 
@@ -770,7 +740,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("?");
 
@@ -881,12 +851,9 @@ public class RestMusicDataAPI {
                 result = MusicCore.atomicPut(keyspace, tablename, primaryKey, queryObject, null);
 
             }
-            else if (consistency.equalsIgnoreCase(MusicUtil.ATOMICDELETELOCK)) {
-                result = MusicCore.atomicPutWithDeleteLock(keyspace, tablename, primaryKey, queryObject, null);
-
-            }
         } catch (Exception ex) {
-            logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR  ,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
+            logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR  ,ErrorSeverity
+                .WARN, ErrorTypes.MUSICSERVICEERROR, ex);
             return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
         }
 
@@ -943,23 +910,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.
@@ -976,7 +933,8 @@ 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, e);
               return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
         }
         if (tableInfo == null) {
@@ -996,14 +954,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(), ex);
                 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);
@@ -1043,7 +1001,8 @@ 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, ex);
               return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
         }
 
@@ -1091,7 +1050,8 @@ 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, e);
                   return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
             }
         } else if (consistency.equalsIgnoreCase(MusicUtil.ATOMIC)) {
@@ -1099,7 +1059,8 @@ 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, e);
                 return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
             }
         }else if(consistency.equalsIgnoreCase(MusicUtil.EVENTUAL_NB)) {
@@ -1176,23 +1137,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();
@@ -1201,7 +1152,7 @@ public class RestMusicDataAPI {
         StringBuilder columnString = new StringBuilder();
 
         int counter = 0;
-        ArrayList<String> columnList = delObj.getColumns();
+        List<String> columnList = delObj.getColumns();
         if (columnList != null) {
             for (String column : columnList) {
                 columnString.append(column);
@@ -1216,7 +1167,8 @@ 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, ex);
               return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
         }
         String rowSpec = rowId.rowIdString.toString();
@@ -1277,16 +1229,13 @@ public class RestMusicDataAPI {
             } else if (consistency.equalsIgnoreCase(MusicUtil.ATOMIC)) {
                     operationResult = MusicCore.atomicPut(keyspace, tablename, rowId.primarKeyValue,
                                     queryObject, conditionInfo);
-            }
-            else if (consistency.equalsIgnoreCase(MusicUtil.ATOMICDELETELOCK)) {
-                    operationResult = MusicCore.atomicPutWithDeleteLock(keyspace, tablename, rowId.primarKeyValue,
-                                    queryObject, conditionInfo);
-            }else if(consistency.equalsIgnoreCase(MusicUtil.EVENTUAL_NB)) {
+            } else if(consistency.equalsIgnoreCase(MusicUtil.EVENTUAL_NB)) {
                 
                 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, e);
               return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE)
                     .setError("Unable to perform Delete operation. Exception from music").toMap()).build();
         }
@@ -1339,17 +1288,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();
@@ -1357,7 +1302,8 @@ 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 {
@@ -1403,16 +1349,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();
@@ -1421,7 +1364,8 @@ 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, ex);
               return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
         }
         queryObject.appendQueryString(
@@ -1443,10 +1387,6 @@ public class RestMusicDataAPI {
         } else if (consistency.equalsIgnoreCase(MusicUtil.ATOMIC)) {
             results = MusicCore.atomicGet(keyspace, tablename, rowId.primarKeyValue, queryObject);
         }
-
-        else if (consistency.equalsIgnoreCase(MusicUtil.ATOMICDELETELOCK)) {
-            results = MusicCore.atomicGetWithDeleteLock(keyspace, tablename, rowId.primarKeyValue, queryObject);
-        }
         if(results!=null && results.getAvailableWithoutFetching() >0) {
             return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setDataResult(MusicDataStoreHandle.marshallResults(results)).toMap()).build();
         }
@@ -1493,17 +1433,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
@@ -1511,10 +1447,10 @@ 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, ex);
                 return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
             }
         }
@@ -1526,7 +1462,8 @@ 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, ex);
             return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
         }
         } finally {
@@ -1543,9 +1480,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();
@@ -1598,7 +1534,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);