Skip to content

Commit

Permalink
Add settings for email and time zone of root user
Browse files Browse the repository at this point in the history
  • Loading branch information
Jochen Schalanda committed Jan 6, 2015
1 parent 5dfeb3b commit 6b3adb7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
15 changes: 15 additions & 0 deletions graylog2-server/src/main/java/org/graylog2/Configuration.java
Expand Up @@ -21,6 +21,7 @@
import com.github.joschi.jadconfig.validators.PositiveIntegerValidator;
import com.github.joschi.jadconfig.validators.PositiveLongValidator;
import org.graylog2.plugin.BaseConfiguration;
import org.joda.time.DateTimeZone;

import java.net.URI;

Expand Down Expand Up @@ -75,6 +76,12 @@ public class Configuration extends BaseConfiguration {
@Parameter(value = "root_password_sha2", required = true)
private String rootPasswordSha2;

@Parameter(value = "root_timezone")
private DateTimeZone rootTimeZone = DateTimeZone.UTC;

@Parameter(value = "root_email")
private String rootEmail = "";

@Parameter(value = "allow_leading_wildcard_searches")
private boolean allowLeadingWildcardSearches = false;

Expand Down Expand Up @@ -171,6 +178,14 @@ public String getRootPasswordSha2() {
return rootPasswordSha2;
}

public DateTimeZone getRootTimeZone() {
return rootTimeZone;
}

public String getRootEmail() {
return rootEmail;
}

public boolean isAllowLeadingWildcardSearches() {
return allowLeadingWildcardSearches;
}
Expand Down
20 changes: 11 additions & 9 deletions graylog2-server/src/main/java/org/graylog2/users/UserImpl.java
Expand Up @@ -38,6 +38,7 @@
import java.util.concurrent.TimeUnit;

import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Strings.nullToEmpty;

@CollectionName("users")
public class UserImpl extends PersistedImpl implements User {
Expand All @@ -52,6 +53,8 @@ public class UserImpl extends PersistedImpl implements User {
public static final String TIMEZONE = "timezone";
public static final String EXTERNAL_USER = "external_user";
public static final String SESSION_TIMEOUT = "session_timeout_ms";
public static final String STARTPAGE = "startpage";
public static final String HASH_ALGORITHM = "SHA-1";

public static final int MAX_USERNAME_LENGTH = 100;
public static final int MAX_EMAIL_LENGTH = 254;
Expand Down Expand Up @@ -107,8 +110,7 @@ public void setName(final String username) {

@Override
public String getEmail() {
final Object email = fields.get(EMAIL);
return email == null ? "" : email.toString();
return nullToEmpty((String) fields.get(EMAIL));
}

@Override
Expand Down Expand Up @@ -142,9 +144,9 @@ public void setPreferences(final Map<String, Object> preferences) {
public Map<String, String> getStartpage() {
final Map<String, String> startpage = Maps.newHashMap();

if (fields.containsKey("startpage")) {
if (fields.containsKey(STARTPAGE)) {
@SuppressWarnings("unchecked")
final Map<String, String> obj = (Map<String, String>) fields.get("startpage");
final Map<String, String> obj = (Map<String, String>) fields.get(STARTPAGE);
startpage.put("type", obj.get("type"));
startpage.put("id", obj.get("id"));
}
Expand Down Expand Up @@ -181,14 +183,14 @@ public void setPassword(final String password, final String passwordSecret) {
// If no password is given, we leave the hashed password empty and we fail during validation.
setHashedPassword("");
} else {
final String newPassword = new SimpleHash("SHA-1", password, passwordSecret).toString();
final String newPassword = new SimpleHash(HASH_ALGORITHM, password, passwordSecret).toString();
setHashedPassword(newPassword);
}
}

@Override
public boolean isUserPassword(final String password, final String passwordSecret) {
final String oldPasswordHash = new SimpleHash("SHA-1", password, passwordSecret).toString();
final String oldPasswordHash = new SimpleHash(HASH_ALGORITHM, password, passwordSecret).toString();
return getHashedPassword().equals(oldPasswordHash);
}

Expand Down Expand Up @@ -247,7 +249,7 @@ public void setStartpage(final String type, final String id) {
startpage.put("id", id);
}

this.fields.put("startpage", startpage);
this.fields.put(STARTPAGE, startpage);
}

public static class LocalAdminUser extends UserImpl {
Expand All @@ -269,7 +271,7 @@ public String getFullName() {
}

public String getEmail() {
return "none";
return configuration.getRootEmail();
}

@Override
Expand Down Expand Up @@ -304,7 +306,7 @@ public long getSessionTimeoutMs() {

@Override
public DateTimeZone getTimeZone() {
return null;
return configuration.getRootTimeZone();
}

@Override
Expand Down
8 changes: 8 additions & 0 deletions misc/graylog2.conf
Expand Up @@ -21,6 +21,14 @@ password_secret =
# and put the resulting hash value into the following line
root_password_sha2 =

# The email address of the root user.
# Default is empty
#root_email = ""

# The time zone setting of the root user.
# Default is UTC
#root_timezone = UTC

# Set plugin directory here (relative or absolute)
plugin_dir = plugin

Expand Down

0 comments on commit 6b3adb7

Please sign in to comment.