MemoryTokenAuthHandler.java
3.84 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.servlet.http.HttpServletRequest
* javax.servlet.http.HttpServletResponse
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Properties
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.auth.core.spi.AuthenticationHandler
* org.apache.sling.auth.core.spi.AuthenticationInfo
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.dam.s7imaging.impl.auth;
import com.adobe.cq.dam.s7imaging.impl.auth.MemoryTokenCredentials;
import com.adobe.cq.dam.s7imaging.impl.auth.MemoryTokenService;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.auth.core.spi.AuthenticationHandler;
import org.apache.sling.auth.core.spi.AuthenticationInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=1, label="Adobe CQ ImageServer Authentication Handler", description="Adobe CQ ImageServer Authentication Handler")
@Service(value={AuthenticationHandler.class})
@Properties(value={@Property(name="service.description", value={"ImageServer Authentication Handler"}), @Property(name="service.ranking", intValue={50000}, propertyPrivate=1), @Property(name="path", value={"/"}, cardinality=2, label="Paths", description="Paths for which this Sling Authentication Handler is used")})
public class MemoryTokenAuthHandler
implements AuthenticationHandler {
private static Logger log = LoggerFactory.getLogger(MemoryTokenAuthHandler.class);
@Property(name="authtype", propertyPrivate=1)
private static final String TYPE = "DynamicMediaMemoryToken";
private static final Pattern UUID_PATTERN = Pattern.compile("\\p{XDigit}{8}-\\p{XDigit}{4}-\\p{XDigit}{4}-\\p{XDigit}{4}-\\p{XDigit}{12}");
@Reference
protected MemoryTokenService tokenService;
public AuthenticationInfo extractCredentials(HttpServletRequest request, HttpServletResponse response) {
String HTTP_HEADER = this.tokenService.getHttpHeaderName();
String token = request.getHeader(HTTP_HEADER);
if (token == null) {
if (log.isTraceEnabled()) {
log.trace("Skipping, no {} header in request: {} {}", new Object[]{HTTP_HEADER, request.getMethod(), request.getRequestURI()});
}
return null;
}
if (!UUID_PATTERN.matcher(token).matches()) {
if (log.isTraceEnabled()) {
log.trace("Invalid token {}, returning FAIL_AUTH: {} {}", new Object[]{token, request.getMethod(), request.getRequestURI()});
}
return AuthenticationInfo.FAIL_AUTH;
}
AuthenticationInfo info = new AuthenticationInfo("DynamicMediaMemoryToken", token);
info.put("user.jcr.credentials", (Object)new MemoryTokenCredentials(token));
return info;
}
public boolean requestCredentials(HttpServletRequest request, HttpServletResponse response) throws IOException {
return false;
}
public void dropCredentials(HttpServletRequest request, HttpServletResponse response) throws IOException {
}
protected void bindTokenService(MemoryTokenService memoryTokenService) {
this.tokenService = memoryTokenService;
}
protected void unbindTokenService(MemoryTokenService memoryTokenService) {
if (this.tokenService == memoryTokenService) {
this.tokenService = null;
}
}
}