Skip to content

Commit

Permalink
build and return a LocalAdminUser when authenticating, fixes issue #181
Browse files Browse the repository at this point in the history
  • Loading branch information
kroepke committed Aug 17, 2013
1 parent a8d36fd commit 7955e96
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions graylog2-server/src/main/java/org/graylog2/users/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.bson.types.ObjectId;
import org.graylog2.Core;
import org.graylog2.database.Persisted;
import org.graylog2.database.ValidationException;
import org.graylog2.database.validators.FilledStringValidator;
import org.graylog2.database.validators.Validator;
import org.slf4j.Logger;
Expand Down Expand Up @@ -56,6 +57,11 @@ protected User(ObjectId id, Map<String, Object> fields, Core core) {
}

public static User load(String username, Core core) {
// special case for the locally defined user, we don't store that in MongoDB.
if (core.getConfiguration().getRootUsername().equals(username)) {
return new LocalAdminUser(core);
}

DBObject query = new BasicDBObject();
query.put(USERNAME, username);

Expand Down Expand Up @@ -111,6 +117,10 @@ public static String saltPass(String password, String salt) {
return password + salt;
}

public boolean isReadOnly() {
return false;
}

@Override
public String getCollectionName() {
return COLLECTION;
Expand Down Expand Up @@ -142,4 +152,28 @@ public String getName() {
return fields.get(USERNAME).toString();
}

private static class LocalAdminUser extends User {
LocalAdminUser(Core core) {
super(null, Maps.<String, Object>newHashMap(), core);
}

@Override
public String getFullName() {
return "Administrator";
}

@Override
public String getName() {
return core.getConfiguration().getRootUsername();
}

public boolean isReadOnly() {
return true;
}

@Override
public ObjectId save() throws ValidationException {
throw new IllegalStateException("Cannot modify local root user, this is a bug.");
}
}
}

0 comments on commit 7955e96

Please sign in to comment.