]> SALOME platform Git repositories - modules/gde.git/blob - projects/GDE_App/GDE-ejb/src/java/com/edf/gde/common/PermissionManager.java
Salome HOME
- Code refactoring and simplification
[modules/gde.git] / projects / GDE_App / GDE-ejb / src / java / com / edf / gde / common / PermissionManager.java
1 package com.edf.gde.common;
2
3 import java.util.HashMap;
4 import java.util.HashSet;
5 import java.util.Map;
6 import java.util.Set;
7
8 /**
9  *
10  * @author Kavoos
11  */
12 public class PermissionManager {
13     /**
14      * MAP<K,V>
15      * K = Service name
16      * V = Set of user Id
17      */
18     Map<String, Set<Long>> userPermissions;
19
20     public PermissionManager() {
21         userPermissions = new HashMap<>();
22     }
23     
24     public synchronized void addUser(String serviceName, long userId) {
25         Set<Long> users = userPermissions.get(serviceName);
26         if (users == null) {
27             users = new HashSet<>();
28             users.add(userId);
29             userPermissions.put(serviceName, users);
30         } else {
31             users.add(userId);
32         }
33     }
34     
35     public synchronized boolean isValid(String serviceName, long userId) {
36         Set<Long> users = userPermissions.get(serviceName);
37         if (users == null) {
38             return false;
39         }
40         return users.contains(userId);
41     }
42     
43 }