IT-KIMI_SHI\SINOIT.KIMI
2018-06-12 f45b113c68408a0a58a78ffb2716ba7e6b90ccde
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package frame.role;
 
import java.util.HashSet;
import java.util.Set;
 
import frame.object.http.Path;
import frame.util.Util;
 
 
 
public class Role {
 
    private String name;
    private Set<String> dataSet;
    private Set<String> includeResources;
    private Set<String> endsWithResource;
    private Set<String> cachedAuthorization;
    
    public Role(String name) {
        this.name = name;
        dataSet = new HashSet<String>();
        includeResources = new HashSet<String>();
        endsWithResource = new HashSet<String>();
        cachedAuthorization = new HashSet<String>();
    }
    
    public boolean containsData(String data) {
        return dataSet.contains(data);
    }
 
    public boolean containsPath(Path path) {
        String uri = path.getURI();
        
        if (cachedAuthorization.contains(uri)) {
            return true;
        }
        
        for (String include: includeResources) {
            if (uri.contains(include)) {
                return true;
            }
        }
        
        for (String endswidth: cachedAuthorization) {
            if (uri.endsWith(endswidth)) {
                return true;
            }
        }
        
        return false;
    }
 
    public void addResource(String resource) {
        if (Util.isEmptyStr(resource)) {
            return;
        }
        
        resource = resource.trim().toLowerCase();
        
        if (resource.startsWith("/")) {
            
        }
        
        if (resource.endsWith("/*")) {
            resource = resource.subString(0, resource.length() - "/*".length());
            includeResources.add(resource);
            return;
        }
        
        endsWithResource.add(resource);
    }
 
    @Override
    public String toString() {
        return "Role [name=" + name + "]";
    }
    
}