diff options
author | Thomas Nelson Jr (arthurdent3) <tn1381@att.com> | 2018-02-23 15:14:24 -0500 |
---|---|---|
committer | Thomas Nelson Jr (arthurdent3) <tn1381@att.com> | 2018-02-23 15:29:08 -0500 |
commit | b6a14a0dc52c9ed43b035aff79831fc32fd52fe3 (patch) | |
tree | 400ba474c44d779632406d3d998e65038816eed1 /src/main/java/org/onap/music/rest | |
parent | 3acbae6bf3be04f352bfaac340b8303064a2f7c4 (diff) |
Changes related to Authentication and Atomic
Authentication Fixes
Atomic with delete added.
Issue-ID: MUSIC-38,MUSIC-39
Change-Id: Ide2974a42ff8618d8a94ef7e8a1b0abde3630550
Signed-off-by: Thomas Nelson Jr (arthurdent3) <tn1381@att.com>
Diffstat (limited to 'src/main/java/org/onap/music/rest')
4 files changed, 130 insertions, 47 deletions
diff --git a/src/main/java/org/onap/music/rest/RestMusicBmAPI.java b/src/main/java/org/onap/music/rest/RestMusicBmAPI.java index 8f62f9c1..55eb47f2 100644 --- a/src/main/java/org/onap/music/rest/RestMusicBmAPI.java +++ b/src/main/java/org/onap/music/rest/RestMusicBmAPI.java @@ -31,25 +31,18 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.UriInfo; -import org.apache.log4j.Logger; import org.onap.music.datastore.jsonobjects.JsonInsert; -import org.onap.music.datastore.jsonobjects.JsonOnboard; -import org.onap.music.datastore.jsonobjects.JsonUpdate; import org.onap.music.eelf.logging.EELFLoggerDelegate; -import org.onap.music.main.CachingUtil; import org.onap.music.main.MusicCore; import org.onap.music.main.MusicUtil; import org.onap.music.main.ResultType; import org.onap.music.main.ReturnType; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import org.onap.music.datastore.PreparedQueryObject; import com.datastax.driver.core.DataType; -import com.datastax.driver.core.ResultSet; import com.datastax.driver.core.TableMetadata; import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; +//import io.swagger.annotations.ApiOperation; +//import io.swagger.annotations.ApiParam; /* * These are functions created purely for benchmarking purposes. Commented out Swagger - This should diff --git a/src/main/java/org/onap/music/rest/RestMusicDataAPI.java b/src/main/java/org/onap/music/rest/RestMusicDataAPI.java index e16cc373..f1d88efa 100755 --- a/src/main/java/org/onap/music/rest/RestMusicDataAPI.java +++ b/src/main/java/org/onap/music/rest/RestMusicDataAPI.java @@ -36,8 +36,6 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.UriInfo; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import org.onap.music.datastore.PreparedQueryObject; import org.onap.music.datastore.jsonobjects.JsonDelete; import org.onap.music.datastore.jsonobjects.JsonInsert; @@ -93,6 +91,7 @@ public class RestMusicDataAPI { private class RowIdentifier { public String primarKeyValue; public StringBuilder rowIdString; + @SuppressWarnings("unused") public PreparedQueryObject queryObject;// the string with all the row // identifiers separated by AND @@ -104,6 +103,7 @@ public class RestMusicDataAPI { } } + @SuppressWarnings("unused") private String buildVersion(String major, String minor, String patch) { if (minor != null) { major += "." + minor; @@ -187,12 +187,14 @@ public class RestMusicDataAPI { logger.error(EELFLoggerDelegate.errorLogger, "resulta = " + result); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, e.getMessage()); + resultMap.put("Exception", "Couldn't create keyspace. Please make sure all the information is correct."); } logger.debug("result = " + result); if (!result) { resultMap.put("Status", String.valueOf(result)); - resultMap.put("Exception", "Keyspace already exists. Please contact admin."); + if(!resultMap.containsKey("Exception")) + resultMap.put("Exception", "Keyspace already exists. Please contact admin."); if (resultMap.get("uuid").equals("new")) { queryObject = new PreparedQueryObject(); queryObject.appendQueryString( @@ -206,10 +208,9 @@ public class RestMusicDataAPI { } else { queryObject = new PreparedQueryObject(); queryObject.appendQueryString( - "UPDATE admin.keyspace_master SET keyspace_name=?,password=?,is_api=null where uuid = ?;"); + "UPDATE admin.keyspace_master SET keyspace_name=? where uuid = ?;"); queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), MusicUtil.DEFAULTKEYSPACENAME)); - queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), null)); queryObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), newAid)); result = MusicCore.nonKeyRelatedPut(queryObject, consistency); resultMap.remove("aid"); @@ -223,17 +224,11 @@ public class RestMusicDataAPI { queryObject.appendQueryString("CREATE ROLE IF NOT EXISTS '" + userId + "' WITH PASSWORD = '" + password + "' AND LOGIN = true;"); result = MusicCore.nonKeyRelatedPut(queryObject, consistency); - if (result) { - queryObject = new PreparedQueryObject(); - queryObject.appendQueryString("GRANT ALL PERMISSIONS on KEYSPACE " + keyspaceName - + " to " + userId); - queryObject.appendQueryString(";"); - result = MusicCore.nonKeyRelatedPut(queryObject, consistency); - } else { - resultMap.remove("uuid"); - resultMap.put("Exception", "Exception while creating user."); - return resultMap; - } + queryObject = new PreparedQueryObject(); + queryObject.appendQueryString("GRANT ALL PERMISSIONS on KEYSPACE " + keyspaceName + + " to '" + userId + "'"); + queryObject.appendQueryString(";"); + result = MusicCore.nonKeyRelatedPut(queryObject, consistency); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, e.getMessage()); } @@ -393,6 +388,7 @@ public class RestMusicDataAPI { if (ot instanceof String) { value = "'" + value + "'"; } else if (ot instanceof Map) { + @SuppressWarnings("unchecked") Map<String, Object> otMap = (Map<String, Object>) ot; value = "{" + MusicUtil.jsonMaptoSqlString(otMap, ",") + "}"; } @@ -589,6 +585,10 @@ 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); + + } return (result != null) ? result.toMap() : new ReturnType(ResultType.FAILURE, "Null result - Please Contact admin").toMap(); @@ -862,6 +862,10 @@ public class RestMusicDataAPI { operationResult = MusicCore.atomicPut(keyspace, tablename, rowId.primarKeyValue, queryObject, conditionInfo); } + else if (consistency.equalsIgnoreCase(MusicUtil.ATOMICDELETELOCK)) { + operationResult = MusicCore.atomicPutWithDeleteLock(keyspace, tablename, rowId.primarKeyValue, + queryObject, conditionInfo); + } try { return operationResult.toMap(); } catch (NullPointerException e) { @@ -970,7 +974,6 @@ public class RestMusicDataAPI { String lockId = selObj.getConsistencyInfo().get("lockId"); PreparedQueryObject queryObject = new PreparedQueryObject(); - StringBuilder rowSpec = new StringBuilder(); RowIdentifier rowId = null; try { @@ -979,18 +982,22 @@ public class RestMusicDataAPI { return MusicUtil.setErrorResponse(ex); } queryObject.appendQueryString( - "SELECT * FROM " + keyspace + "." + tablename + " WHERE " + rowSpec + ";"); + "SELECT * FROM " + keyspace + "." + tablename + " WHERE " + rowId.rowIdString + ";"); ResultSet results = null; String consistency = selObj.getConsistencyInfo().get("type"); - if (consistency.equalsIgnoreCase("critical")) { + if (consistency.equalsIgnoreCase(MusicUtil.CRITICAL)) { results = MusicCore.criticalGet(keyspace, tablename, rowId.primarKeyValue, queryObject, lockId); - } else if (consistency.equalsIgnoreCase("atomic")) { + } 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); + } return MusicCore.marshallResults(results); } diff --git a/src/main/java/org/onap/music/rest/RestMusicLocksAPI.java b/src/main/java/org/onap/music/rest/RestMusicLocksAPI.java index 5f28f447..e565e829 100644 --- a/src/main/java/org/onap/music/rest/RestMusicLocksAPI.java +++ b/src/main/java/org/onap/music/rest/RestMusicLocksAPI.java @@ -27,6 +27,7 @@ import javax.servlet.http.HttpServletResponse; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; @@ -37,16 +38,11 @@ import javax.ws.rs.core.MediaType; import org.onap.music.datastore.jsonobjects.JsonLeasedLock; import org.onap.music.eelf.logging.EELFLoggerDelegate; import org.onap.music.lockingservice.MusicLockState; -import org.onap.music.lockingservice.MusicLockState.LockStatus; import org.onap.music.main.MusicCore; import org.onap.music.main.MusicUtil; import org.onap.music.main.ResultType; import org.onap.music.main.ReturnType; import org.onap.music.response.jsonobjects.JsonLockResponse; -import org.powermock.core.spi.testresult.Result; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -57,7 +53,8 @@ import io.swagger.annotations.ApiParam; @Api(value="Lock Api") public class RestMusicLocksAPI { - private EELFLoggerDelegate logger =EELFLoggerDelegate.getLogger(RestMusicLocksAPI.class); + @SuppressWarnings("unused") + private EELFLoggerDelegate logger =EELFLoggerDelegate.getLogger(RestMusicLocksAPI.class); private static String xLatestVersion = "X-latestVersion"; /** @@ -66,6 +63,7 @@ public class RestMusicLocksAPI { * * @param lockName * @return + * @throws Exception */ @POST @@ -78,8 +76,20 @@ public class RestMusicLocksAPI { @Produces(MediaType.APPLICATION_JSON) public Map<String,Object> createLockReference( @ApiParam(value="Lock Name",required=true) @PathParam("lockname") String lockName, - @Context HttpServletResponse response){ - response.addHeader(xLatestVersion,MusicUtil.getVersion()); + @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid, + @ApiParam(value = "Application namespace", + required = true) @HeaderParam("ns") String ns, + @ApiParam(value = "userId", + required = true) @HeaderParam("userId") String userId, + @ApiParam(value = "Password", + required = true) @HeaderParam("password") String password, + @Context HttpServletResponse response) throws Exception{ + response.addHeader(xLatestVersion,MusicUtil.getVersion()); + Map<String, Object> resultMap = MusicCore.autheticateUser(ns, userId, password, null, aid, + "createLockReference"); + if (!resultMap.isEmpty()) { + return resultMap; + } ResultType status = ResultType.SUCCESS; String lockId = MusicCore.createLockReference(lockName); if (lockId == null) { status = ResultType.FAILURE; } @@ -92,6 +102,7 @@ public class RestMusicLocksAPI { * * @param lockId * @return + * @throws Exception */ @GET @Path("/acquire/{lockreference}") @@ -101,8 +112,20 @@ public class RestMusicLocksAPI { @Produces(MediaType.APPLICATION_JSON) public Map<String,Object> accquireLock( @ApiParam(value="Lock Reference",required=true) @PathParam("lockreference") String lockId, - @Context HttpServletResponse response){ + @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid, + @ApiParam(value = "Application namespace", + required = true) @HeaderParam("ns") String ns, + @ApiParam(value = "userId", + required = true) @HeaderParam("userId") String userId, + @ApiParam(value = "Password", + required = true) @HeaderParam("password") String password, + @Context HttpServletResponse response) throws Exception{ response.addHeader(xLatestVersion,MusicUtil.getVersion()); + Map<String, Object> resultMap = MusicCore.autheticateUser(ns, userId, password, null, aid, + "accquireLock"); + if (!resultMap.isEmpty()) { + return resultMap; + } String lockName = lockId.substring(lockId.indexOf('$')+1, lockId.lastIndexOf('$')); ReturnType lockStatus = MusicCore.acquireLock(lockName,lockId); return new JsonLockResponse(lockStatus.getResult()).setLock(lockId) @@ -119,8 +142,20 @@ public class RestMusicLocksAPI { @Produces(MediaType.APPLICATION_JSON) public Map<String,Object> accquireLockWithLease(JsonLeasedLock lockObj, @ApiParam(value="Lock Reference",required=true) @PathParam("lockreference") String lockId, - @Context HttpServletResponse response){ + @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid, + @ApiParam(value = "Application namespace", + required = true) @HeaderParam("ns") String ns, + @ApiParam(value = "userId", + required = true) @HeaderParam("userId") String userId, + @ApiParam(value = "Password", + required = true) @HeaderParam("password") String password, + @Context HttpServletResponse response) throws Exception{ response.addHeader(xLatestVersion,MusicUtil.getVersion()); + Map<String, Object> resultMap = MusicCore.autheticateUser(ns, userId, password, null, aid, + "accquireLockWithLease"); + if (!resultMap.isEmpty()) { + return resultMap; + } String lockName = lockId.substring(lockId.indexOf('$')+1, lockId.lastIndexOf('$')); ReturnType lockLeaseStatus = MusicCore.acquireLockWithLease(lockName, lockId, lockObj.getLeasePeriod()); return new JsonLockResponse(lockLeaseStatus.getResult()).setLock(lockName) @@ -137,8 +172,20 @@ public class RestMusicLocksAPI { @Produces(MediaType.APPLICATION_JSON) public Map<String,Object> currentLockHolder( @ApiParam(value="Lock Name",required=true) @PathParam("lockname") String lockName, - @Context HttpServletResponse response){ + @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid, + @ApiParam(value = "Application namespace", + required = true) @HeaderParam("ns") String ns, + @ApiParam(value = "userId", + required = true) @HeaderParam("userId") String userId, + @ApiParam(value = "Password", + required = true) @HeaderParam("password") String password, + @Context HttpServletResponse response) throws Exception{ response.addHeader(xLatestVersion,MusicUtil.getVersion()); + Map<String, Object> resultMap = MusicCore.autheticateUser(ns, userId, password, null, aid, + "currentLockHolder"); + if (!resultMap.isEmpty()) { + return resultMap; + } String who = MusicCore.whoseTurnIsIt(lockName); ResultType status = ResultType.SUCCESS; String error = ""; @@ -158,8 +205,20 @@ public class RestMusicLocksAPI { @Produces(MediaType.APPLICATION_JSON) public Map<String,Object> currentLockState( @ApiParam(value="Lock Name",required=true) @PathParam("lockname") String lockName, - @Context HttpServletResponse response){ + @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid, + @ApiParam(value = "Application namespace", + required = true) @HeaderParam("ns") String ns, + @ApiParam(value = "userId", + required = true) @HeaderParam("userId") String userId, + @ApiParam(value = "Password", + required = true) @HeaderParam("password") String password, + @Context HttpServletResponse response) throws Exception{ response.addHeader(xLatestVersion,MusicUtil.getVersion()); + Map<String, Object> resultMap = MusicCore.autheticateUser(ns, userId, password, null, aid, + "currentLockState"); + if (!resultMap.isEmpty()) { + return resultMap; + } MusicLockState mls = MusicCore.getMusicLockState(lockName); Map<String,Object> returnMap = null; JsonLockResponse jsonResponse = new JsonLockResponse(ResultType.FAILURE).setLock(lockName); @@ -179,6 +238,7 @@ public class RestMusicLocksAPI { * deletes the process from the zk queue * * @param lockId + * @throws Exception */ @DELETE @Path("/release/{lockreference}") @@ -187,8 +247,20 @@ public class RestMusicLocksAPI { response = Map.class) @Produces(MediaType.APPLICATION_JSON) public Map<String,Object> unLock(@PathParam("lockreference") String lockId, - @Context HttpServletResponse response){ + @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid, + @ApiParam(value = "Application namespace", + required = true) @HeaderParam("ns") String ns, + @ApiParam(value = "userId", + required = true) @HeaderParam("userId") String userId, + @ApiParam(value = "Password", + required = true) @HeaderParam("password") String password, + @Context HttpServletResponse response) throws Exception{ response.addHeader(xLatestVersion,MusicUtil.getVersion()); + Map<String, Object> resultMap = MusicCore.autheticateUser(ns, userId, password, null, aid, + "unLock"); + if (!resultMap.isEmpty()) { + return resultMap; + } boolean voluntaryRelease = true; MusicLockState mls = MusicCore.releaseLock(lockId,voluntaryRelease); Map<String,Object> returnMap = null; @@ -206,14 +278,27 @@ public class RestMusicLocksAPI { /** * * @param lockName + * @throws Exception */ @DELETE @Path("/delete/{lockname}") @ApiOperation(value = "Delete Lock", response = Map.class) @Produces(MediaType.APPLICATION_JSON) public Map<String,Object> deleteLock(@PathParam("lockname") String lockName, - @Context HttpServletResponse response){ + @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid, + @ApiParam(value = "Application namespace", + required = true) @HeaderParam("ns") String ns, + @ApiParam(value = "userId", + required = true) @HeaderParam("userId") String userId, + @ApiParam(value = "Password", + required = true) @HeaderParam("password") String password, + @Context HttpServletResponse response) throws Exception{ response.addHeader(xLatestVersion,MusicUtil.getVersion()); + Map<String, Object> resultMap = MusicCore.autheticateUser(ns, userId, password, null, aid, + "deleteLock"); + if (!resultMap.isEmpty()) { + return resultMap; + } MusicCore.deleteLock(lockName); return new JsonLockResponse(ResultType.SUCCESS).toMap(); } diff --git a/src/main/java/org/onap/music/rest/RestMusicTestAPI.java b/src/main/java/org/onap/music/rest/RestMusicTestAPI.java index f606eb8d..287fa176 100644 --- a/src/main/java/org/onap/music/rest/RestMusicTestAPI.java +++ b/src/main/java/org/onap/music/rest/RestMusicTestAPI.java @@ -34,9 +34,6 @@ import javax.ws.rs.core.MediaType; import org.onap.music.eelf.logging.EELFLoggerDelegate; import org.onap.music.main.MusicUtil; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -45,7 +42,8 @@ import io.swagger.annotations.ApiOperation; @Api(value="Test Api") public class RestMusicTestAPI { - private EELFLoggerDelegate logger =EELFLoggerDelegate.getLogger(RestMusicTestAPI.class); + @SuppressWarnings("unused") + private EELFLoggerDelegate logger =EELFLoggerDelegate.getLogger(RestMusicTestAPI.class); /** * Returns a test JSON. This will confirm that REST is working. |