aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java/org/openecomp/vid/roles/RoleProvider.java
blob: 99645a1057e318326fa9502f1ca8bb3819152607 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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);
        }
    }

}