-
Notifications
You must be signed in to change notification settings - Fork 1
/
AppConfigDefault.java
142 lines (110 loc) · 4.07 KB
/
AppConfigDefault.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package org.spincast.website;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spincast.core.guice.TestingMode;
import org.spincast.plugins.config.SpincastConfigDefault;
import org.spincast.plugins.config.SpincastConfigPluginConfig;
import org.spincast.shaded.org.apache.commons.lang3.StringUtils;
import org.spincast.shaded.org.apache.commons.lang3.tuple.Pair;
import com.google.inject.Inject;
/**
* Application configurations
*/
public class AppConfigDefault extends SpincastConfigDefault implements AppConfig {
protected static final Logger logger = LoggerFactory.getLogger(AppConfigDefault.class);
private List<Pair<String, String>> adminUsernamesPasswords;
/**
* Constructor
*/
@Inject
public AppConfigDefault(SpincastConfigPluginConfig spincastConfigPluginConfig, @TestingMode boolean testingMode) {
super(spincastConfigPluginConfig, testingMode);
}
@Override
public String getPublicUrlBase() {
return getString("api.base", super.getPublicUrlBase());
}
@Override
public int getHttpServerPort() {
return getInteger("server.port.http", -1);
}
@Override
public int getHttpsServerPort() {
return getInteger("server.port.https", 44420);
}
@Override
public String getHttpsKeyStorePath() {
return "certificates/devKeyStore.jks";
}
@Override
public String getHttpsKeyStoreType() {
return "JKS";
}
@Override
public String getHttpsKeyStoreStorePass() {
return "myStorePass";
}
@Override
public String getHttpsKeyStoreKeyPass() {
return "myKeyPass";
}
@Override
public String getEnvironmentName() {
return getString("environment.name", super.getEnvironmentName());
}
@Override
public boolean isDevelopmentMode() {
return getBoolean("environment.isDebug", super.isDevelopmentMode());
}
@Override
protected String getSpincastWritableDirPath() {
return getString("writableDirPath", super.getSpincastWritableDirPath());
}
@Override
public int getNbrNewsEntriesOnNewsPage() {
return 5;
}
@Override
public int getNbrNewsEntriesPerFeedRequest() {
return 25;
}
@Override
public List<Pair<String, String>> getAdminUsernamesPasswords() {
if (this.adminUsernamesPasswords == null) {
List<Map<String, Object>> administrators =
getMapList("administrators", new ArrayList<Map<String, Object>>());
List<Pair<String, String>> usernamesPasswords = new ArrayList<Pair<String, String>>();
if (administrators != null && administrators.size() > 0) {
for (Map<String, Object> administratorInfo : administrators) {
String name = (String)administratorInfo.get("username");
if (!StringUtils.isBlank(name)) {
String pass = (String)administratorInfo.get("password");
if (StringUtils.isBlank(pass)) {
logger.error("The password can't be empty for user '" + name + "'");
} else {
Pair<String, String> userPassPair = Pair.of(name, pass);
usernamesPasswords.add(userPassPair);
}
}
}
} else {
//==========================================
// Dev credentials
//==========================================
if (isDevelopmentMode() && getPublicUrlBase().startsWith("http://localhost:")) {
Pair<String, String> userPassPair = Pair.of("admin", "admin");
usernamesPasswords.add(userPassPair);
}
}
this.adminUsernamesPasswords = usernamesPasswords;
}
return this.adminUsernamesPasswords;
}
@Override
public String getQueryParamFlashMessageId() {
return "flash";
}
}