DefaultProfileProvider.java
7.54 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.security.user.UserProperties
* com.adobe.granite.security.user.UserPropertiesManager
* com.adobe.granite.security.user.UserPropertiesService
* com.day.cq.personalization.ProfileProvider
* com.day.cq.personalization.UserPropertiesProvider
* com.day.cq.security.User
* com.day.cq.security.profile.Profile
* com.day.cq.security.profile.ProfileManager
* javax.jcr.RepositoryException
* javax.jcr.Session
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceUtil
* org.apache.sling.api.resource.ValueMap
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.personalization.impl;
import com.adobe.granite.security.user.UserProperties;
import com.adobe.granite.security.user.UserPropertiesManager;
import com.adobe.granite.security.user.UserPropertiesService;
import com.day.cq.personalization.ProfileProvider;
import com.day.cq.personalization.UserPropertiesProvider;
import com.day.cq.security.User;
import com.day.cq.security.profile.Profile;
import com.day.cq.security.profile.ProfileManager;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DefaultProfileProvider
implements ProfileProvider,
UserPropertiesProvider {
private static final String PARAM_AUTHORIZABLE = "authorizable";
private static final String PROPERTY_PROFILE = "profile";
private static final String VARIABLE_ME = "~";
private final Logger log = LoggerFactory.getLogger(DefaultProfileProvider.class);
private ProfileManager profileManager;
private UserPropertiesService userPropertiesService;
@Deprecated
public Profile getProfile(SlingHttpServletRequest request) {
ResourceResolver resourceResolver = request.getResourceResolver();
Resource resource = request.getResource();
Profile profile = (Profile)resource.adaptTo(Profile.class);
if (profile == null) {
this.log.debug("Resource didn't adapt to an Profile, search for authorizable ID at {}", (Object)resource.getPath());
ValueMap properties = ResourceUtil.getValueMap((Resource)resource);
String auth = (String)properties.get("profile", String.class);
if (auth == null) {
this.log.debug("Resource didn't have a authorizable property value at, search request parameter", (Object)resource.getPath());
auth = request.getParameter("authorizable");
}
if (auth != null) {
if ("~".equals(auth)) {
this.log.debug("replaced variable 'me' with current user", (Object)resource.getPath());
profile = ((User)resourceResolver.adaptTo(User.class)).getProfile();
} else {
this.log.debug("resolve Profile from request to {} for User {}", (Object)resource.getPath(), (Object)auth);
try {
return this.profileManager.getProfile(auth, (Session)resourceResolver.adaptTo(Session.class));
}
catch (RepositoryException e) {
this.log.error("error accessing profile: ", (Throwable)e);
}
}
}
}
if (profile == null) {
profile = this.getProfile(resourceResolver);
}
return profile;
}
@Deprecated
public Profile getProfile(ResourceResolver resolver) {
User user = (User)resolver.adaptTo(User.class);
return null != user ? user.getProfile() : null;
}
public UserProperties getUserProperties(SlingHttpServletRequest request) {
Resource resource = request.getResource();
ResourceResolver resourceResolver = request.getResourceResolver();
UserProperties userProperties = (UserProperties)resource.adaptTo(UserProperties.class);
if (userProperties == null) {
this.log.debug("resource does not represent user properties, searching via authorizable ID at {}", (Object)resource.getPath());
ValueMap properties = ResourceUtil.getValueMap((Resource)resource);
String auth = (String)properties.get("profile", String.class);
if (auth == null) {
this.log.debug("Resource didn't have a authorizable property value at, search request parameter", (Object)resource.getPath());
auth = request.getParameter("authorizable");
}
if (auth != null) {
UserPropertiesManager upm = (UserPropertiesManager)resourceResolver.adaptTo(UserPropertiesManager.class);
if (null == upm) {
this.log.error("getUserProperties: UserPropertiesManager unavailable.");
return null;
}
if ("~".equals(auth)) {
this.log.debug("replaced variable 'me' with current user", (Object)resource.getPath());
try {
userProperties = upm.getUserProperties(((User)resourceResolver.adaptTo(User.class)).getID(), null);
}
catch (RepositoryException e) {
this.log.error("getUserProperties: error retrieving user properties: ", (Throwable)e);
}
} else {
this.log.debug("resolve UserProperties from request to {} for User {}", (Object)resource.getPath(), (Object)auth);
try {
return upm.getUserProperties(auth, null);
}
catch (RepositoryException e) {
this.log.error("error accessing userProperties: ", (Throwable)e);
}
}
}
}
if (userProperties == null) {
userProperties = this.getUserProperties(resourceResolver);
}
return userProperties;
}
public UserProperties getUserProperties(ResourceResolver resolver) {
UserPropertiesManager upm = (UserPropertiesManager)resolver.adaptTo(UserPropertiesManager.class);
if (null == upm) {
this.log.error("getUserProperties: UserPropertiesManager unavailable.");
return null;
}
try {
return upm.getUserProperties(resolver.getUserID(), "profile");
}
catch (RepositoryException e) {
this.log.error("getUserProperties: repository error while getting user properties: ", (Throwable)e);
return null;
}
}
protected void bindProfileManager(ProfileManager profileManager) {
this.profileManager = profileManager;
}
protected void unbindProfileManager(ProfileManager profileManager) {
if (this.profileManager == profileManager) {
this.profileManager = null;
}
}
protected void bindUserPropertiesService(UserPropertiesService userPropertiesService) {
this.userPropertiesService = userPropertiesService;
}
protected void unbindUserPropertiesService(UserPropertiesService userPropertiesService) {
if (this.userPropertiesService == userPropertiesService) {
this.userPropertiesService = null;
}
}
}