1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.impl.identity; |
17 | |
|
18 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.kuali.rice.kim.api.KimConstants; |
20 | |
import org.kuali.rice.kim.api.identity.IdentityService; |
21 | |
import org.kuali.rice.kim.api.identity.entity.EntityDefault; |
22 | |
import org.kuali.rice.kim.api.identity.privacy.EntityPrivacyPreferences; |
23 | |
import org.kuali.rice.kim.api.permission.PermissionService; |
24 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
25 | |
import org.kuali.rice.krad.UserSession; |
26 | |
import org.kuali.rice.krad.util.GlobalVariables; |
27 | |
|
28 | |
import java.util.Collections; |
29 | |
|
30 | |
class KimInternalSuppressUtils { |
31 | |
|
32 | |
private static IdentityService identityService; |
33 | |
private static PermissionService permissionService; |
34 | |
|
35 | 0 | private KimInternalSuppressUtils() { |
36 | 0 | throw new UnsupportedOperationException("do not call"); |
37 | |
} |
38 | |
|
39 | |
public static boolean isSuppressName(String entityId) { |
40 | 0 | EntityPrivacyPreferences privacy = null; |
41 | 0 | EntityDefault entityInfo = getIdentityService().getEntityDefault(entityId); |
42 | 0 | if (entityInfo != null) { |
43 | 0 | privacy = entityInfo.getPrivacyPreferences(); |
44 | |
} else { |
45 | 0 | return true; |
46 | |
} |
47 | 0 | UserSession userSession = GlobalVariables.getUserSession(); |
48 | |
|
49 | 0 | boolean suppressName = false; |
50 | 0 | if (privacy != null) { |
51 | 0 | suppressName = privacy.isSuppressName(); |
52 | |
} |
53 | |
|
54 | 0 | return suppressName |
55 | |
&& userSession != null |
56 | |
&& !StringUtils.equals(userSession.getPerson().getEntityId(), entityId) |
57 | |
&& !canOverrideEntityPrivacyPreferences(entityInfo.getPrincipals().get(0).getPrincipalId()); |
58 | |
} |
59 | |
|
60 | |
public static boolean isSuppressEmail(String entityId) { |
61 | 0 | EntityPrivacyPreferences privacy = null; |
62 | 0 | EntityDefault entityInfo = getIdentityService().getEntityDefault(entityId); |
63 | 0 | if (entityInfo != null) { |
64 | 0 | privacy = entityInfo.getPrivacyPreferences(); |
65 | |
} else { |
66 | 0 | return true; |
67 | |
} |
68 | 0 | UserSession userSession = GlobalVariables.getUserSession(); |
69 | |
|
70 | 0 | boolean suppressEmail = false; |
71 | 0 | if (privacy != null) { |
72 | 0 | suppressEmail = privacy.isSuppressEmail(); |
73 | |
} |
74 | 0 | return suppressEmail |
75 | |
&& userSession != null |
76 | |
&& !StringUtils.equals(userSession.getPerson().getEntityId(), entityId) |
77 | |
&& !canOverrideEntityPrivacyPreferences(entityInfo.getPrincipals().get(0).getPrincipalId()); |
78 | |
} |
79 | |
|
80 | |
public static boolean isSuppressAddress(String entityId) { |
81 | 0 | EntityPrivacyPreferences privacy = null; |
82 | 0 | EntityDefault entityInfo = getIdentityService().getEntityDefault(entityId); |
83 | 0 | if (entityInfo != null) { |
84 | 0 | privacy = entityInfo.getPrivacyPreferences(); |
85 | |
} else { |
86 | 0 | return false; |
87 | |
} |
88 | 0 | UserSession userSession = GlobalVariables.getUserSession(); |
89 | |
|
90 | 0 | boolean suppressAddress = false; |
91 | 0 | if (privacy != null) { |
92 | 0 | suppressAddress = privacy.isSuppressAddress(); |
93 | |
} |
94 | 0 | return suppressAddress |
95 | |
&& userSession != null |
96 | |
&& !StringUtils.equals(userSession.getPerson().getEntityId(), entityId) |
97 | |
&& !canOverrideEntityPrivacyPreferences(entityInfo.getPrincipals().get(0).getPrincipalId()); |
98 | |
} |
99 | |
|
100 | |
public static boolean isSuppressPhone(String entityId) { |
101 | 0 | EntityPrivacyPreferences privacy = null; |
102 | 0 | EntityDefault entityInfo = getIdentityService().getEntityDefault(entityId); |
103 | 0 | if (entityInfo != null) { |
104 | 0 | privacy = entityInfo.getPrivacyPreferences(); |
105 | |
} else { |
106 | 0 | return true; |
107 | |
} |
108 | 0 | UserSession userSession = GlobalVariables.getUserSession(); |
109 | |
|
110 | 0 | boolean suppressPhone = false; |
111 | 0 | if (privacy != null) { |
112 | 0 | suppressPhone = privacy.isSuppressPhone(); |
113 | |
} |
114 | 0 | return suppressPhone |
115 | |
&& userSession != null |
116 | |
&& !StringUtils.equals(userSession.getPerson().getEntityId(), entityId) |
117 | |
&& !canOverrideEntityPrivacyPreferences(entityInfo.getPrincipals().get(0).getPrincipalId()); |
118 | |
} |
119 | |
|
120 | |
public static boolean isSuppressPersonal(String entityId) { |
121 | 0 | EntityPrivacyPreferences privacy = null; |
122 | 0 | EntityDefault entityInfo = getIdentityService().getEntityDefault(entityId); |
123 | 0 | if (entityInfo != null) { |
124 | 0 | privacy = entityInfo.getPrivacyPreferences(); |
125 | |
} else { |
126 | 0 | return true; |
127 | |
} |
128 | 0 | UserSession userSession = GlobalVariables.getUserSession(); |
129 | |
|
130 | 0 | boolean suppressPersonal = false; |
131 | 0 | if (privacy != null) { |
132 | 0 | suppressPersonal = privacy.isSuppressPersonal(); |
133 | |
} |
134 | 0 | return suppressPersonal |
135 | |
&& userSession != null |
136 | |
&& !StringUtils.equals(userSession.getPerson().getEntityId(), entityId) |
137 | |
&& !canOverrideEntityPrivacyPreferences(entityInfo.getPrincipals().get(0).getPrincipalId()); |
138 | |
} |
139 | |
|
140 | |
protected static boolean canOverrideEntityPrivacyPreferences( String principalId ){ |
141 | 0 | return getPermissionService().isAuthorized( |
142 | |
GlobalVariables.getUserSession().getPrincipalId(), |
143 | |
KimConstants.NAMESPACE_CODE, |
144 | |
KimConstants.PermissionNames.OVERRIDE_ENTITY_PRIVACY_PREFERENCES, |
145 | |
Collections.<String, String>emptyMap(), |
146 | |
Collections.singletonMap(KimConstants.AttributeConstants.PRINCIPAL_ID, principalId) ); |
147 | |
} |
148 | |
|
149 | |
private static IdentityService getIdentityService() { |
150 | 0 | if ( identityService == null ) { |
151 | 0 | identityService = KimApiServiceLocator.getIdentityService(); |
152 | |
} |
153 | 0 | return identityService; |
154 | |
} |
155 | |
|
156 | |
private static PermissionService getPermissionService() { |
157 | 0 | if ( permissionService == null ) { |
158 | 0 | permissionService = KimApiServiceLocator.getPermissionService(); |
159 | |
} |
160 | 0 | return permissionService; |
161 | |
} |
162 | |
} |