aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/main')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/filters/ThreadLocalUtils.java39
-rwxr-xr-xcatalog-be/src/main/resources/scripts/sdcBePy/users/data/users.json9
2 files changed, 28 insertions, 20 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/filters/ThreadLocalUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/filters/ThreadLocalUtils.java
index 42b0291c89..13abdd3546 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/filters/ThreadLocalUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/filters/ThreadLocalUtils.java
@@ -25,10 +25,14 @@ import java.util.List;
import java.util.Optional;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
+
+import org.apache.commons.lang3.StringUtils;
import org.onap.sdc.security.AuthenticationCookie;
import org.onap.sdc.security.IUsersThreadLocalHolder;
import org.onap.sdc.security.PortalClient;
import org.onap.sdc.security.RestrictionAccessFilterException;
+import org.openecomp.sdc.be.config.Configuration;
+import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.openecomp.sdc.common.api.Constants;
@@ -41,15 +45,15 @@ public class ThreadLocalUtils implements IUsersThreadLocalHolder {
private static final Logger log = Logger.getLogger(ThreadLocalUtils.class);
@Autowired
- PortalClient portalClient;
+ private PortalClient portalClient;
@Autowired
- UserBusinessLogic userBusinessLogic;
+ private UserBusinessLogic userBusinessLogic;
@Override
public void setUserContext(AuthenticationCookie authenticationCookie) {
UserContext userContext;
userContext = new UserContext(authenticationCookie.getUserID(), authenticationCookie.getRoles(), authenticationCookie.getFirstName(),
- authenticationCookie.getLastName());
+ authenticationCookie.getLastName());
ThreadLocalsHolder.setUserContext(userContext);
}
@@ -59,7 +63,7 @@ public class ThreadLocalUtils implements IUsersThreadLocalHolder {
Set<String> roles = null;
try {
final Optional<String> userRolesFromPortalOptional = portalClient.fetchUserRolesFromPortal(userId);
- if (userRolesFromPortalOptional.isPresent()){
+ if (userRolesFromPortalOptional.isPresent()) {
roles = new HashSet<>(List.of(userRolesFromPortalOptional.get()));
}
} catch (RestrictionAccessFilterException e) {
@@ -74,17 +78,28 @@ public class ThreadLocalUtils implements IUsersThreadLocalHolder {
}
protected void setUserContextFromDB(HttpServletRequest httpRequest) {
- String user_id = httpRequest.getHeader(Constants.USER_ID_HEADER);
- //there are some internal request that have no user_id header e.g. healthcheck
- if (user_id != null) {
- updateUserContext(user_id);
- } else {
- log.debug("user_id value in req header is null, userContext will not be initialized");
+ String userId = httpRequest.getHeader(Constants.USER_ID_HEADER);
+ final Configuration.BasicAuthConfig basicAuthConf = ConfigurationManager.getConfigurationManager().getConfiguration().getBasicAuth();
+ if (StringUtils.isBlank(userId)) {
+ final String excludedUrls = basicAuthConf.getExcludedUrls();
+ //there are some internal request that have no user_id header e.g. healthcheck
+ if (StringUtils.isBlank(excludedUrls) || !checkForExclusion(excludedUrls, httpRequest.getPathInfo())) {
+ log.info("UserId is empty");
+ userId = "cs0008";
+ } else {
+ log.debug("user_id value in req header is null, userContext will not be initialized");
+ return;
+ }
}
+ updateUserContext(userId);
+ }
+
+ private boolean checkForExclusion(final String excludedUrls, final String pathInfo) {
+ return Arrays.stream(excludedUrls.split(";")).anyMatch(s -> s.endsWith(pathInfo));
}
- private void updateUserContext(String user_id) {
- User user = userBusinessLogic.getUser(user_id, false);
+ private void updateUserContext(String userId) {
+ User user = userBusinessLogic.getUser(userId, false);
Set<String> roles = new HashSet<>(Arrays.asList(user.getRole()));
UserContext userContext = new UserContext(user.getUserId(), roles, user.getFirstName(), user.getLastName());
ThreadLocalsHolder.setUserContext(userContext);
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/users/data/users.json b/catalog-be/src/main/resources/scripts/sdcBePy/users/data/users.json
index ed3adafe66..0c9b556acf 100755
--- a/catalog-be/src/main/resources/scripts/sdcBePy/users/data/users.json
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/users/data/users.json
@@ -7,13 +7,6 @@
"email": "demo@openecomp.org"
},
{
- "userId": "gv0001",
- "firstName": "Giuseppe",
- "lastName": "Verdi",
- "role": "GOVERNOR",
- "email": "gv0001@openecomp.org"
- },
- {
"userId": "jh0003",
"firstName": "Jimmy",
"lastName": "Hendrix",
@@ -34,4 +27,4 @@
"role": "DESIGNER",
"email": "cs0008r@openecomp.org"
}
-] \ No newline at end of file
+]