import java.util.Date;
import java.util.List;
-
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.POST;
import com.att.nsa.cambria.metabroker.Broker.TopicExistsException;
import com.att.nsa.cambria.security.DMaaPAAFAuthenticator;
import com.att.nsa.cambria.security.DMaaPAAFAuthenticatorImpl;
+import com.att.nsa.cambria.security.DMaaPAuthenticatorImpl;
import com.att.nsa.cambria.service.MMService;
/**
@Autowired
private DMaaPErrorMessages errorMessages;
+ private DMaaPAAFAuthenticator dmaapAAFauthenticator = new DMaaPAAFAuthenticatorImpl();
+
/**
* This method is used for taking Configuration Object,HttpServletRequest
* Object,HttpServletRequest HttpServletResponse Object,HttpServletSession
sendErrResponse(ctx, errorMessages.getIncorrectJson());
LOGGER.error("JsonSyntaxException: ", ex);
}
- String name = createMirrorMaker.getCreateMirrorMaker().getName();
+ String name = createMirrorMaker.getCreateMirrorMaker()==null? "":createMirrorMaker.getCreateMirrorMaker().getName();
// send error message if it is not a CreateMirrorMaker request.
if (createMirrorMaker.getCreateMirrorMaker() == null) {
sendErrResponse(ctx, "This is not a CreateMirrorMaker request. Please try again.");
|| createMirrorMaker.getCreateMirrorMaker().getStatus() != null) {
sendErrResponse(ctx, "This is not a CreateMirrorMaker request. Please try again.");
}
-
+
// if empty, blank name is entered
else if (StringUtils.isBlank(name)) {
sendErrResponse(ctx, "Name can not be empty or blank.");
// Check if request has listAllMirrorMaker and
// listAllMirrorMaker is empty
- if ((jsonOb != null) && (jsonOb.has("listAllMirrorMaker") &&
- jsonOb.getJSONObject("listAllMirrorMaker").length() == 0)) {
+ if ((jsonOb != null) && (jsonOb.has("listAllMirrorMaker")
+ && jsonOb.getJSONObject("listAllMirrorMaker").length() == 0)) {
jsonOb.put("messageID", randomStr);
InputStream inStream = null;
LOGGER.error("JsonSyntaxException: ", ex);
}
- String name = updateMirrorMaker.getUpdateMirrorMaker().getName();
-
+ String name = updateMirrorMaker.getUpdateMirrorMaker()==null? "":updateMirrorMaker.getUpdateMirrorMaker().getName();
// send error message if it is not a UpdateMirrorMaker request.
if (updateMirrorMaker.getUpdateMirrorMaker() == null) {
sendErrResponse(ctx, "This is not a UpdateMirrorMaker request. Please try again.");
|| updateMirrorMaker.getUpdateMirrorMaker().getStatus() != null) {
sendErrResponse(ctx, "This is not a UpdateMirrorMaker request. Please try again.");
}
-
+
// if empty, blank name is entered
else if (StringUtils.isBlank(name)) {
sendErrResponse(ctx, "Name can not be empty or blank.");
// Check if request has DeleteMirrorMaker and
// DeleteMirrorMaker has MirrorMaker object with name variable
// and check if the name contain only alpha numeric
- if ((jsonOb != null) && (jsonOb.has("deleteMirrorMaker")
- && jsonOb.getJSONObject("deleteMirrorMaker").length() == 1
- && jsonOb.getJSONObject("deleteMirrorMaker").has("name")
- && !StringUtils.isBlank(jsonOb.getJSONObject("deleteMirrorMaker").getString("name"))
- && isAlphaNumeric(jsonOb.getJSONObject("deleteMirrorMaker").getString("name")))) {
+ if ((jsonOb != null)
+ && (jsonOb.has("deleteMirrorMaker") && jsonOb.getJSONObject("deleteMirrorMaker").length() == 1
+ && jsonOb.getJSONObject("deleteMirrorMaker").has("name")
+ && !StringUtils.isBlank(jsonOb.getJSONObject("deleteMirrorMaker").getString("name"))
+ && isAlphaNumeric(jsonOb.getJSONObject("deleteMirrorMaker").getString("name")))) {
jsonOb.put("messageID", randomStr);
InputStream inStream = null;
inStream = IOUtils.toInputStream(jsonOb.toString(), UTF_8);
} catch (IOException ioe) {
- ioe.printStackTrace();
LOGGER.error("IOException: ", ioe);
}
}
} catch (IOException ioe) {
-
- ioe.printStackTrace();
LOGGER.error("IOException: ", ioe);
}
for (int i = 0; i < jArray.length(); i++) {
jObj = jArray.getJSONObject(i);
-
+
JSONObject obj = new JSONObject();
if (jObj.has(MESSAGE)) {
obj = jObj.getJSONObject(MESSAGE);
boolean hasPermission = false;
- DMaaPAAFAuthenticator aaf = new DMaaPAAFAuthenticatorImpl();
-
- if (aaf.aafAuthentication(ctx.getRequest(), permission)) {
+ if (dmaapAAFauthenticator.aafAuthentication(ctx.getRequest(), permission)) {
hasPermission = true;
}
return hasPermission;
for (int i = 0; i < jsonArray.length(); i++) {
jsonObj = jsonArray.getJSONObject(i);
-
+
JSONObject obj = new JSONObject();
if (jsonObj.has(MESSAGE)) {
obj = jsonObj.getJSONObject(MESSAGE);
}
} catch (Exception e) {
- e.printStackTrace();
- LOGGER.error("Exception: ", e);
+ LOGGER.error("Exception: ", e);
}
}
LOGGER.error(errMsg);
} catch (JSONException | IOException e) {
- LOGGER.error(errMsg);
+ LOGGER.error("Error at sendErrResponse method:" + errMsg + "Exception name:" + e.getMessage());
}
}
// numeric
// and check if the request has namespace and namespace contains
// only alpha numeric
- if (jsonOb != null
- && jsonOb.length() == 2 && jsonOb.has("name")
- && !StringUtils.isBlank(jsonOb.getString("name"))
- && isAlphaNumeric(jsonOb.getString("name")) && jsonOb.has(NAMESPACE)
- && !StringUtils.isBlank(jsonOb.getString(NAMESPACE))) {
+ if (jsonOb != null && jsonOb.length() == 2 && jsonOb.has("name")
+ && !StringUtils.isBlank(jsonOb.getString("name")) && isAlphaNumeric(jsonOb.getString("name"))
+ && jsonOb.has(NAMESPACE) && !StringUtils.isBlank(jsonOb.getString(NAMESPACE))) {
String permission = AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop,
"msgRtr.mirrormakeruser.aaf.create") + jsonOb.getString(NAMESPACE) + "|create";
inStream = IOUtils.toInputStream(listAll.toString(), UTF_8);
} catch (IOException ioe) {
- ioe.printStackTrace();
LOGGER.error("IOException: ", ioe);
}
// call listAllMirrorMaker
if (msgFrmSubscribe != null && msgFrmSubscribe.length() > 0
&& isListMirrorMaker(msgFrmSubscribe, randomStr)) {
-
+
JSONArray listMirrorMaker;
listMirrorMaker = getListMirrorMaker(msgFrmSubscribe, randomStr);
LOGGER.error("JSONException: ", ex);
}
- // Check if the request has name and name contains only alpha numeric,
+ // Check if the request has name and name contains only alpha
+ // numeric,
// check if the request has namespace and
// check if the request has whitelistTopicName
// check if the topic name contains only alpha numeric
if (jsonOb != null && jsonOb.length() == 3 && jsonOb.has("name")
- && !StringUtils.isBlank(jsonOb.getString("name"))
- && isAlphaNumeric(jsonOb.getString("name"))
+ && !StringUtils.isBlank(jsonOb.getString("name")) && isAlphaNumeric(jsonOb.getString("name"))
&& jsonOb.has(NAMESPACE) && !StringUtils.isBlank(jsonOb.getString(NAMESPACE))
- && jsonOb.has("whitelistTopicName") && !StringUtils.isBlank(jsonOb.getString("whitelistTopicName"))
- && isAlphaNumeric(jsonOb.getString("whitelistTopicName").substring(jsonOb.getString("whitelistTopicName").lastIndexOf(".")+1,
+ && jsonOb.has("whitelistTopicName")
+ && !StringUtils.isBlank(jsonOb.getString("whitelistTopicName"))
+ && isAlphaNumeric(jsonOb.getString("whitelistTopicName").substring(
+ jsonOb.getString("whitelistTopicName").lastIndexOf(".") + 1,
jsonOb.getString("whitelistTopicName").length()))) {
String permission = AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop,
inStream = IOUtils.toInputStream(listAll.toString(), UTF_8);
} catch (IOException ioe) {
- ioe.printStackTrace();
LOGGER.error("IOException: ", ioe);
}
// call listAllMirrorMaker
if (msgFrmSubscribe != null && msgFrmSubscribe.length() > 0
&& isListMirrorMaker(msgFrmSubscribe, randomStr)) {
-
+
listMirrorMaker = getListMirrorMaker(msgFrmSubscribe, randomStr);
String whitelist = null;
LOGGER.error("JSONException: ", ex);
}
- // Check if the request has name and name contains only alpha numeric,
+ // Check if the request has name and name contains only alpha
+ // numeric,
// check if the request has namespace and
// check if the request has whitelistTopicName
- if (jsonOb != null && jsonOb.length() == 3 && jsonOb.has("name") && isAlphaNumeric(jsonOb.getString("name"))
- && jsonOb.has(NAMESPACE) && jsonOb.has("whitelistTopicName")
- && isAlphaNumeric(jsonOb.getString("whitelistTopicName").substring(jsonOb.getString("whitelistTopicName").lastIndexOf(".")+1,
+ if (jsonOb != null && jsonOb.length() == 3 && jsonOb.has("name")
+ && isAlphaNumeric(jsonOb.getString("name")) && jsonOb.has(NAMESPACE)
+ && jsonOb.has("whitelistTopicName")
+ && isAlphaNumeric(jsonOb.getString("whitelistTopicName").substring(
+ jsonOb.getString("whitelistTopicName").lastIndexOf(".") + 1,
jsonOb.getString("whitelistTopicName").length()))) {
String permission = AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop,
inStream = IOUtils.toInputStream(listAll.toString(), UTF_8);
} catch (IOException ioe) {
- ioe.printStackTrace();
LOGGER.error("IOException: ", ioe);
}
// call listAllMirrorMaker
for (int i = 0; i < jsonArray.length(); i++) {
jsonObj = jsonArray.getJSONObject(i);
-
+
JSONObject obj = new JSONObject();
if (jsonObj.has(MESSAGE)) {
obj = jsonObj.getJSONObject(MESSAGE);
}
- if (obj.has("messageID") && obj.get("messageID").equals(randomStr) && obj.has(LISTMIRRORMAKER)) {
+ if (obj.has("messageID") && obj.get("messageID").equals(randomStr)
+ && obj.has(LISTMIRRORMAKER)) {
listMirrorMaker = obj.getJSONArray(LISTMIRRORMAKER);
break;
}
sendErrResponse(ctx, "The topic does not exist.");
}
-
if (removeTopic) {
UpdateWhiteList updateWhiteList = new UpdateWhiteList();
MirrorMaker mirrorMaker = new MirrorMaker();
-
+
mirrorMaker.setName(jsonOb.getString("name"));
mirrorMaker.setWhitelist(removeTopic(whitelist, topicToRemove));
-
+
String newRandom = getRandomNum();
-
+
updateWhiteList.setMessageID(newRandom);
updateWhiteList.setUpdateWhiteList(mirrorMaker);
-
+
Gson g = new Gson();
g.toJson(updateWhiteList);
-
+
InputStream inputStream;
inputStream = IOUtils.toInputStream(g.toJson(updateWhiteList), UTF_8);
callPubSubForWhitelist(newRandom, ctx, inputStream, getNamespace(topicToRemove));
}
if (topicList.contains(topicToRemove)) {
- for (String topic: topicList) {
+ for (String topic : topicList) {
if (!topic.equals(topicToRemove)) {
newTopicList.add(topic);
}
}
private void callPubSubForWhitelist(String randomStr, DMaaPContext ctx, InputStream inStream, String namespace) {
-
+
try {
mirrorService.pushEvents(ctx, topic, inStream, null, null);
long startTime = System.currentTimeMillis();
for (int i = 0; i < jsonArray.length(); i++) {
jsonObj = jsonArray.getJSONObject(i);
-
+
JSONObject obj = new JSONObject();
if (jsonObj.has(MESSAGE)) {
obj = jsonObj.getJSONObject(MESSAGE);
return whitelist;
}
-
+
private JSONArray getListMirrorMaker(String msgFrmSubscribe, String randomStr) {
JSONObject jsonObj;
JSONArray jsonArray;
JSONArray listMirrorMaker = new JSONArray();
-
+
msgFrmSubscribe = removeExtraChar(msgFrmSubscribe);
jsonArray = new JSONArray(msgFrmSubscribe);
for (int i = 0; i < jsonArray.length(); i++) {
jsonObj = jsonArray.getJSONObject(i);
-
+
JSONObject obj = new JSONObject();
if (jsonObj.has(MESSAGE)) {
obj = jsonObj.getJSONObject(MESSAGE);
break;
}
}
- return listMirrorMaker;
+ return listMirrorMaker;
}
}