1 17 package org.apache.geronimo.jetty; 18 19 import java.security.Principal ; 20 import java.util.HashMap ; 21 import java.util.Map ; 22 23 import org.apache.geronimo.security.ContextManager; 24 import org.mortbay.http.HttpRequest; 25 import org.mortbay.http.UserRealm; 26 import org.mortbay.jetty.Server; 27 28 29 32 public class JettyServer extends Server { 33 private final Map realmDelegates = new HashMap (); 34 35 public UserRealm addRealm(UserRealm realm) { 36 RealmDelegate delegate = (RealmDelegate) realmDelegates.get(realm.getName()); 37 if (delegate == null) { 38 delegate = new RealmDelegate(realm.getName()); 39 realmDelegates.put(realm.getName(), delegate); 40 } 41 delegate.delegate = realm; 42 43 return delegate; 44 } 45 46 public UserRealm getRealm(String realmName) { 47 RealmDelegate delegate = (RealmDelegate) realmDelegates.get(realmName); 48 49 if (delegate == null) { 50 delegate = new RealmDelegate(realmName); 51 realmDelegates.put(realmName, delegate); 52 } 53 return delegate; 54 } 55 56 public void removeRealm(UserRealm realm) { 57 realmDelegates.remove(realm.getName()); 58 } 59 60 private class RealmDelegate implements UserRealm { 61 62 private UserRealm delegate; 63 private final String name; 64 65 private RealmDelegate(String name) { 66 this.name = name; 67 } 68 69 public String getName() { 70 return name; 71 } 72 73 public Principal getPrincipal(String username) { 74 return delegate.getPrincipal(username); 75 } 76 77 public Principal authenticate(String username, Object credentials, HttpRequest request) { 78 return delegate.authenticate(username, credentials, request); 79 } 80 81 public boolean reauthenticate(Principal user) { 82 return delegate.reauthenticate(user); 83 } 84 85 public boolean isUserInRole(Principal user, String role) { 86 return delegate.isUserInRole(user, role); 87 } 88 89 public void disassociate(Principal user) { 90 delegate.disassociate(user); 91 } 92 93 public Principal pushRole(Principal user, String role) { 94 return delegate.pushRole(user, role); 95 } 96 97 public Principal popRole(Principal user) { 98 return delegate.popRole(user); 99 } 100 101 public void logout(Principal user) { 102 delegate.logout(user); 103 } 104 } 105 } 106 | Popular Tags |