KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > jetty > JettyServer


1 /**
2  *
3  * Copyright 2004 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.jetty;
18
19 import java.security.Principal JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.Map JavaDoc;
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 /**
30  * @version $Rev: 111239 $ $Date: 2004-12-08 01:29:11 -0800 (Wed, 08 Dec 2004) $
31  */

32 public class JettyServer extends Server {
33     private final Map JavaDoc realmDelegates = new HashMap JavaDoc();
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 JavaDoc 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 JavaDoc name;
64
65         private RealmDelegate(String JavaDoc name) {
66             this.name = name;
67         }
68
69         public String JavaDoc getName() {
70             return name;
71         }
72
73         public Principal JavaDoc getPrincipal(String JavaDoc username) {
74             return delegate.getPrincipal(username);
75         }
76
77         public Principal JavaDoc authenticate(String JavaDoc username, Object JavaDoc credentials, HttpRequest request) {
78             return delegate.authenticate(username, credentials, request);
79         }
80
81         public boolean reauthenticate(Principal JavaDoc user) {
82             return delegate.reauthenticate(user);
83         }
84
85         public boolean isUserInRole(Principal JavaDoc user, String JavaDoc role) {
86             return delegate.isUserInRole(user, role);
87         }
88
89         public void disassociate(Principal JavaDoc user) {
90             delegate.disassociate(user);
91         }
92
93         public Principal JavaDoc pushRole(Principal JavaDoc user, String JavaDoc role) {
94             return delegate.pushRole(user, role);
95         }
96
97         public Principal JavaDoc popRole(Principal JavaDoc user) {
98             return delegate.popRole(user);
99         }
100
101         public void logout(Principal JavaDoc user) {
102             delegate.logout(user);
103         }
104     }
105 }
106
Popular Tags