ConfigPostProcessor.java
3.31 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.crypto.CryptoException
* com.adobe.granite.crypto.CryptoSupport
* javax.jcr.Property
* javax.jcr.RepositoryException
* javax.jcr.Session
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.servlets.post.Modification
* org.apache.sling.servlets.post.ModificationType
* org.apache.sling.servlets.post.SlingPostProcessor
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.replication.impl;
import com.adobe.granite.crypto.CryptoException;
import com.adobe.granite.crypto.CryptoSupport;
import com.day.cq.replication.impl.AgentConfigImpl;
import java.util.List;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.servlets.post.Modification;
import org.apache.sling.servlets.post.ModificationType;
import org.apache.sling.servlets.post.SlingPostProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=0)
@Service(value={SlingPostProcessor.class})
public class ConfigPostProcessor
implements SlingPostProcessor {
private static final Logger log = LoggerFactory.getLogger(ConfigPostProcessor.class);
@Reference
private CryptoSupport crypto;
public void process(SlingHttpServletRequest request, List<Modification> changes) throws Exception {
Session session = null;
for (Modification mod : changes) {
switch (mod.getType()) {
case MODIFY:
case CREATE: {
String path = mod.getSource();
if (!path.startsWith("/etc/replication/") || !this.isPasswordProp(path)) break;
if (session == null) {
session = (Session)request.getResourceResolver().adaptTo(Session.class);
}
this.fix(session.getProperty(path));
}
}
}
}
private void fix(Property p) throws RepositoryException {
String pwd = p.getString();
if (pwd.length() > 0 && !this.crypto.isProtected(pwd)) {
String dec = AgentConfigImpl.legacyDecrypt(pwd);
if (dec != null) {
pwd = dec;
}
try {
p.setValue(this.crypto.protect(pwd));
}
catch (CryptoException e) {
log.error("Error during protecting password: {}", (Object)e.toString());
}
}
}
private boolean isPasswordProp(String path) {
return path.endsWith("transportPassword") || path.endsWith("proxyPassword");
}
protected void bindCrypto(CryptoSupport cryptoSupport) {
this.crypto = cryptoSupport;
}
protected void unbindCrypto(CryptoSupport cryptoSupport) {
if (this.crypto == cryptoSupport) {
this.crypto = null;
}
}
}