ContextProfileProvider.java
5.56 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.security.user.UserProperties
* com.adobe.granite.security.user.UserPropertiesManager
* com.day.cq.personalization.ContextSessionPersistence
* com.day.cq.personalization.ProfileProvider
* com.day.cq.personalization.UserPropertiesProvider
* com.day.cq.security.profile.Profile
* com.day.cq.security.profile.ProfileManager
* com.day.cq.wcm.api.WCMMode
* javax.jcr.RepositoryException
* javax.jcr.Session
* javax.servlet.ServletRequest
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.jcr.api.SlingRepository
* 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.day.cq.personalization.ContextSessionPersistence;
import com.day.cq.personalization.ProfileProvider;
import com.day.cq.personalization.UserPropertiesProvider;
import com.day.cq.security.profile.Profile;
import com.day.cq.security.profile.ProfileManager;
import com.day.cq.wcm.api.WCMMode;
import java.util.Map;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.servlet.ServletRequest;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.jcr.api.SlingRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public class ContextProfileProvider
implements ProfileProvider,
UserPropertiesProvider {
private final Logger log = LoggerFactory.getLogger(ContextProfileProvider.class);
private SlingRepository repository = null;
private ProfileManager profileManager = null;
public Profile getProfile(SlingHttpServletRequest request) {
return this.getProfileOrUserProperties(request, Profile.class);
}
public Profile getProfile(ResourceResolver resolver) {
return null;
}
public UserProperties getUserProperties(SlingHttpServletRequest request) {
return this.getProfileOrUserProperties(request, UserProperties.class);
}
public UserProperties getUserProperties(ResourceResolver resolver) {
return null;
}
private <T> T getProfileOrUserProperties(SlingHttpServletRequest request, Class<T> clazz) {
if (WCMMode.DISABLED != WCMMode.fromRequest((ServletRequest)request)) {
String authorizableId;
T t;
Map contextProfile = ContextSessionPersistence.getStore((SlingHttpServletRequest)request, (String)"PROFILEDATA");
if (contextProfile.containsKey("authorizableId")) {
authorizableId = (String)contextProfile.get("authorizableId");
try {
t = this.getProfileObject(authorizableId, request.getResourceResolver(), clazz);
if (t != null) {
return t;
}
}
catch (RepositoryException e) {
this.log.error("error while getting {}: ", (Object)clazz.getSimpleName(), (Object)e);
}
}
if ((contextProfile = ContextSessionPersistence.getStore((SlingHttpServletRequest)request, (String)"CLICKSTREAMCLOUD")).containsKey("visitorId")) {
authorizableId = (String)contextProfile.get("visitorId");
try {
t = this.getProfileObject(authorizableId, request.getResourceResolver(), clazz);
if (t != null) {
return t;
}
}
catch (RepositoryException e) {
this.log.error("error while getting {}: ", (Object)clazz.getSimpleName(), (Object)e);
}
}
try {
T t2 = this.getProfileObject("anonymous", request.getResourceResolver(), clazz);
if (t2 != null) {
return t2;
}
}
catch (RepositoryException e) {
this.log.error("error while getting {}: ", (Object)clazz.getSimpleName(), (Object)e);
}
}
return null;
}
private <T> T getProfileObject(String authorizableId, ResourceResolver resolver, Class<T> clazz) throws RepositoryException {
if (clazz == Profile.class) {
return (T)this.profileManager.getProfile(authorizableId, (Session)resolver.adaptTo(Session.class));
}
if (clazz == UserProperties.class) {
UserPropertiesManager upm = (UserPropertiesManager)resolver.adaptTo(UserPropertiesManager.class);
if (null != upm) {
return (T)upm.getUserProperties(authorizableId, "profile");
}
this.log.error("getProfileOrUserProperties: UserPropertiesManager unavailable");
}
return null;
}
protected void bindRepository(SlingRepository slingRepository) {
this.repository = slingRepository;
}
protected void unbindRepository(SlingRepository slingRepository) {
if (this.repository == slingRepository) {
this.repository = null;
}
}
protected void bindProfileManager(ProfileManager profileManager) {
this.profileManager = profileManager;
}
protected void unbindProfileManager(ProfileManager profileManager) {
if (this.profileManager == profileManager) {
this.profileManager = null;
}
}
}