%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jetspeed.security.spi.impl.DefaultRoleSecurityHandler |
|
|
1 | /* |
|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
3 | * contributor license agreements. See the NOTICE file distributed with |
|
4 | * this work for additional information regarding copyright ownership. |
|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
6 | * (the "License"); you may not use this file except in compliance with |
|
7 | * the License. You may obtain a copy of the License at |
|
8 | * |
|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
10 | * |
|
11 | * Unless required by applicable law or agreed to in writing, software |
|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 | * See the License for the specific language governing permissions and |
|
15 | * limitations under the License. |
|
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.RolePrincipal; |
|
24 | import org.apache.jetspeed.security.SecurityException; |
|
25 | import org.apache.jetspeed.security.impl.RolePrincipalImpl; |
|
26 | import org.apache.jetspeed.security.om.InternalRolePrincipal; |
|
27 | import org.apache.jetspeed.security.om.impl.InternalRolePrincipalImpl; |
|
28 | import org.apache.jetspeed.security.spi.RoleSecurityHandler; |
|
29 | import org.apache.jetspeed.security.spi.SecurityAccess; |
|
30 | ||
31 | /** |
|
32 | * @see org.apache.jetspeed.security.spi.RoleSecurityHandler |
|
33 | * @author <a href="mailto:dlestrat@apache.org">David Le Strat </a> |
|
34 | * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a> |
|
35 | */ |
|
36 | public class DefaultRoleSecurityHandler implements RoleSecurityHandler |
|
37 | { |
|
38 | ||
39 | /** Common queries. */ |
|
40 | 0 | private SecurityAccess commonQueries = null; |
41 | ||
42 | /** |
|
43 | * <p> |
|
44 | * Constructor providing access to the common queries. |
|
45 | * </p> |
|
46 | */ |
|
47 | public DefaultRoleSecurityHandler(SecurityAccess commonQueries) |
|
48 | 0 | { |
49 | 0 | this.commonQueries = commonQueries; |
50 | 0 | } |
51 | ||
52 | /** |
|
53 | * @see org.apache.jetspeed.security.spi.RoleSecurityHandler#getRolePrincipal(java.lang.String) |
|
54 | */ |
|
55 | public RolePrincipal getRolePrincipal(String roleFullPathName) |
|
56 | { |
|
57 | 0 | RolePrincipal rolePrincipal = null; |
58 | 0 | InternalRolePrincipal internalRole = commonQueries |
59 | .getInternalRolePrincipal(RolePrincipalImpl |
|
60 | .getFullPathFromPrincipalName(roleFullPathName)); |
|
61 | 0 | if (null != internalRole) |
62 | { |
|
63 | 0 | rolePrincipal = new RolePrincipalImpl(RolePrincipalImpl |
64 | .getPrincipalNameFromFullPath(internalRole.getFullPath()), |
|
65 | internalRole.isEnabled(), internalRole.isMappingOnly()); |
|
66 | } |
|
67 | 0 | return rolePrincipal; |
68 | } |
|
69 | ||
70 | /** |
|
71 | * @see org.apache.jetspeed.security.spi.RoleSecurityHandler#setRolePrincipal(org.apache.jetspeed.security.RolePrincipal) |
|
72 | */ |
|
73 | public void setRolePrincipal(RolePrincipal rolePrincipal) |
|
74 | throws SecurityException |
|
75 | { |
|
76 | 0 | String fullPath = rolePrincipal.getFullPath(); |
77 | 0 | InternalRolePrincipal internalRole = commonQueries.getInternalRolePrincipal(fullPath); |
78 | 0 | if ( null == internalRole ) |
79 | { |
|
80 | 0 | internalRole = new InternalRolePrincipalImpl(fullPath); |
81 | 0 | internalRole.setEnabled(rolePrincipal.isEnabled()); |
82 | 0 | commonQueries.setInternalRolePrincipal(internalRole, false); |
83 | } |
|
84 | 0 | else if ( !internalRole.isMappingOnly() ) |
85 | { |
|
86 | 0 | if ( internalRole.isEnabled() != rolePrincipal.isEnabled() ) |
87 | { |
|
88 | 0 | internalRole.setEnabled(rolePrincipal.isEnabled()); |
89 | 0 | commonQueries.setInternalRolePrincipal(internalRole, false); |
90 | } |
|
91 | } |
|
92 | else |
|
93 | { |
|
94 | // TODO: should we throw an exception here? |
|
95 | } |
|
96 | 0 | } |
97 | ||
98 | /** |
|
99 | * @see org.apache.jetspeed.security.spi.RoleSecurityHandler#removeRolePrincipal(org.apache.jetspeed.security.RolePrincipal) |
|
100 | */ |
|
101 | public void removeRolePrincipal(RolePrincipal rolePrincipal) |
|
102 | throws SecurityException |
|
103 | { |
|
104 | 0 | InternalRolePrincipal internalRole = commonQueries |
105 | .getInternalRolePrincipal(rolePrincipal.getFullPath()); |
|
106 | 0 | if (null != internalRole) |
107 | { |
|
108 | 0 | commonQueries.removeInternalRolePrincipal(internalRole); |
109 | } |
|
110 | 0 | } |
111 | ||
112 | /** |
|
113 | * @see org.apache.jetspeed.security.spi.RoleSecurityHandler#getRolePrincipals(java.lang.String) |
|
114 | */ |
|
115 | public List getRolePrincipals(String filter) |
|
116 | { |
|
117 | 0 | List rolePrincipals = new LinkedList(); |
118 | 0 | Iterator result = commonQueries.getInternalRolePrincipals(filter); |
119 | 0 | while (result.hasNext()) |
120 | { |
|
121 | 0 | InternalRolePrincipal internalRole = (InternalRolePrincipal) result |
122 | .next(); |
|
123 | 0 | String path = internalRole.getFullPath(); |
124 | 0 | if (path == null) |
125 | { |
|
126 | 0 | continue; |
127 | } |
|
128 | 0 | rolePrincipals.add(new RolePrincipalImpl(RolePrincipalImpl |
129 | .getPrincipalNameFromFullPath(internalRole.getFullPath()))); |
|
130 | 0 | } |
131 | 0 | return rolePrincipals; |
132 | } |
|
133 | ||
134 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |