SimpleCredentialsConfig.java
2.21 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.Credentials
* javax.jcr.SimpleCredentials
*/
package com.day.jcr.vault.fs.config;
import com.day.jcr.vault.fs.config.ConfigurationException;
import com.day.jcr.vault.fs.config.CredentialsConfig;
import javax.jcr.Credentials;
import javax.jcr.SimpleCredentials;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class SimpleCredentialsConfig
extends CredentialsConfig {
private final SimpleCredentials creds;
public static final String ELEM_USER = "user";
public static final String ATTR_NAME = "name";
public static final String ATTR_PASSWORD = "password";
public SimpleCredentialsConfig(SimpleCredentials creds) {
super("simple");
this.creds = creds;
}
public Credentials getCredentials() {
return this.creds;
}
public static SimpleCredentialsConfig load(Element elem) throws ConfigurationException {
assert (elem.getNodeName().equals("credentials"));
NodeList nl = elem.getChildNodes();
for (int i = 0; i < nl.getLength(); ++i) {
Node child = nl.item(i);
if (child.getNodeType() != 1 || !child.getNodeName().equals("user")) continue;
Element e = (Element)child;
String name = e.getAttribute("name");
String pass = e.getAttribute("password");
return new SimpleCredentialsConfig(new SimpleCredentials(name, pass == null ? new char[]{} : pass.toCharArray()));
}
throw new ConfigurationException("mandatory element <user> missing.");
}
public void writeInner(ContentHandler handler) throws SAXException {
if (this.creds != null) {
AttributesImpl attrs = new AttributesImpl();
attrs.addAttribute("", "name", "", "CDATA", this.creds.getUserID());
attrs.addAttribute("", "password", "", "CDATA", new String(this.creds.getPassword()));
handler.startElement("", "user", "", attrs);
handler.endElement("", "user", "");
}
}
}