diff options
Diffstat (limited to 'org.eclipse.jgit.junit.http/src')
-rw-r--r-- | org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AppServer.java | 35 | ||||
-rw-r--r-- | org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/RecordingLogger.java | 6 |
2 files changed, 25 insertions, 16 deletions
diff --git a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AppServer.java b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AppServer.java index 9ef4068cc4..28c0f21111 100644 --- a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AppServer.java +++ b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AppServer.java @@ -46,25 +46,25 @@ package org.eclipse.jgit.junit.http; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import java.io.IOException; import java.net.InetAddress; import java.net.URI; import java.net.URISyntaxException; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import org.eclipse.jetty.security.AbstractLoginService; import org.eclipse.jetty.security.Authenticator; import org.eclipse.jetty.security.ConstraintMapping; import org.eclipse.jetty.security.ConstraintSecurityHandler; -import org.eclipse.jetty.security.MappedLoginService; import org.eclipse.jetty.security.authentication.BasicAuthenticator; import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpConnectionFactory; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; -import org.eclipse.jetty.server.UserIdentity; import org.eclipse.jetty.server.handler.ContextHandlerCollection; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.util.security.Constraint; @@ -168,38 +168,41 @@ public class AppServer { return ctx; } - static class TestMappedLoginService extends MappedLoginService { + static class TestMappedLoginService extends AbstractLoginService { private String role; + protected final ConcurrentMap<String, UserPrincipal> users = new ConcurrentHashMap<>(); + TestMappedLoginService(String role) { this.role = role; } @Override - protected UserIdentity loadUser(String who) { - return null; - } - - @Override - protected void loadUsers() throws IOException { - putUser(username, new Password(password), new String[] { role }); + protected void doStart() throws Exception { + UserPrincipal p = new UserPrincipal(username, + new Password(password)); + users.put(username, p); + super.doStart(); } @Override - protected String[] loadRoleInfo(KnownUser user) { - return null; + protected String[] loadRoleInfo(UserPrincipal user) { + if (users.get(user.getName()) == null) + return null; + else + return new String[] { role }; } @Override - protected KnownUser loadUserInfo(String usrname) { - return null; + protected UserPrincipal loadUserInfo(String user) { + return users.get(user); } } private void auth(ServletContextHandler ctx, Authenticator authType) { final String role = "can-access"; - MappedLoginService users = new TestMappedLoginService(role); + AbstractLoginService users = new TestMappedLoginService(role); ConstraintMapping cm = new ConstraintMapping(); cm.setConstraint(new Constraint()); cm.getConstraint().setAuthenticate(true); diff --git a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/RecordingLogger.java b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/RecordingLogger.java index 415398da26..4e35ff6422 100644 --- a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/RecordingLogger.java +++ b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/RecordingLogger.java @@ -161,6 +161,12 @@ public class RecordingLogger implements Logger { @Override public void warn(String msg, Object... args) { synchronized (warnings) { + int i = 0; + int index = msg.indexOf("{}"); + while (index >= 0) { + msg = msg.replaceFirst("\\{\\}", "{" + i++ + "}"); + index = msg.indexOf("{}"); + } warnings.add(new Warning(MessageFormat.format(msg, args))); } } |