summaryrefslogtreecommitdiffstats
path: root/portal-BE/src/main/java/org
diff options
context:
space:
mode:
authorSunder Tattavarada <statta@research.att.com>2020-03-18 01:51:24 +0000
committerGerrit Code Review <gerrit@onap.org>2020-03-18 01:51:24 +0000
commit7ada1331fd2438a8d6712a46877d0c6209d88d2b (patch)
treed08e1c6818fdd74a306592469000f74e06be512c /portal-BE/src/main/java/org
parent99fe490df64c83cdbe0f0c13ea7a33d436af38c4 (diff)
parent457d999e8272aab60177ae2acfddb41cce1062dd (diff)
Merge "RolesApprovalSystemController up"
Diffstat (limited to 'portal-BE/src/main/java/org')
-rw-r--r--portal-BE/src/main/java/org/onap/portal/controller/RolesApprovalSystemController.java207
-rw-r--r--portal-BE/src/main/java/org/onap/portal/controller/RolesApprovalSystemVersionController.java78
-rw-r--r--portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpUserRolesRequest.java72
-rw-r--r--portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpUserRolesRequestDet.java44
-rw-r--r--portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnApp.java7
-rw-r--r--portal-BE/src/main/java/org/onap/portal/domain/dto/model/ExternalSystemRoleApproval.java56
-rw-r--r--portal-BE/src/main/java/org/onap/portal/domain/dto/model/ExternalSystemUser.java64
-rw-r--r--portal-BE/src/main/java/org/onap/portal/service/AdminRolesService.java350
-rw-r--r--portal-BE/src/main/java/org/onap/portal/service/ExternalAccessRolesService.java3
-rw-r--r--portal-BE/src/main/java/org/onap/portal/service/app/FnAppDao.java11
-rw-r--r--portal-BE/src/main/java/org/onap/portal/service/app/FnAppService.java9
-rw-r--r--portal-BE/src/main/java/org/onap/portal/service/userRolesRequestDet/EpUserRolesRequestDetService.java23
12 files changed, 795 insertions, 129 deletions
diff --git a/portal-BE/src/main/java/org/onap/portal/controller/RolesApprovalSystemController.java b/portal-BE/src/main/java/org/onap/portal/controller/RolesApprovalSystemController.java
new file mode 100644
index 00000000..53bf7e11
--- /dev/null
+++ b/portal-BE/src/main/java/org/onap/portal/controller/RolesApprovalSystemController.java
@@ -0,0 +1,207 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+
+package org.onap.portal.controller;
+
+import io.swagger.annotations.ApiOperation;
+import java.util.ArrayList;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.onap.portal.domain.dto.PortalRestResponse;
+import org.onap.portal.domain.dto.PortalRestStatusEnum;
+import org.onap.portal.domain.dto.model.ExternalSystemRoleApproval;
+import org.onap.portal.domain.dto.model.ExternalSystemUser;
+import org.onap.portal.domain.dto.transport.ExternalRequestFieldsValidator;
+import org.onap.portal.service.AdminRolesService;
+import org.onap.portal.service.ExternalAccessRolesService;
+import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/auxapi")
+@Configuration
+@EnableAspectJAutoProxy
+public class RolesApprovalSystemController {
+
+ private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RolesApprovalSystemController.class);
+
+ @Autowired
+ private AdminRolesService userRolesService;
+
+ @ApiOperation(value = "Creates an application user with the specified roles.", response = PortalRestResponse.class)
+ @RequestMapping(value = {"/userProfile"}, method = RequestMethod.POST, produces = "application/json")
+ public PortalRestResponse<String> postUserProfile(HttpServletRequest request,
+ @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) {
+ ExternalRequestFieldsValidator reqResult = null;
+ try {
+ logger.info(EELFLoggerDelegate.debugLogger, "postUserProfile: request received for app {}, user {}",
+ extSysUser.getApplicationName(), extSysUser.getLoginId());
+
+ validateExtSystemUser(extSysUser, true);
+ reqResult = userRolesService.setExternalRequestUserAppRole(extSysUser, "POST");
+ if (!reqResult.isResult()) {
+ throw new Exception(reqResult.getDetailMessage());
+ }
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "postUserProfile: failed for app {}, user {}",
+ extSysUser.getApplicationName(), extSysUser.getLoginId(), e);
+ if (reqResult == null || (!reqResult.isResult() && !e.getMessage().contains("404") && !e.getMessage()
+ .contains("405"))) {
+ response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
+ return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR,
+ e.getMessage(), "save user profile failed");
+ } else if (e.getMessage().contains("404")) {
+ response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+ return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR,
+ e.getMessage(), "save user profile failed");
+ } else if (e.getMessage().contains("500")) {
+ response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR,
+ e.getMessage(), "save user profile failed");
+ } else if (e.getMessage().contains("405")) {
+ response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
+ return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(),
+ "save user profile failed");
+ } else {
+ response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(),
+ "save user profile failed");
+ }
+ }
+ return new PortalRestResponse<String>(PortalRestStatusEnum.OK, reqResult.getDetailMessage(), "Success");
+ }
+
+ @ApiOperation(value = "Updates an application user to have only the specified roles.", response = PortalRestResponse.class)
+ @RequestMapping(value = {"/userProfile"}, method = RequestMethod.PUT, produces = "application/json")
+ public PortalRestResponse<String> putUserProfile(HttpServletRequest request,
+ @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) {
+ ExternalRequestFieldsValidator reqResult = null;
+ try {
+ logger.info(EELFLoggerDelegate.debugLogger, "putUserProfile: request received for app {}, user {}",
+ extSysUser.getApplicationName(), extSysUser.getLoginId());
+ validateExtSystemUser(extSysUser, true);
+ reqResult = userRolesService.setExternalRequestUserAppRole(extSysUser, "PUT");
+ if (!reqResult.isResult()) {
+ throw new Exception(reqResult.getDetailMessage());
+ }
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "putUserProfile: failed for app {}, user {}",
+ extSysUser.getApplicationName(), extSysUser.getLoginId(), e);
+ if (reqResult == null || (!reqResult.isResult() && !e.getMessage().contains("404") && !e.getMessage()
+ .contains("405"))) {
+ response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
+ return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR,
+ e.getMessage(), "save user profile failed");
+ } else if (e.getMessage().contains("404")) {
+ response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+ return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR,
+ e.getMessage(), "save user profile failed");
+ } else if (e.getMessage().contains("500")) {
+ response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR,
+ e.getMessage(), "save user profile failed");
+ } else if (e.getMessage().contains("405")) {
+ response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
+ return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(),
+ "save user profile failed");
+ } else {
+ response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR,
+ e.getMessage(), "save user profile failed");
+ }
+ }
+ return new PortalRestResponse<String>(PortalRestStatusEnum.OK, reqResult.getDetailMessage(), "Success");
+ }
+
+ @ApiOperation(value = "Processes a request to delete one or more application roles for one specified user who has roles.", response = PortalRestResponse.class)
+ @RequestMapping(value = {"/userProfile"}, method = RequestMethod.DELETE, produces = "application/json")
+ public PortalRestResponse<String> deleteUserProfile(HttpServletRequest request,
+ @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) {
+ ExternalRequestFieldsValidator reqResult = null;
+ try {
+ logger.info(EELFLoggerDelegate.debugLogger, "deleteUserProfile: request received for app {}, user {}",
+ extSysUser.getApplicationName(), extSysUser.getLoginId());
+ validateExtSystemUser(extSysUser, false);
+ // Ignore any roles that might be mistakenly present in the request
+ extSysUser.setRoles(new ArrayList<ExternalSystemRoleApproval>());
+ reqResult = userRolesService.setExternalRequestUserAppRole(extSysUser, "DELETE");
+ if (!reqResult.isResult()) {
+ throw new Exception(reqResult.getDetailMessage());
+ }
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "deleteUserProfile: failed for app {}, user {}",
+ extSysUser.getApplicationName(), extSysUser.getLoginId(), e);
+ if (reqResult == null || (!reqResult.isResult() && !e.getMessage().contains("404"))) {
+ response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
+ return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR,
+ e.getMessage(), "delete user profile failed");
+ } else if (e.getMessage().contains("404")) {
+ response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+ return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR,
+ e.getMessage(), "delete user profile failed");
+ } else {
+ response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR,
+ e.getMessage(), "delete user profile failed");
+ }
+ }
+ return new PortalRestResponse<String>(PortalRestStatusEnum.OK, "Deleted Successfully", "Success");
+ }
+
+ private void validateExtSystemUser(ExternalSystemUser extSysUser, boolean rolesRequired) throws Exception {
+ if (extSysUser.getLoginId() == null || extSysUser.getLoginId() == "") {
+ throw new Exception("Request has no login ID");
+ }
+ if (extSysUser.getApplicationName() == null || extSysUser.getApplicationName() == "") {
+ throw new Exception("Request has no application name");
+ }
+ if (extSysUser.getMyloginrequestId() == null) {
+ throw new Exception("Request has no request ID");
+ }
+ if (rolesRequired && (extSysUser.getRoles() == null || extSysUser.getRoles().size() == 0)) {
+ throw new Exception("Request has no roles");
+ }
+ }
+
+}
diff --git a/portal-BE/src/main/java/org/onap/portal/controller/RolesApprovalSystemVersionController.java b/portal-BE/src/main/java/org/onap/portal/controller/RolesApprovalSystemVersionController.java
new file mode 100644
index 00000000..79311886
--- /dev/null
+++ b/portal-BE/src/main/java/org/onap/portal/controller/RolesApprovalSystemVersionController.java
@@ -0,0 +1,78 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ */
+package org.onap.portal.controller;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.onap.portal.annotation.ApiVersion;
+import org.onap.portal.domain.dto.PortalRestResponse;
+import org.onap.portal.domain.dto.model.ExternalSystemUser;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
+
+@Configuration
+@EnableAspectJAutoProxy
+@ApiVersion
+public class RolesApprovalSystemVersionController {
+
+ private final RolesApprovalSystemController rolesApprovalSystemController;
+
+ @Autowired
+ public RolesApprovalSystemVersionController(
+ RolesApprovalSystemController rolesApprovalSystemController) {
+ this.rolesApprovalSystemController = rolesApprovalSystemController;
+ }
+
+ @ApiVersion(max = "v3", service = "/v3/userProfile", min = 0, method = "POST")
+ public PortalRestResponse<String> postUserProfile(HttpServletRequest request,
+ HttpServletResponse response, ExternalSystemUser extSysUser) {
+ return rolesApprovalSystemController.postUserProfile(request, extSysUser, response);
+ }
+
+ @ApiVersion(max = "v3", service = "/v3/userProfile", min = 0, method = "PUT")
+ public PortalRestResponse<String> putUserProfile(HttpServletRequest request,
+ HttpServletResponse response, ExternalSystemUser extSysUser) {
+ return rolesApprovalSystemController.putUserProfile(request, extSysUser, response);
+ }
+
+ @ApiVersion(max = "v3", service = "/v3/userProfile", min = 0, method = "DELETE")
+ public PortalRestResponse<String> deleteUserProfile(HttpServletRequest request,
+ HttpServletResponse response, ExternalSystemUser extSysUser) {
+ return rolesApprovalSystemController.deleteUserProfile(request, extSysUser, response);
+ }
+}
diff --git a/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpUserRolesRequest.java b/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpUserRolesRequest.java
index 113863c3..7828c134 100644
--- a/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpUserRolesRequest.java
+++ b/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpUserRolesRequest.java
@@ -100,42 +100,42 @@ CREATE TABLE `ep_user_roles_request` (
@Setter
@Entity
public class EpUserRolesRequest implements Serializable {
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO)
- @Column(name = "req_id", length = 11, nullable = false, columnDefinition = "int(11) AUTO_INCREMENT")
- @Digits(integer = 11, fraction = 0)
- private Long reqId;
- @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
- @JoinColumn(name = "user_id", nullable = false, columnDefinition = "bigint")
- @NotNull
- @Valid
- private FnUser userId;
- @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
- @JoinColumn(name = "app_id", nullable = false, columnDefinition = "bigint")
- @NotNull
- @Valid
- private FnApp appId;
- @Column(name = "created_date", nullable = false, columnDefinition = "datetime default now()")
- @PastOrPresent
- private LocalDateTime createdDate;
- @Column(name = "updated_date", nullable = false, columnDefinition = "datetime default now()")
- @PastOrPresent
- private LocalDateTime updatedDate;
- @Column(name = "request_status", nullable = false, length = 50)
- @Size(max = 50)
- @NotNull
- @SafeHtml
- private String requestStatus;
- @OneToMany(
- targetEntity = EpUserRolesRequestDet.class,
- mappedBy = "reqId",
- cascade = CascadeType.MERGE,
- fetch = FetchType.LAZY
- )
- private Set<EpUserRolesRequestDet> epUserRolesRequestDets;
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ @Column(name = "req_id", length = 11, nullable = false, columnDefinition = "int(11) AUTO_INCREMENT")
+ @Digits(integer = 11, fraction = 0)
+ private Long reqId;
+ @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
+ @JoinColumn(name = "user_id", nullable = false, columnDefinition = "bigint")
+ @NotNull
+ @Valid
+ private FnUser userId;
+ @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
+ @JoinColumn(name = "app_id", nullable = false, columnDefinition = "bigint")
+ @NotNull
+ @Valid
+ private FnApp appId;
+ @Column(name = "created_date", nullable = false, columnDefinition = "datetime default now()")
+ @PastOrPresent
+ private LocalDateTime createdDate;
+ @Column(name = "updated_date", nullable = false, columnDefinition = "datetime default now()")
+ @PastOrPresent
+ private LocalDateTime updatedDate;
+ @Column(name = "request_status", nullable = false, length = 50)
+ @Size(max = 50)
+ @NotNull
+ @SafeHtml
+ private String requestStatus;
+ @OneToMany(
+ targetEntity = EpUserRolesRequestDet.class,
+ mappedBy = "reqId",
+ cascade = CascadeType.MERGE,
+ fetch = FetchType.LAZY
+ )
+ private Set<EpUserRolesRequestDet> epUserRolesRequestDets;
- public void setEpRequestIdDetail(Set<EpUserRolesRequestDet> epMyLoginsDetail) {
- this.epUserRolesRequestDets = epMyLoginsDetail;
- }
+ public void setEpRequestIdDetail(Set<EpUserRolesRequestDet> epMyLoginsDetail) {
+ this.epUserRolesRequestDets = epMyLoginsDetail;
+ }
}
diff --git a/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpUserRolesRequestDet.java b/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpUserRolesRequestDet.java
index 4d2fcaea..1af088e5 100644
--- a/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpUserRolesRequestDet.java
+++ b/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpUserRolesRequestDet.java
@@ -89,8 +89,8 @@ CREATE TABLE `ep_user_roles_request_det` (
})
@Table(name = "ep_user_roles_request_det", indexes = {
- @Index(name = "fk_user_roles_req_fn_req_id", columnList = "req_id"),
- @Index(name = "fk_user_roles_req_fn_role_id", columnList = "requested_role_id")
+ @Index(name = "fk_user_roles_req_fn_req_id", columnList = "req_id"),
+ @Index(name = "fk_user_roles_req_fn_role_id", columnList = "requested_role_id")
})
@NoArgsConstructor
@AllArgsConstructor
@@ -99,25 +99,25 @@ CREATE TABLE `ep_user_roles_request_det` (
@Entity
public class EpUserRolesRequestDet implements Serializable {
- @Id
-
- @GeneratedValue(strategy = GenerationType.AUTO)
- @Column(name = "id", length = 11, nullable = false, columnDefinition = "int(11) AUTO_INCREMENT")
- @Digits(integer = 11, fraction = 0)
- private Long id;
- @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
- @JoinColumn(name = "req_id", columnDefinition = "int(11) default null")
- @Valid
- private EpUserRolesRequest reqId;
- @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
- @JoinColumn(name = "requested_role_id", nullable = false, columnDefinition = "bigint")
- @NotNull
- @Valid
- private FnRole requestedRoleId;
- @Column(name = "request_type", length = 10, nullable = false)
- @Size(max = 10)
- @NotNull
- @SafeHtml
- private String requestType;
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ @Column(name = "id", length = 11, nullable = false, columnDefinition = "int(11) AUTO_INCREMENT")
+ @Digits(integer = 11, fraction = 0)
+ private Long id;
+ //TODO One to many
+ @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
+ @JoinColumn(name = "req_id", columnDefinition = "int(11) default null")
+ @Valid
+ private EpUserRolesRequest reqId;
+ @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
+ @JoinColumn(name = "requested_role_id", nullable = false, columnDefinition = "bigint")
+ @NotNull
+ @Valid
+ private FnRole requestedRoleId;
+ @Column(name = "request_type", length = 10, nullable = false)
+ @Size(max = 10)
+ @NotNull
+ @SafeHtml
+ private String requestType;
}
diff --git a/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnApp.java b/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnApp.java
index 307abebd..beb5bd55 100644
--- a/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnApp.java
+++ b/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnApp.java
@@ -108,10 +108,15 @@ CREATE TABLE `fn_app` (
query = "from FnApp where uebKey = :uebKey"),
@NamedQuery(
name = "FnApp.getCentralizedApps",
- query = "from FnApp where authCentral = 'Y' and open = 'N' and authNamespace is not null"
+ query = "from FnApp where authCentral = 'Y' and open = 'N' and authNamespace is not null"),
+ @NamedQuery(
+ name = "FnApp.retrieveWhereAppName",
+ query = "FROM FnApp WHERE appName = :appName"
)
})
+//TODO appName as unique index?
+
@Table(name = "fn_app")
@NoArgsConstructor
@AllArgsConstructor
diff --git a/portal-BE/src/main/java/org/onap/portal/domain/dto/model/ExternalSystemRoleApproval.java b/portal-BE/src/main/java/org/onap/portal/domain/dto/model/ExternalSystemRoleApproval.java
new file mode 100644
index 00000000..7b13b1c6
--- /dev/null
+++ b/portal-BE/src/main/java/org/onap/portal/domain/dto/model/ExternalSystemRoleApproval.java
@@ -0,0 +1,56 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+package org.onap.portal.domain.dto.model;
+
+import java.io.Serializable;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import org.hibernate.validator.constraints.SafeHtml;
+
+@Getter
+@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+public class ExternalSystemRoleApproval implements Serializable {
+
+ @SafeHtml
+ private String roleName;
+
+}
diff --git a/portal-BE/src/main/java/org/onap/portal/domain/dto/model/ExternalSystemUser.java b/portal-BE/src/main/java/org/onap/portal/domain/dto/model/ExternalSystemUser.java
new file mode 100644
index 00000000..95b440a0
--- /dev/null
+++ b/portal-BE/src/main/java/org/onap/portal/domain/dto/model/ExternalSystemUser.java
@@ -0,0 +1,64 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+package org.onap.portal.domain.dto.model;
+
+
+import java.util.List;
+import javax.validation.Valid;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import org.hibernate.validator.constraints.SafeHtml;
+
+@Getter
+@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+public class ExternalSystemUser {
+
+ @SafeHtml
+ private String loginId;
+ @SafeHtml
+ private String applicationName;
+ @SafeHtml
+ private String myloginrequestId;
+ @Valid
+ private List<ExternalSystemRoleApproval> roles;
+
+}
diff --git a/portal-BE/src/main/java/org/onap/portal/service/AdminRolesService.java b/portal-BE/src/main/java/org/onap/portal/service/AdminRolesService.java
index f8ef4a99..3ee30827 100644
--- a/portal-BE/src/main/java/org/onap/portal/service/AdminRolesService.java
+++ b/portal-BE/src/main/java/org/onap/portal/service/AdminRolesService.java
@@ -78,7 +78,9 @@ import org.onap.portal.domain.db.fn.FnRole;
import org.onap.portal.domain.db.fn.FnRoleFunction;
import org.onap.portal.domain.db.fn.FnUser;
import org.onap.portal.domain.db.fn.FnUserRole;
-import org.onap.portal.domain.dto.ecomp.EPUserApp;
+import org.onap.portal.domain.dto.ecomp.EPUserAppRolesRequest;
+import org.onap.portal.domain.dto.model.ExternalSystemRoleApproval;
+import org.onap.portal.domain.dto.model.ExternalSystemUser;
import org.onap.portal.domain.dto.transport.AppNameIdIsAdmin;
import org.onap.portal.domain.dto.transport.AppWithRolesForUser;
import org.onap.portal.domain.dto.transport.AppsListWithAdminRole;
@@ -98,16 +100,16 @@ import org.onap.portal.exception.RoleFunctionException;
import org.onap.portal.exception.SyncUserRolesException;
import org.onap.portal.logging.format.EPAppMessagesEnum;
import org.onap.portal.logging.logic.EPLogUtil;
-import org.onap.portal.service.appFunction.EpAppFunctionService;
-import org.onap.portal.service.roleFunction.FnRoleFunctionService;
-import org.onap.portal.service.userRolesRequestDet.EpUserRolesRequestDetService;
-import org.onap.portal.service.userRolesRequest.EpUserRolesRequestService;
import org.onap.portal.service.app.FnAppService;
-import org.onap.portal.service.menuFunctionalRoles.FnMenuFunctionalRolesService;
+import org.onap.portal.service.appFunction.EpAppFunctionService;
import org.onap.portal.service.menuFunctional.FnMenuFunctionalService;
+import org.onap.portal.service.menuFunctionalRoles.FnMenuFunctionalRolesService;
import org.onap.portal.service.role.FnRoleService;
-import org.onap.portal.service.userRole.FnUserRoleService;
+import org.onap.portal.service.roleFunction.FnRoleFunctionService;
import org.onap.portal.service.user.FnUserService;
+import org.onap.portal.service.userRole.FnUserRoleService;
+import org.onap.portal.service.userRolesRequest.EpUserRolesRequestService;
+import org.onap.portal.service.userRolesRequestDet.EpUserRolesRequestDetService;
import org.onap.portal.utils.EPCommonSystemProperties;
import org.onap.portal.utils.EPUserUtils;
import org.onap.portal.utils.EcompPortalUtils;
@@ -546,7 +548,7 @@ public class AdminRolesService {
FnRole appRole = getAppRoles.stream()
.filter(applicationRole -> epRole.getId().equals(applicationRole.getId())).findAny().orElse(null);
List<FnRoleFunction> fnRoleFunctions = new ArrayList<>();
- for (DomainVo vo: epRole.getRoleFunctions()){
+ for (DomainVo vo : epRole.getRoleFunctions()) {
Optional<FnRoleFunction> roleFunction = fnRoleFunctionService.findById(vo.getId());
roleFunction.ifPresent(fnRoleFunctions::add);
}
@@ -688,23 +690,6 @@ public class AdminRolesService {
}
}
- private Set<EcompRole> postUsersRolesToLocalApp(List<RoleInAppForUser> roleInAppForUserList) {
- return constructUsersEcompRoles(roleInAppForUserList);
- }
-
- private Set<EcompRole> constructUsersEcompRoles(List<RoleInAppForUser> roleInAppForUserList) {
- Set<EcompRole> existingUserRoles = new TreeSet<>();
- for (RoleInAppForUser roleInAppForUser : roleInAppForUserList) {
- if (roleInAppForUser.getIsApplied()) {
- EcompRole ecompRole = new EcompRole();
- ecompRole.setId(roleInAppForUser.getRoleId());
- ecompRole.setName(roleInAppForUser.getRoleName());
- existingUserRoles.add(ecompRole);
- }
- }
- return existingUserRoles;
- }
-
public RolesInAppForUser constructRolesInAppForUserUpdate(String userId, Long appId,
Set<EcompRole> userRolesInRemoteApp) {
RolesInAppForUser result;
@@ -1935,45 +1920,302 @@ public class AdminRolesService {
}
public AppsListWithAdminRole getAppsWithAdminRoleStateForUser(String orgUserId) {
- AppsListWithAdminRole appsListWithAdminRole = null;
+ AppsListWithAdminRole appsListWithAdminRole = null;
+ try {
+ List<FnUser> userList = fnUserService.getUserWithOrgUserId(orgUserId);
+ HashMap<Long, Long> appsUserAdmin = new HashMap<>();
+ if (userList != null && userList.size() > 0) {
+ FnUser user = userList.get(0);
+ List<FnUserRole> userAppList = new ArrayList<>();
+ try {
+ userAppList = fnUserRoleService.retrieveByUserIdAndRoleId(user.getId(), ACCOUNT_ADMIN_ROLE_ID);
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "getAppsWithAdminRoleStateForUser 1 failed", e);
+ EPLogUtil.logEcompError(EPAppMessagesEnum.BeDaoSystemError);
+ }
+ for (FnUserRole userApp : userAppList) {
+ appsUserAdmin.put(userApp.getFnAppId().getId(), userApp.getUserId().getId());
+ }
+ }
+
+ appsListWithAdminRole = new AppsListWithAdminRole();
+ appsListWithAdminRole.setOrgUserId(orgUserId);
+ List<FnApp> appsList = new ArrayList<>();
+ try {
+ appsList = fnAppService.findAll();
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "getAppsWithAdminRoleStateForUser 2 failed", e);
+ EPLogUtil.logEcompError(EPAppMessagesEnum.BeDaoSystemError);
+ }
+ for (FnApp app : appsList) {
+ AppNameIdIsAdmin appNameIdIsAdmin = new AppNameIdIsAdmin();
+ appNameIdIsAdmin.setId(app.getId());
+ appNameIdIsAdmin.setAppName(app.getAppName());
+ appNameIdIsAdmin.setIsAdmin(appsUserAdmin.containsKey(app.getId()));
+ appNameIdIsAdmin.setRestrictedApp(app.isRestrictedApp());
+ appsListWithAdminRole.getAppsRoles().add(appNameIdIsAdmin);
+ }
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "getAppsWithAdminRoleStateForUser 3 failed", e);
+ }
+ return appsListWithAdminRole;
+ }
+
+ public ExternalRequestFieldsValidator setExternalRequestUserAppRole(ExternalSystemUser newAppRolesForUser,
+ String reqType) {
+ boolean result = false;
+ boolean externalSystemRequest = true;
+ List<FnUser> userInfo = null;
+ FnUser user = null;
+ List<EpUserRolesRequest> epRequestId = null;
+ String orgUserId = "";
+ String updateStatus = "";
+ String reqMessage = "";
+ FnApp app = null;
+ if (newAppRolesForUser != null && newAppRolesForUser.getLoginId() != null) {
+ orgUserId = newAppRolesForUser.getLoginId().trim();
+ }
+ String appName = newAppRolesForUser.getApplicationName();
+ String logMessage = ("DELETE").equals(reqType) ? "Deleting" : "Assigning/Updating";
+ if (orgUserId.length() > 0) {
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ int epRequestIdSize = 0;
try {
- List<FnUser> userList = fnUserService.getUserWithOrgUserId(orgUserId);
- HashMap<Long, Long> appsUserAdmin = new HashMap<>();
- if (userList!= null && userList.size() > 0) {
- FnUser user = userList.get(0);
- List<FnUserRole> userAppList = new ArrayList<>();
+ app = fnAppService.getAppDetail(appName);
+ userInfo = checkIfUserExists(orgUserId);
+ reqMessage = "Updated Successfully";
+ if (!reqType.equals("DELETE") && (userInfo.isEmpty())) {
+ reqMessage = validateNewUser(orgUserId, app);
+ }
+ if (!userInfo.isEmpty()) {
+ validateExternalRequestFields(app);
+ user = userInfo.get(0);
+ epRequestId = epUserRolesRequestService.userAppRolesRequestList(user.getId(), app.getId());
+ epRequestIdSize = epRequestId.size();
+ }
+ if (!app.getId().equals(PortalConstants.PORTAL_APP_ID) && !app.getAuthCentral()) {
+ logger.debug(EELFLoggerDelegate.debugLogger,
+ "setExternalRequestUserAppRole: Starting GET roles for app {}", app.getId());
+ EcompRole[] appRoles = applicationsRestClientService.get(EcompRole[].class, app.getId(), "/roles");
+ logger.debug(EELFLoggerDelegate.debugLogger,
+ "setExternalRequestUserAppRole: Finshed GET roles for app {} and payload {}", app.getId(),
+ appRoles);
+ if (appRoles.length > 0) {
+ syncAppRoles(app.getId(), appRoles);
+ }
+ }
+ List<RoleInAppForUser> roleInAppForUserList = roleInAppForUserList(newAppRolesForUser.getRoles(),
+ app.getId(), app.getMlAppName());
+ List<EcompUserAppRoles> userRoleList = null;
+ if (!userInfo.isEmpty()) {
+ userRoleList = ecompUserAppRolesService.getUserAppExistingRoles(app.getId(), user.getId());
+ }
+ // Check if list contains just account admin role
+ boolean checkIfAdminRoleExists = false;
+ if (reqType.equals("DELETE") && userRoleList != null) {
+ checkIfAdminRoleExists = userRoleList.stream()
+ .anyMatch(userRole -> userRole.getRoleId().equals(PortalConstants.ACCOUNT_ADMIN_ROLE_ID));
+ } else {
+ checkIfAdminRoleExists = roleInAppForUserList.stream()
+ .anyMatch(roleList -> roleList.getRoleId().equals(PortalConstants.ACCOUNT_ADMIN_ROLE_ID));
+ }
+ if (app.getAuthCentral()) {
try {
- userAppList = fnUserRoleService.retrieveByUserIdAndRoleId(user.getId(), ACCOUNT_ADMIN_ROLE_ID);
+ if (!(app.getId().equals(PortalConstants.PORTAL_APP_ID) && reqType.equals("DELETE"))
+ && ((checkIfAdminRoleExists && roleInAppForUserList.size() > 1)
+ || (!checkIfAdminRoleExists && roleInAppForUserList.size() >= 1))) {
+ List<RoleInAppForUser> remoteUserRoles = new ArrayList<>(roleInAppForUserList);
+ remoteUserRoles.removeIf(role -> {
+ return (role.getRoleId().equals(PortalConstants.ACCOUNT_ADMIN_ROLE_ID));
+ });
+ String orgUserIdNewOrExist = (!userInfo.isEmpty()) ? user.getOrgUserId() : orgUserId;
+ pushRemoteUser(remoteUserRoles, orgUserIdNewOrExist, app, mapper,
+ applicationsRestClientService, true);
+ }
} catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, "getAppsWithAdminRoleStateForUser 1 failed", e);
- EPLogUtil.logEcompError(EPAppMessagesEnum.BeDaoSystemError);
+ reqMessage = e.getMessage();
+ logger.error(EELFLoggerDelegate.errorLogger,
+ "setExternalRequestUserAppRole: Failed to added remote user", e);
+ throw new Exception(reqMessage);
+ }
+ Set<EcompRole> userRolesInLocalApp = postUsersRolesToLocalApp(roleInAppForUserList);
+ RolesInAppForUser rolesInAppForUser = constructRolesInAppForUserUpdate(orgUserId, app.getId(),
+ userRolesInLocalApp);
+ List<RoleInAppForUser> roleAppUserList = rolesInAppForUser.getRoles();
+ Set<EcompRole> rolesGotDeletedByApprover = new TreeSet<>();
+ if (EcompPortalUtils.checkIfRemoteCentralAccessAllowed()) {
+ updateUserRolesInExternalSystem(app, rolesInAppForUser.getOrgUserId(), roleAppUserList,
+ externalSystemRequest, false, rolesGotDeletedByApprover, false);
}
- for (FnUserRole userApp : userAppList) {
- appsUserAdmin.put(userApp.getFnAppId().getId(), userApp.getUserId().getId());
+ logger.info(EELFLoggerDelegate.debugLogger,
+ "setExternalRequestUserAppRole: {} user app roles: for app {}, user {}", logMessage,
+ newAppRolesForUser.getApplicationName(), newAppRolesForUser.getLoginId());
+ result = applyChangesInUserRolesForAppToEcompDB(rolesInAppForUser, externalSystemRequest, reqType,
+ false, rolesGotDeletedByApprover, false);
+ } else if (!app.getAuthCentral() && app.getId().equals(PortalConstants.PORTAL_APP_ID)) {
+ Set<EcompRole> userRolesInLocalApp = postUsersRolesToLocalApp(roleInAppForUserList);
+ RolesInAppForUser rolesInAppForUser = constructRolesInAppForUserUpdate(orgUserId, app.getId(),
+ userRolesInLocalApp);
+ Set<EcompRole> rolesGotDeletedByApprover = new TreeSet<>();
+
+ result = applyChangesInUserRolesForAppToEcompDB(rolesInAppForUser, externalSystemRequest, reqType,
+ false, rolesGotDeletedByApprover, false);
+ } else {
+ if (!((roleInAppForUserList.size() == 1 || reqType.equals("DELETE")) && checkIfAdminRoleExists)) {
+ FnUser remoteAppUser = null;
+ remoteAppUser = checkIfRemoteUserExits(orgUserId, app, applicationsRestClientService);
+ if (remoteAppUser == null) {
+ addRemoteUser(roleInAppForUserList, orgUserId, app, mapper,
+ applicationsRestClientService);
+ reqMessage = "Saved Successfully";
+ }
+ Set<EcompRole> userRolesInRemoteApp = postUsersRolesToRemoteApp(roleInAppForUserList, mapper,
+ applicationsRestClientService, app.getId(), orgUserId);
+ RolesInAppForUser rolesInAppForUser = constructRolesInAppForUserUpdate(orgUserId, app.getId(),
+ userRolesInRemoteApp);
+ logger.info(EELFLoggerDelegate.debugLogger,
+ "setExternalRequestUserAppRole: {} user app roles: for app {}, user {}", logMessage,
+ newAppRolesForUser.getApplicationName(), newAppRolesForUser.getLoginId());
+ Set<EcompRole> rolesGotDeletedByApprover = new TreeSet<>();
+ result = applyChangesInUserRolesForAppToEcompDB(rolesInAppForUser, externalSystemRequest,
+ reqType, false, rolesGotDeletedByApprover, false);
+ } else {
+ if (!(reqType.equals("DELETE")) && userInfo.isEmpty()) {
+ reqMessage = "Saved Successfully";
+ }
+ Set<EcompRole> userRolesInRemoteApp = constructUsersEcompRoles(roleInAppForUserList);
+ RolesInAppForUser rolesInAppForUser = constructRolesInAppForUserUpdate(orgUserId, app.getId(),
+ userRolesInRemoteApp);
+ logger.info(EELFLoggerDelegate.debugLogger,
+ "setExternalRequestUserAppRole: {} user app roles: for app {}, user {}",
+ logMessage, newAppRolesForUser.getApplicationName(), newAppRolesForUser.getLoginId());
+ Set<EcompRole> rolesGotDeletedByApprover = new TreeSet<>();
+ result = applyChangesInUserRolesForAppToEcompDB(rolesInAppForUser, externalSystemRequest,
+ reqType, false, rolesGotDeletedByApprover, false);
+ }
+ if (!result) {
+ reqMessage = "Failed to save the user app role(s)";
+ }
+ if (epRequestIdSize > 0 && !userInfo.isEmpty()) {
+ updateStatus = "C";
+ applyChangesToAppRolesRequest(user.getId(), updateStatus, epRequestId.get(0));
}
}
+ } catch (Exception e) {
+ String message = String.format(
+ "setExternalRequestUserAppRole: Failed to create user or update user roles for User %s, AppId %s",
+ orgUserId, appName);
+ logger.error(EELFLoggerDelegate.errorLogger, message, e);
+ result = false;
+ reqMessage = e.getMessage();
+ if (epRequestIdSize > 0 && userInfo != null && !userInfo.isEmpty()) {
+ updateStatus = "F";
+ applyChangesToAppRolesRequest(user.getId(),
+ updateStatus, epRequestId.get(0));
+ }
+ }
+ }
+ return new ExternalRequestFieldsValidator(result, reqMessage);
+ }
- appsListWithAdminRole = new AppsListWithAdminRole();
- appsListWithAdminRole.setOrgUserId(orgUserId);
- List<FnApp> appsList = new ArrayList<>();
- try {
- appsList = fnAppService.findAll();
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, "getAppsWithAdminRoleStateForUser 2 failed", e);
- EPLogUtil.logEcompError(EPAppMessagesEnum.BeDaoSystemError);
+ private Set<EcompRole> postUsersRolesToLocalApp(List<RoleInAppForUser> roleInAppForUserList) {
+ return constructUsersEcompRoles(roleInAppForUserList);
+ }
+
+ private Set<EcompRole> constructUsersEcompRoles(List<RoleInAppForUser> roleInAppForUserList) {
+ Set<EcompRole> existingUserRoles = new TreeSet<>();
+ for (RoleInAppForUser roleInAppForUser : roleInAppForUserList) {
+ if (roleInAppForUser.getIsApplied()) {
+ EcompRole ecompRole = new EcompRole();
+ ecompRole.setId(roleInAppForUser.getRoleId());
+ ecompRole.setName(roleInAppForUser.getRoleName());
+ existingUserRoles.add(ecompRole);
+ }
+ }
+ return existingUserRoles;
+ }
+
+ private List<RoleInAppForUser> roleInAppForUserList(List<ExternalSystemRoleApproval> roleInAppForUserList,
+ Long appId, String appName) throws Exception {
+ List<RoleInAppForUser> existingUserRoles = new ArrayList<>();
+ List<FnRole> existingAppRole;
+ for (ExternalSystemRoleApproval roleInAppForUser : roleInAppForUserList) {
+ RoleInAppForUser ecompRole = new RoleInAppForUser();
+ existingAppRole = fnRoleService.retrieveAppRolesByRoleNameAndByAppId(roleInAppForUser.getRoleName(), appId);
+ if (existingAppRole.isEmpty()) {
+ logger.error(EELFLoggerDelegate.errorLogger, "roleInAppForUserList failed for the roles {}",
+ roleInAppForUserList);
+ throw new Exception("'" + roleInAppForUser.getRoleName() + "'" + " role does not exist for " + appName
+ + " application");
+ }
+ if (!existingAppRole.get(0).getActiveYn()) {
+ logger.error(EELFLoggerDelegate.errorLogger, "roleInAppForUserList failed for the roles {}",
+ roleInAppForUserList);
+ throw new Exception(
+ roleInAppForUser.getRoleName() + " role is unavailable for " + appName + " application");
+ } else {
+
+ List<FnRole> roleInfo = externalAccessRolesService
+ .getPortalAppRoleInfo(PortalConstants.ACCOUNT_ADMIN_ROLE_ID);
+ FnRole adminRole = new FnRole();
+ if (roleInfo.size() > 0) {
+ adminRole = roleInfo.get(0);
+ logger.debug(EELFLoggerDelegate.debugLogger, "Admin RoleName form DB: " + adminRole.getRoleName());
}
- for (FnApp app : appsList) {
- AppNameIdIsAdmin appNameIdIsAdmin = new AppNameIdIsAdmin();
- appNameIdIsAdmin.setId(app.getId());
- appNameIdIsAdmin.setAppName(app.getAppName());
- appNameIdIsAdmin.setIsAdmin(appsUserAdmin.containsKey(app.getId()));
- appNameIdIsAdmin.setRestrictedApp(app.isRestrictedApp());
- appsListWithAdminRole.getAppsRoles().add(appNameIdIsAdmin);
+ ecompRole.setRoleId(
+ (appId == 1 || roleInAppForUser.getRoleName().equals(adminRole.getRoleName())) ? existingAppRole
+ .get(0)
+ .getId() : existingAppRole.get(0).getAppRoleId());
+ ecompRole.setRoleName(roleInAppForUser.getRoleName());
+ ecompRole.setIsApplied(true);
+ existingUserRoles.add(ecompRole);
+ }
+ }
+ return existingUserRoles;
+ }
+
+ private void validateExternalRequestFields(FnApp app) throws Exception {
+ if (app == null) {
+ throw new Exception("Application does not exist");
+ } else if (!app.getEnabled() && !app.getId().equals(PortalConstants.PORTAL_APP_ID)) {
+ throw new Exception(app.getMlAppName() + " application is unavailable");
+ }
+ }
+
+ private String validateNewUser(String orgUserId, FnApp app) throws Exception {
+ FnUser epUser = fnUserService.getUserWithOrgUserId(orgUserId).get(0);
+ if (epUser == null) {
+ throw new Exception("User does not exist");
+ } else if (!epUser.getOrgUserId().equals(orgUserId)) {
+ throw new Exception("User does not exist");
+ } else if (app == null) {
+ throw new Exception("Application does not exist");
+ }
+ return "Saved Successfully";
+ }
+
+ private void applyChangesToAppRolesRequest(final Long userId, final String updateStatus,
+ final EpUserRolesRequest epUserAppRolesRequest) {
+ try {
+ epUserAppRolesRequest.setUpdatedDate(LocalDateTime.now());
+ epUserAppRolesRequest.setRequestStatus(updateStatus);
+ epUserAppRolesRequest.setUserId(fnUserService.getUser(userId).get());
+ epUserRolesRequestService.saveOne(epUserAppRolesRequest);
+ List<EpUserRolesRequestDet> epUserAppRolessDetailList = epUserRolesRequestDetService
+ .appRolesRequestDetailList(epUserAppRolesRequest.getReqId());
+ if (epUserAppRolessDetailList.size() > 0) {
+ for (EpUserRolesRequestDet epRequestUpdateData : epUserAppRolessDetailList) {
+ epRequestUpdateData.setRequestType(updateStatus);
+ epRequestUpdateData.setReqId(epUserAppRolesRequest);
+ epRequestUpdateData.setReqId(epUserAppRolesRequest);
+ epUserRolesRequestDetService.saveOne(epRequestUpdateData);
}
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, "getAppsWithAdminRoleStateForUser 3 failed", e);
}
- return appsListWithAdminRole;
+ logger.debug(EELFLoggerDelegate.debugLogger, "The request is set to complete");
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "applyChangesToAppRolesRequest failed", e);
}
+ }
}
diff --git a/portal-BE/src/main/java/org/onap/portal/service/ExternalAccessRolesService.java b/portal-BE/src/main/java/org/onap/portal/service/ExternalAccessRolesService.java
index 1fa6203d..4bfce266 100644
--- a/portal-BE/src/main/java/org/onap/portal/service/ExternalAccessRolesService.java
+++ b/portal-BE/src/main/java/org/onap/portal/service/ExternalAccessRolesService.java
@@ -72,7 +72,9 @@ import org.onap.portal.domain.db.fn.FnRoleFunction;
import org.onap.portal.domain.db.fn.FnUser;
import org.onap.portal.domain.db.fn.FnUserRole;
import org.onap.portal.domain.dto.ecomp.EPAppRoleFunction;
+import org.onap.portal.domain.dto.ecomp.EPUserAppRolesRequest;
import org.onap.portal.domain.dto.ecomp.ExternalRoleDetails;
+import org.onap.portal.domain.dto.model.ExternalSystemUser;
import org.onap.portal.domain.dto.transport.BulkUploadRoleFunction;
import org.onap.portal.domain.dto.transport.BulkUploadUserRoles;
import org.onap.portal.domain.dto.transport.CentralApp;
@@ -3223,5 +3225,4 @@ public class ExternalAccessRolesService {
}
return roleDescUpdated;
}
-
}
diff --git a/portal-BE/src/main/java/org/onap/portal/service/app/FnAppDao.java b/portal-BE/src/main/java/org/onap/portal/service/app/FnAppDao.java
index f57cc246..2313ce18 100644
--- a/portal-BE/src/main/java/org/onap/portal/service/app/FnAppDao.java
+++ b/portal-BE/src/main/java/org/onap/portal/service/app/FnAppDao.java
@@ -1,6 +1,7 @@
package org.onap.portal.service.app;
import java.util.List;
+import java.util.Optional;
import org.onap.portal.domain.db.fn.FnApp;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
@@ -12,10 +13,12 @@ import org.springframework.transaction.annotation.Transactional;
@Transactional
interface FnAppDao extends JpaRepository<FnApp, Long> {
- @Query
- List<FnApp> getByUebKey(final @Param("uebKey") String uebKey);
+ @Query
+ List<FnApp> getByUebKey(final @Param("uebKey") String uebKey);
- @Query
- List<FnApp> getCentralizedApps();
+ @Query
+ List<FnApp> getCentralizedApps();
+ @Query
+ Optional<List<FnApp>> retrieveWhereAppName(final @Param("appName") String appName);
}
diff --git a/portal-BE/src/main/java/org/onap/portal/service/app/FnAppService.java b/portal-BE/src/main/java/org/onap/portal/service/app/FnAppService.java
index 1a7c2fa5..98cb0fa7 100644
--- a/portal-BE/src/main/java/org/onap/portal/service/app/FnAppService.java
+++ b/portal-BE/src/main/java/org/onap/portal/service/app/FnAppService.java
@@ -142,4 +142,13 @@ public class FnAppService {
public List<FnApp> findAll() {
return Optional.of(fnAppDao.findAll()).orElse(new ArrayList<>());
}
+
+ public FnApp getAppDetail(final String appName) {
+ List<FnApp> fnApps = fnAppDao.retrieveWhereAppName(appName).orElse(new ArrayList<>());
+ if (!fnApps.isEmpty()) {
+ return fnApps.get(0);
+ } else {
+ throw new EntityExistsException("No FnApp where appName equals " + appName);
+ }
+ }
}
diff --git a/portal-BE/src/main/java/org/onap/portal/service/userRolesRequestDet/EpUserRolesRequestDetService.java b/portal-BE/src/main/java/org/onap/portal/service/userRolesRequestDet/EpUserRolesRequestDetService.java
index f8641f06..57a6c9f1 100644
--- a/portal-BE/src/main/java/org/onap/portal/service/userRolesRequestDet/EpUserRolesRequestDetService.java
+++ b/portal-BE/src/main/java/org/onap/portal/service/userRolesRequestDet/EpUserRolesRequestDetService.java
@@ -51,18 +51,19 @@ import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional
public class EpUserRolesRequestDetService {
- private final EpUserRolesRequestDetDao epUserRolesRequestDetDao;
- @Autowired
- public EpUserRolesRequestDetService(EpUserRolesRequestDetDao epUserRolesRequestDetDao) {
- this.epUserRolesRequestDetDao = epUserRolesRequestDetDao;
- }
+ private final EpUserRolesRequestDetDao epUserRolesRequestDetDao;
- public EpUserRolesRequestDet saveOne(EpUserRolesRequestDet epUserRolesRequestDet){
- return epUserRolesRequestDetDao.save(epUserRolesRequestDet);
- }
+ @Autowired
+ public EpUserRolesRequestDetService(EpUserRolesRequestDetDao epUserRolesRequestDetDao) {
+ this.epUserRolesRequestDetDao = epUserRolesRequestDetDao;
+ }
- public List<EpUserRolesRequestDet> appRolesRequestDetailList(final Long reqId){
- return Optional.of(epUserRolesRequestDetDao.appRolesRequestDetailList(reqId)).orElse(new ArrayList<>());
- }
+ public EpUserRolesRequestDet saveOne(EpUserRolesRequestDet epUserRolesRequestDet) {
+ return epUserRolesRequestDetDao.save(epUserRolesRequestDet);
+ }
+
+ public List<EpUserRolesRequestDet> appRolesRequestDetailList(final Long reqId) {
+ return Optional.of(epUserRolesRequestDetDao.appRolesRequestDetailList(reqId)).orElse(new ArrayList<>());
+ }
}