forked from JabRef/jabref
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathSharelatexConnectionProperties.java
91 lines (69 loc) · 2.27 KB
/
SharelatexConnectionProperties.java
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
package org.jabref.logic.sharelatex;
import java.security.GeneralSecurityException;
import java.util.Objects;
import org.jabref.logic.shared.security.Password;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class SharelatexConnectionProperties {
private static final Log LOGGER = LogFactory.getLog(SharelatexConnectionProperties.class);
private String user;
private String password;
private String url;
private String project;
public SharelatexConnectionProperties() {
// no data
}
public SharelatexConnectionProperties(ShareLatexPreferences prefs) {
setFromPreferences(prefs);
}
public SharelatexConnectionProperties(String url, String user, String password, String project) {
this.url = url;
this.user = user;
this.password = password;
this.project = project;
}
public void setUser(String user) {
this.user = user;
}
public void setPassword(String password) {
this.password = password;
}
public void setUrl(String url) {
this.url = url;
}
public void setProject(String project) {
this.project = project;
}
public String getUser() {
return user;
}
public String getPassword() {
return password;
}
public String getUrl() {
return url;
}
public String getProject() {
return project;
}
public boolean isValid() {
return Objects.nonNull(url)
&& Objects.nonNull(user)
&& Objects.nonNull(password)
&& Objects.nonNull(project);
}
private void setFromPreferences(ShareLatexPreferences prefs) {
this.url = prefs.getSharelatexUrl();
prefs.getDefaultProject().ifPresent(proj -> this.project = proj);
if (prefs.getUser().isPresent()) {
this.user = prefs.getUser().get();
if (prefs.getPassword().isPresent()) {
try {
this.password = new Password(prefs.getPassword().get().toCharArray(), prefs.getUser().get()).decrypt();
} catch (GeneralSecurityException e) {
LOGGER.error("Could not decrypt password", e);
}
}
}
}
}