1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.jetspeed.security.spi.impl; |
18 |
|
|
19 |
|
import java.util.Iterator; |
20 |
|
import java.util.LinkedList; |
21 |
|
import java.util.List; |
22 |
|
|
23 |
|
import org.apache.jetspeed.security.GroupPrincipal; |
24 |
|
import org.apache.jetspeed.security.SecurityException; |
25 |
|
import org.apache.jetspeed.security.impl.GroupPrincipalImpl; |
26 |
|
import org.apache.jetspeed.security.om.InternalGroupPrincipal; |
27 |
|
import org.apache.jetspeed.security.om.impl.InternalGroupPrincipalImpl; |
28 |
|
import org.apache.jetspeed.security.spi.GroupSecurityHandler; |
29 |
|
import org.apache.jetspeed.security.spi.SecurityAccess; |
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
public class DefaultGroupSecurityHandler implements GroupSecurityHandler |
37 |
|
{ |
38 |
|
|
39 |
|
|
40 |
0 |
private SecurityAccess commonQueries = null; |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
public DefaultGroupSecurityHandler(SecurityAccess commonQueries) |
48 |
0 |
{ |
49 |
0 |
this.commonQueries = commonQueries; |
50 |
0 |
} |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
public GroupPrincipal getGroupPrincipal(String groupFullPathName) |
56 |
|
{ |
57 |
0 |
GroupPrincipal groupPrincipal = null; |
58 |
0 |
InternalGroupPrincipal internalGroup = commonQueries |
59 |
|
.getInternalGroupPrincipal(GroupPrincipalImpl |
60 |
|
.getFullPathFromPrincipalName(groupFullPathName)); |
61 |
0 |
if (null != internalGroup) |
62 |
|
{ |
63 |
0 |
groupPrincipal = new GroupPrincipalImpl(GroupPrincipalImpl |
64 |
|
.getPrincipalNameFromFullPath(internalGroup.getFullPath()), internalGroup.isEnabled(), internalGroup.isMappingOnly()); |
65 |
|
} |
66 |
0 |
return groupPrincipal; |
67 |
|
} |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
public void setGroupPrincipal(GroupPrincipal groupPrincipal) |
73 |
|
throws SecurityException |
74 |
|
{ |
75 |
0 |
String fullPath = groupPrincipal.getFullPath(); |
76 |
0 |
InternalGroupPrincipal internalGroup = commonQueries.getInternalGroupPrincipal(fullPath); |
77 |
0 |
if ( null == internalGroup ) |
78 |
|
{ |
79 |
0 |
internalGroup = new InternalGroupPrincipalImpl(fullPath); |
80 |
0 |
internalGroup.setEnabled(groupPrincipal.isEnabled()); |
81 |
0 |
commonQueries.setInternalGroupPrincipal(internalGroup, false); |
82 |
|
} |
83 |
0 |
else if ( !internalGroup.isMappingOnly() ) |
84 |
|
{ |
85 |
0 |
if ( internalGroup.isEnabled() != groupPrincipal.isEnabled() ) |
86 |
|
{ |
87 |
0 |
internalGroup.setEnabled(groupPrincipal.isEnabled()); |
88 |
0 |
commonQueries.setInternalGroupPrincipal(internalGroup, false); |
89 |
|
} |
90 |
|
} |
91 |
|
else |
92 |
|
{ |
93 |
|
|
94 |
|
} |
95 |
0 |
} |
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
public void removeGroupPrincipal(GroupPrincipal groupPrincipal) |
101 |
|
throws SecurityException |
102 |
|
{ |
103 |
0 |
InternalGroupPrincipal internalGroup = commonQueries |
104 |
|
.getInternalGroupPrincipal(groupPrincipal.getFullPath()); |
105 |
0 |
if (null != internalGroup) |
106 |
|
{ |
107 |
0 |
commonQueries.removeInternalGroupPrincipal(internalGroup); |
108 |
|
} |
109 |
0 |
} |
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
public List getGroupPrincipals(String filter) |
115 |
|
{ |
116 |
0 |
List groupPrincipals = new LinkedList(); |
117 |
0 |
Iterator result = commonQueries.getInternalGroupPrincipals(filter); |
118 |
0 |
while (result.hasNext()) |
119 |
|
{ |
120 |
0 |
InternalGroupPrincipal internalGroup = (InternalGroupPrincipal) result |
121 |
|
.next(); |
122 |
0 |
String path = internalGroup.getFullPath(); |
123 |
0 |
if (path == null) |
124 |
|
{ |
125 |
0 |
continue; |
126 |
|
} |
127 |
0 |
groupPrincipals |
128 |
|
.add(new GroupPrincipalImpl(GroupPrincipalImpl.getPrincipalNameFromFullPath(internalGroup.getFullPath()), |
129 |
|
internalGroup.isEnabled(), internalGroup.isMappingOnly()) |
130 |
|
); |
131 |
0 |
} |
132 |
0 |
return groupPrincipals; |
133 |
|
} |
134 |
|
|
135 |
|
} |