tvaultapi/src/main/java/com/tmobile/cso/vault/api/controller/ControllerUtil.java
public static Response canDeleteRole(String roleName, String token, UserDetails userDetails, String metadataPath) {
		log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
				put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
				put(LogMessage.ACTION, "canDeleteRole").
				put(LogMessage.MESSAGE,"Start checking whether the current user can delete a role.").
				put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
				build()));
		Response response = new Response();
		String _path = metadataPath + "/" + roleName;
		Response readResponse = reqProcessor.process(READSTR,PATHSTR+_path+"\"}",token);
		Map<String, Object> responseMap = null;
		if(HttpStatus.OK.equals(readResponse.getHttpstatus())) {
			responseMap = ControllerUtil.parseJson(readResponse.getResponse());
			if(responseMap.isEmpty()) {
				response.setHttpstatus(HttpStatus.INTERNAL_SERVER_ERROR);
				response.setResponse("Error reading role info");
				response.setSuccess(false);
				return response;
			}
			// Safeadmin can always delete any role
			if (userDetails.isAdmin()) {
				response.setHttpstatus(HttpStatus.OK);
				response.setResponse(TVaultConstants.EMPTY);
				response.setSuccess(true);
				return response;
			}
			// normal users
			Map<String,Object> metadataMap = (Map<String,Object>)responseMap.get("data");
			if (userDetails.getUsername().equalsIgnoreCase((String)metadataMap.get("createdBy"))) {
				response.setHttpstatus(HttpStatus.OK);
				response.setResponse(TVaultConstants.EMPTY);
				response.setSuccess(true);
				return response;
			}
		} else if (HttpStatus.NOT_FOUND.equals(readResponse.getHttpstatus()) && userDetails.isAdmin()) {
			response.setHttpstatus(HttpStatus.OK);
			response.setResponse(TVaultConstants.EMPTY);
			response.setSuccess(true);
			return response;
		}
		response.setHttpstatus(HttpStatus.UNAUTHORIZED);
		response.setResponse("Either role doesn't exist or you don't have enough permission to remove this role from Safe");
		response.setSuccess(false);
		return response;
	}
/**
	 * Check whether the current user can delete a role
	 * @param approle
	 * @param token
	 * @param userDetails
	 * @return
	 */
Check whether the current user can delete a role
@param approle
@param token
@param userDetails
@return
Check whether the current user can delete a role @param approle @param token @param userDetails @return
public static Response canDeleteRole(String roleName, String token, UserDetails userDetails, String metadataPath) {
		log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
				put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
				put(LogMessage.ACTION, "canDeleteRole").
				put(LogMessage.MESSAGE,"Start checking whether the current user can delete a role.").
				put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
				build()));
		Response response = new Response();
		String _path = metadataPath + "/" + roleName;
		Response readResponse = reqProcessor.process(READSTR,PATHSTR+_path+"\"}",token);
		Map<String, Object> responseMap = null;
		if(HttpStatus.OK.equals(readResponse.getHttpstatus())) {
			responseMap = ControllerUtil.parseJson(readResponse.getResponse());
			if(responseMap.isEmpty()) {
				response.setHttpstatus(HttpStatus.INTERNAL_SERVER_ERROR);
				response.setResponse("Error reading role info");
				response.setSuccess(false);
				return response;
			}
			if (userDetails.isAdmin()) {
				response.setHttpstatus(HttpStatus.OK);
				response.setResponse(TVaultConstants.EMPTY);
				response.setSuccess(true);
				return response;
			}
			Map<String,Object> metadataMap = (Map<String,Object>)responseMap.get("data");
			if (userDetails.getUsername().equalsIgnoreCase((String)metadataMap.get("createdBy"))) {
				response.setHttpstatus(HttpStatus.OK);
				response.setResponse(TVaultConstants.EMPTY);
				response.setSuccess(true);
				return response;
			}
		} else if (HttpStatus.NOT_FOUND.equals(readResponse.getHttpstatus()) && userDetails.isAdmin()) {
			response.setHttpstatus(HttpStatus.OK);
			response.setResponse(TVaultConstants.EMPTY);
			response.setSuccess(true);
			return response;
		}
		response.setHttpstatus(HttpStatus.UNAUTHORIZED);
		response.setResponse("Either role doesn't exist or you don't have enough permission to remove this role from Safe");
		response.setSuccess(false);
		return response;
	}
public static Response canDeleteRole ( String roleName , String token , UserDetails userDetails , String metadataPath ) { log . debug ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , "canDeleteRole" ) . put ( LogMessage . MESSAGE , "Start checking whether the current user can delete a role." ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; Response response = new Response ( ) ; String _path = metadataPath + "/" + roleName ; Response readResponse = reqProcessor . process ( READSTR , PATHSTR + _path + "\"}" , token ) ; Map < String , Object > responseMap = null ; if ( HttpStatus . OK . equals ( readResponse . getHttpstatus ( ) ) ) { responseMap = ControllerUtil . parseJson ( readResponse . getResponse ( ) ) ; if ( responseMap . isEmpty ( ) ) { response . setHttpstatus ( HttpStatus . INTERNAL_SERVER_ERROR ) ; response . setResponse ( "Error reading role info" ) ; response . setSuccess ( false ) ; return response ; } if ( userDetails . isAdmin ( ) ) { response . setHttpstatus ( HttpStatus . OK ) ; response . setResponse ( TVaultConstants . EMPTY ) ; response . setSuccess ( true ) ; return response ; } Map < String , Object > metadataMap = ( Map < String , Object > ) responseMap . get ( "data" ) ; if ( userDetails . getUsername ( ) . equalsIgnoreCase ( ( String ) metadataMap . get ( "createdBy" ) ) ) { response . setHttpstatus ( HttpStatus . OK ) ; response . setResponse ( TVaultConstants . EMPTY ) ; response . setSuccess ( true ) ; return response ; } } else if ( HttpStatus . NOT_FOUND . equals ( readResponse . getHttpstatus ( ) ) && userDetails . isAdmin ( ) ) { response . setHttpstatus ( HttpStatus . OK ) ; response . setResponse ( TVaultConstants . EMPTY ) ; response . setSuccess ( true ) ; return response ; } response . setHttpstatus ( HttpStatus . UNAUTHORIZED ) ; response . setResponse ( "Either role doesn't exist or you don't have enough permission to remove this role from Safe" ) ; response . setSuccess ( false ) ; return response ; }
Check whether the current user can delete a role
 @param approle
 @param token
 @param userDetails
 @return
Check whether the current user can delete a role @param approle @param token @param userDetails @return
// Safeadmin can always delete any role // normal users