Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AppServer.java')
-rw-r--r--org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AppServer.java35
1 files changed, 20 insertions, 15 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 a66348452c..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,36 +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;
+ protected void doStart() throws Exception {
+ UserPrincipal p = new UserPrincipal(username,
+ new Password(password));
+ users.put(username, p);
+ super.doStart();
}
@Override
- protected void loadUsers() throws IOException {
- putUser(username, new Password(password), new String[] { role });
- }
-
- 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 };
}
- protected KnownUser loadUserInfo(String usrname) {
- return null;
+ @Override
+ 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);

Back to the top