diff options
author | 2017-09-20 13:20:42 +0300 | |
---|---|---|
committer | 2017-09-20 13:37:03 +0300 | |
commit | 9dfd7e28c1eb348fcb4a2de8c6faae2a01b34942 (patch) | |
tree | c273862f59b0b64c19ccfea5f59ab574071cb323 /vid-app-common/src/main/java/org/openecomp/vid/roles/RoleProvider.java | |
parent | c3722d135481cfab5978c84853d8229d1e7d9cb3 (diff) |
Global Read only role, Support VID specific Roles
Issue-ID: VID-46 , VID-47
Change-Id: Ib100d20ac40a65d39e27a6e2741b19a173a2b8ea
Signed-off-by: Ofir Sonsino <os0695@att.com>
Diffstat (limited to 'vid-app-common/src/main/java/org/openecomp/vid/roles/RoleProvider.java')
-rw-r--r-- | vid-app-common/src/main/java/org/openecomp/vid/roles/RoleProvider.java | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/roles/RoleProvider.java b/vid-app-common/src/main/java/org/openecomp/vid/roles/RoleProvider.java new file mode 100644 index 00000000..99645a10 --- /dev/null +++ b/vid-app-common/src/main/java/org/openecomp/vid/roles/RoleProvider.java @@ -0,0 +1,62 @@ +package org.openecomp.vid.roles; + +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.portalsdk.core.web.support.UserUtils; + +import javax.servlet.http.HttpServletRequest; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +/** + * Created by Oren on 7/1/17. + */ +public class RoleProvider { + + private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(RoleProvider.class); + final String readPermissionString = "read"; + + public static List<String> extractRoleFromSession(HttpServletRequest request) { + + return new ArrayList<String>(); + + } + + public List<Role> getUserRoles(HttpServletRequest request) { + List<Role> roleList = new ArrayList<>(); + HashMap roles = UserUtils.getRoles(request); + for (Object role : roles.keySet()) { + org.openecomp.portalsdk.core.domain.Role sdkRol = (org.openecomp.portalsdk.core.domain.Role) roles.get(role); + try { + if (sdkRol.getName().contains(readPermissionString)) + continue; + String[] roleParts = splitRole((sdkRol.getName())); + roleList.add(createRoleFromStringArr(roleParts)); + } catch (Exception e) { + LOG.error("Failed to parse permission", e); + + } + } + + return roleList; + } + + public String[] splitRole(String roleAsString) { + return roleAsString.split("_"); + } + + public boolean userPermissionIsReadOnly(List<Role> roles) { + + return (!(roles.size() > 0)); + } + + public Role createRoleFromStringArr(String[] roleParts) { + if (roleParts.length > 2) { + return new Role(EcompRole.READ, roleParts[0], roleParts[1], roleParts[2]); + } else { + return new Role(EcompRole.READ, roleParts[0], roleParts[1], null); + } + } + +} + |