--- org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AppServer.java.sav 2016-09-21 16:06:18.000000000 +0300
+++ org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AppServer.java 2016-10-04 20:43:39.992864623 +0300
@@ -53,11 +53,14 @@ import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ConcurrentHashMap;
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.AbstractLoginService;
+import org.eclipse.jetty.security.AbstractLoginService.UserPrincipal;
import org.eclipse.jetty.security.authentication.BasicAuthenticator;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.HttpConfiguration;
@@ -168,38 +171,40 @@ 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<String, UserPrincipal>();
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 UserPrincipal loadUserInfo(String who) {
+ return _users.get(who);
}
-
- protected String[] loadRoleInfo(
- @SuppressWarnings("unused") KnownUser user) {
- return null;
+
+ @Override
+ protected String[] loadRoleInfo(UserPrincipal who) {
+ if (_users.get(who.getName()) == null)
+ return null;
+ else
+ return new String[] { role };
}
- protected KnownUser loadUserInfo(
- @SuppressWarnings("unused") String usrname) {
- return null;
- }
}
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);