Skip to content

Commit c2eb1ba

Browse files
authored
Merge pull request #340 from Zhangxinguo/master
Add back missing mereged codes.
2 parents 5fb55c2 + c7c139a commit c2eb1ba

File tree

3 files changed

+28
-15
lines changed
  • elastic-job-cloud/elastic-job-cloud-scheduler/src/main/resources/conf
  • elastic-job-common/elastic-job-common-restful/src/main/java/com/dangdang/ddframe/job/security
  • elastic-job-lite/elastic-job-lite-console/src/main/resources/conf

3 files changed

+28
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
root.username=root
22
root.password=root
3-
guest.password=guest
43
guest.username=guest
4+
guest.password=guest

elastic-job-common/elastic-job-common-restful/src/main/java/com/dangdang/ddframe/job/security/WwwAuthFilter.java

+26-13
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.apache.commons.codec.binary.Base64;
2222

2323
import javax.servlet.*;
24+
import com.google.common.base.Strings;
2425
import javax.servlet.http.HttpServletRequest;
2526
import javax.servlet.http.HttpServletResponse;
2627
import java.io.FileInputStream;
@@ -31,14 +32,18 @@
3132
public final class WwwAuthFilter implements Filter {
3233

3334
private static final String AUTH_PREFIX = "Basic ";
35+
36+
private static final String GUEST = "guest";
37+
38+
private static final String ROOT = "root";
39+
40+
private String rootUsername;
3441

35-
private String root_username = "root";
36-
37-
private String root_password = "root";
42+
private String rootPassword;
3843

39-
private String guest_username = "guest";
44+
private String guestUsername;
4045

41-
private String guest_password = "guest";
46+
private String guestPassword;
4247

4348
@Override
4449
public void init(final FilterConfig filterConfig) throws ServletException {
@@ -50,10 +55,18 @@ public void init(final FilterConfig filterConfig) throws ServletException {
5055
} catch (final IOException ex) {
5156
log.warn("Cannot found auth config file, use default auth config.");
5257
}
53-
root_username = props.getProperty("root.username", root_username);
54-
root_password = props.getProperty("root.password", root_password);
55-
guest_username = props.getProperty("guset.username", guest_username);
56-
guest_password = props.getProperty("guset.password", guest_password);
58+
if (Strings.isNullOrEmpty(props.getProperty("root.username"))) {
59+
rootUsername = "root";
60+
} else {
61+
rootUsername = props.getProperty("root.username");
62+
}
63+
if (Strings.isNullOrEmpty(props.getProperty("guest.username"))) {
64+
guestUsername = "guest";
65+
} else {
66+
guestUsername = props.getProperty("guest.username");
67+
}
68+
rootPassword = props.getProperty("root.password", "root");
69+
guestPassword = props.getProperty("guest.password", "guest");
5770
}
5871

5972
@Override
@@ -63,10 +76,10 @@ public void doFilter(final ServletRequest request, final ServletResponse respons
6376
String authorization = httpRequest.getHeader("authorization");
6477
if (null != authorization && authorization.length() > AUTH_PREFIX.length()) {
6578
authorization = authorization.substring(AUTH_PREFIX.length(), authorization.length());
66-
if ((root_username + ":" + root_password).equals(new String(Base64.decodeBase64(authorization)))) {
79+
if ((rootUsername + ":" + rootPassword).equals(new String(Base64.decodeBase64(authorization)))) {
6780
authenticateSuccess(httpResponse, false);
6881
chain.doFilter(httpRequest, httpResponse);
69-
} else if ((guest_username + ":" + guest_password).equals(new String(Base64.decodeBase64(authorization)))) {
82+
} else if ((guestUsername + ":" + guestPassword).equals(new String(Base64.decodeBase64(authorization)))) {
7083
authenticateSuccess(httpResponse, true);
7184
chain.doFilter(httpRequest, httpResponse);
7285
} else {
@@ -77,12 +90,12 @@ public void doFilter(final ServletRequest request, final ServletResponse respons
7790
}
7891
}
7992

80-
private void authenticateSuccess(final HttpServletResponse response, boolean isGuset) {
93+
private void authenticateSuccess(final HttpServletResponse response, boolean isGuest) {
8194
response.setStatus(200);
8295
response.setHeader("Pragma", "No-cache");
8396
response.setHeader("Cache-Control", "no-store");
8497
response.setDateHeader("Expires", 0);
85-
response.setHeader("identify", true == isGuset ? guest_username : root_username);
98+
response.setHeader("identify", true == isGuest ? GUEST : ROOT);
8699
}
87100

88101
private void needAuthenticate(final HttpServletRequest request, final HttpServletResponse response) {
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
root.username=root
22
root.password=root
3-
guest.password=guest
43
guest.username=guest
4+
guest.password=guest

0 commit comments

Comments
 (0)