Project

General

Profile

« Previous | Next » 

Revision 61422

added functionality to hide repos/roles from beta to production and vice versa

View differences:

AaiRoleMappingService.java
8 8

  
9 9
import java.net.URLEncoder;
10 10
import java.util.Collection;
11
import java.util.Objects;
11 12
import java.util.stream.Collectors;
12 13

  
13 14
@Service("roleMappingService")
......
15 16

  
16 17
    private static final Logger logger = Logger.getLogger(AaiRoleMappingService.class);
17 18

  
18
    @Value("${registry.production:true}")
19
    @Value("${aai.registry.production:true}")
19 20
    private boolean production;
20 21

  
21 22

  
......
33 34

  
34 35
    @Override
35 36
    public String getRepoIdByRoleId(String roleId) {
37
        if (!roleActive(roleId)) {
38
            return null;
39
        }
36 40
        return roleId.replaceFirst(".*datasource\\.", "").replace("$", ":");
37 41
    }
38 42

  
......
40 44
    public Collection<String> getRepoIdsByRoleIds(Collection<String> roleIds) {
41 45
        return roleIds
42 46
                .stream()
47
                //.filter(this::roleActive) //  implicitly executed in the next statement
43 48
                .map(this::getRepoIdByRoleId)
49
                .filter(Objects::nonNull)
44 50
                .collect(Collectors.toList());
45 51
    }
46 52

  
......
62 68
        return repoIds
63 69
                .stream()
64 70
                .map(this::getRoleIdByRepoId)
71
                .filter(Objects::nonNull)
65 72
                .collect(Collectors.toList());
66 73
    }
67 74

  
68 75
    @Override
69 76
    public String convertAuthorityIdToRepoId(String authorityId) {
70 77
        String repo = "";
71
        if (authorityId != null) {
78
        if (authorityId != null && roleActive(authorityId)) {
72 79
            repo = authorityId
73 80
                    .replaceFirst(".*datasource\\.", "")
74 81
                    .replace("$", ":")
......
105 112
        String role = convertRepoIdToEncodedAuthorityId(repoId);
106 113
        return new SimpleGrantedAuthority(role);
107 114
    }
115

  
116
    private boolean roleActive(String roleId) {
117
        return (production && !roleId.toLowerCase().startsWith("beta."))
118
                || (!production && roleId.toLowerCase().startsWith("beta."));
119
    }
108 120
}

Also available in: Unified diff