KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > webconnector > security > LucaneRealm


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.webconnector.security;
20
21 import java.security.Principal JavaDoc;
22
23 import org.lucane.common.ConnectInfo;
24 import org.lucane.common.crypto.MD5;
25 import org.lucane.server.ConnectInfoManager;
26 import org.lucane.server.Server;
27 import org.lucane.server.auth.AuthRequest;
28 import org.lucane.server.auth.AuthResponse;
29 import org.mortbay.http.HttpRequest;
30 import org.mortbay.http.UserRealm;
31
32 public class LucaneRealm implements UserRealm
33 {
34     private String JavaDoc host;
35     private String JavaDoc name;
36     private int port;
37     
38     public LucaneRealm(String JavaDoc name, int port)
39     {
40         this.host = ConnectInfoManager.getInstance().getServerInfo().getHostName();
41         this.name = name;
42         this.port = port;
43     }
44     
45     public String JavaDoc getName()
46     {
47         return this.name;
48     }
49
50     public Principal JavaDoc getPrincipal(String JavaDoc user)
51     {
52         ConnectInfo info = new ConnectInfo(user, this.host, this.port, "nokey", "webclient");
53         return new LucanePrincipal(user, info);
54     }
55
56     public Principal JavaDoc authenticate(String JavaDoc user, Object JavaDoc credentials, HttpRequest request)
57     {
58         LucanePrincipal lp = (LucanePrincipal)getPrincipal(user);
59         
60         AuthRequest auth = new AuthRequest(lp.getInfo(), MD5.encode((String JavaDoc)credentials));
61         AuthResponse response = Server.getInstance().getAuthenticator().authenticate(auth);
62                 
63         if(response.getValue() == AuthResponse.AUTH_ACCEPTED)
64             return lp;
65         return null;
66     }
67
68     public void logout(Principal JavaDoc user)
69     {
70         LucanePrincipal lp = (LucanePrincipal)user;
71         ConnectInfoManager.getInstance().removeConnectInfo(lp.getInfo());
72     }
73     
74     public boolean reauthenticate(Principal JavaDoc user)
75     {
76         return true;
77     }
78
79     public void disassociate(Principal JavaDoc arg0)
80     {
81     }
82
83     //-- roles arent handled
84
public boolean isUserInRole(Principal JavaDoc user, String JavaDoc role)
85     {
86         return false;
87     }
88
89     public Principal JavaDoc pushRole(Principal JavaDoc user, String JavaDoc role)
90     {
91         return user;
92     }
93
94     public Principal JavaDoc popRole(Principal JavaDoc user)
95     {
96         return user;
97     }
98 }
Popular Tags