UserPropertiesUtil.java
1.9 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.security.user.UserProperties
* javax.jcr.RepositoryException
* org.apache.sling.api.SlingHttpServletRequest
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.personalization;
import com.adobe.granite.security.user.UserProperties;
import org.apache.sling.api.SlingHttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.jcr.RepositoryException;
import java.lang.reflect.Method;
public class UserPropertiesUtil {
private static final Logger log = LoggerFactory.getLogger(UserPropertiesUtil.class);
public static boolean isAnonymous(UserProperties userProperties) {
return userProperties == null || userProperties.getAuthorizableID().equals("anonymous");
}
public static boolean isAnonymous(SlingHttpServletRequest request) {
UserProperties userProperties = (UserProperties)request.adaptTo(UserProperties.class);
return UserPropertiesUtil.isAnonymous(userProperties);
}
public static String getValue(UserProperties userProperties, String propertyName) {
String getterName = "get" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1);
try {
Method method = UserProperties.class.getMethod(getterName, new Class[0]);
Object valueObject = method.invoke((Object)userProperties, null);
return valueObject != null ? valueObject.toString() : "";
}
catch (Exception e) {
log.debug("getValue: error getting value via reflection: ", (Throwable)e);
try {
return userProperties.getProperty(propertyName);
}
catch (RepositoryException e) {
log.error("getValue: error getting value from user properties: ", (Throwable)e);
return null;
}
}
}
}