* ============LICENSE_START=======================================================
* ONAP Policy Engine
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
* Modified Copyright (C) 2018 Samsung Electronics Co., Ltd.
* Modifications Copyright (C) 2019 Bell Canada
* ================================================================================
import org.onap.policy.utils.UserUtils.Pair;
import org.onap.policy.xacml.api.XACMLErrorConstants;
import org.onap.policy.xacml.util.XACMLPolicyScanner;
+import org.onap.portalsdk.core.domain.User;
import org.onap.portalsdk.core.web.support.UserUtils;
@WebServlet(
LOGGER.debug("doPost");
try {
// if request contains multipart-form-data
- if (ServletFileUpload.isMultipartContent(request)) {
+ if (isMultipartContent(request)) {
uploadFile(request, response);
}
// all other post request has json params in body
}
}
+ protected boolean isMultipartContent(HttpServletRequest request) {
+ return ServletFileUpload.isMultipartContent(request);
+ }
+
// Set Error Message for Exception
private void setError(Exception exception, HttpServletResponse response) throws IOException {
try {
private void processFormFile(HttpServletRequest request, FileItem item) {
String newFile;
- if (item.getName().endsWith(".xls") && item.getSize() <= PolicyController.getFileSizeLimit()) {
+ if (item.getName().endsWith(".xls") && item.getSize() <= getFileSizeLimit()) {
File file = new File(item.getName());
try (OutputStream outputStream = new FileOutputStream(file)) {
- IOUtils.copy(item.getInputStream(), outputStream);
+ copyStream(item.getInputStream(), outputStream);
newFile = file.toString();
PolicyExportAndImportController importController = new PolicyExportAndImportController();
importController.importRepositoryFile(newFile, request);
}
}
+ protected long copyStream(InputStream inputStream, OutputStream outputStream) throws IOException {
+ return IOUtils.copy(inputStream, outputStream);
+ }
+
+ protected long getFileSizeLimit() {
+ return PolicyController.getFileSizeLimit();
+ }
+
// File Operation Functionality
private void fileOperation(HttpServletRequest request, HttpServletResponse response) throws ServletException {
JSONObject responseJsonObject;
JSONObject params = jsonObject.getJSONObject("params");
Mode mode = Mode.valueOf(params.getString("mode"));
- String userId = UserUtils.getUserSession(request).getOrgUserId();
+ String userId = getUserSession(request).getOrgUserId();
LOGGER.info(
"********************Logging UserID while doing actions on Editor tab****************************");
LOGGER.info(
setResponse(response, responseJsonObject);
}
+ protected User getUserSession(HttpServletRequest request) {
+ return UserUtils.getUserSession(request);
+ }
+
private void setResponse(HttpServletResponse response, JSONObject responseJsonObject) {
response.setContentType(CONTENTTYPE);
try (PrintWriter out = response.getWriter()) {
private boolean lookupPolicyData(HttpServletRequest request, List<Object> policyData, JSONArray policyList,
PolicyController controller, List<JSONObject> resultList) {
- String userId = UserUtils.getUserSession(request).getOrgUserId();
+ String userId = getUserSession(request).getOrgUserId();
List<Object> userRoles = controller.getRoles(userId);
- Pair<Set<String>, List<String>> pair = org.onap.policy.utils.UserUtils.checkRoleAndScope(userRoles);
+ Pair<Set<String>, List<String>> pair = checkRoleAndScope(userRoles);
List<String> roles = pair.second;
Set<String> scopes = pair.first;
if (roles.contains(ADMIN) || roles.contains(EDITOR) || roles.contains(GUEST)) {
return true;
}
+ protected Pair<Set<String>, List<String>> checkRoleAndScope(List<Object> userRoles) {
+ return org.onap.policy.utils.UserUtils.checkRoleAndScope(userRoles);
+ }
+
private void getPolicyDataForSuperRoles(List<Object> policyData, PolicyController controller,
List<JSONObject> resultList, List<String> roles, Set<String> scopes) {
if (roles.contains(SUPERADMIN) || roles.contains(SUPEREDITOR) || roles.contains(SUPERGUEST)) {
String path = params.getString("path");
String userId = null;
try {
- userId = UserUtils.getUserSession(request).getOrgUserId();
+ userId = getUserSession(request).getOrgUserId();
} catch (Exception e) {
LOGGER.error("Exception Occured while reading userid from cookie" + e);
}
private JSONObject processPolicyList(JSONObject params, HttpServletRequest request) throws ServletException {
// Get the Login Id of the User from Request
String testUserID = getTestUserId();
- String userId = testUserID != null ? testUserID : UserUtils.getUserSession(request).getOrgUserId();
+ String userId = testUserID != null ? testUserID : getUserSession(request).getOrgUserId();
List<Object> userRoles = getPolicyControllerInstance().getRoles(userId);
- Pair<Set<String>, List<String>> pair = org.onap.policy.utils.UserUtils.checkRoleAndScope(userRoles);
+ Pair<Set<String>, List<String>> pair = checkRoleAndScope(userRoles);
List<String> roles = pair.second;
Set<String> scopes = pair.first;
Map<String, String> roleByScope = org.onap.policy.utils.UserUtils.getRoleByScope(userRoles);
boolean isActive = false;
List<String> policyActiveInPdp = new ArrayList<>();
Set<String> scopeOfPolicyActiveInPdp = new HashSet<>();
- String userId = UserUtils.getUserSession(request).getOrgUserId();
+ String userId = getUserSession(request).getOrgUserId();
String oldPath = params.getString("path");
String newPath = params.getString("newPath");
oldPath = oldPath.substring(oldPath.indexOf('/') + 1);
// Clone the Policy
private JSONObject copy(JSONObject params, HttpServletRequest request) throws ServletException {
try {
- String userId = UserUtils.getUserSession(request).getOrgUserId();
+ String userId = getUserSession(request).getOrgUserId();
String oldPath = params.getString("path");
String newPath = params.getString("newPath");
oldPath = oldPath.substring(oldPath.indexOf('/') + 1);
PolicyEntity policyEntity = null;
String policyNamewithoutExtension;
try {
- String userId = UserUtils.getUserSession(request).getOrgUserId();
+ String userId = getUserSession(request).getOrgUserId();
String deleteVersion = "";
String path = params.getString("path");
LOGGER.debug("delete {}" + path);
if (entity != null) {
return error("Scope Already Exists");
}
- String userId = UserUtils.getUserSession(request).getOrgUserId();
+ String userId = getUserSession(request).getOrgUserId();
UserInfo userInfo = new UserInfo();
userInfo.setUserLoginId(userId);
PolicyEditorScopes newScope = new PolicyEditorScopes();