KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > authentication > UserPasswordAuthenticator


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

17
18 package org.objectweb.jac.aspects.authentication;
19
20 import org.objectweb.jac.aspects.user.UserAC;
21 import org.objectweb.jac.core.ACManager;
22 import org.objectweb.jac.util.Log;
23
24 /**
25  * This Authenticator asks for a username and password and checks them
26  * by using the user aspect.
27  *
28  * @see org.objectweb.jac.aspects.user.UserAC */

29
30 public class UserPasswordAuthenticator extends PasswordAuthenticator {
31
32     UserAC userAC;
33     String JavaDoc userAspectName;
34
35     /**
36      * Constructor.
37      *
38      * @param userAspectName the name of the user aspect for the
39      * configured application (note that we should implement a means to
40      * resolve an aspect). It has the form
41      * &lt;application_name&gt;.&lt;aspect_name&gt;
42      */

43     public UserPasswordAuthenticator(String JavaDoc userAspectName) {
44         this.userAspectName=userAspectName;
45     }
46
47     /**
48      * Implements the password checking.
49      *
50      * <p>This method asks to the user aspect which is the currently
51      * user's instance of the current session and checks if the
52      * username and password values corresponds to the values of the
53      * corresponding fields as declared in the user aspect.
54      *
55      * @param username the username to check
56      * @param password the password to check
57      * @return true if matching, false otherwise
58      *
59      * @see org.objectweb.jac.aspects.user.UserAC
60      * @see org.objectweb.jac.aspects.user.UserAC#setUserClass(ClassItem,String,String)
61      * @see org.objectweb.jac.aspects.user.UserAC#getUserFromLogin(String)
62      * @see org.objectweb.jac.aspects.user.UserAC#getUserLogin(Object)
63      * @see org.objectweb.jac.aspects.user.UserAC#getUserPassword(Object)
64      */

65     boolean checkPassword(String JavaDoc username, String JavaDoc password) {
66         if (userAC==null) {
67             userAC=(UserAC)ACManager.get().getObject(userAspectName);
68         }
69         if (userAC==null) {
70             Log.error("UserPasswordAuthenticator: cannot perform "+
71                       "password authentication, no user aspect found.");
72             return false;
73         } else {
74             Object JavaDoc user=userAC.getUserFromLogin(username);
75             Log.trace("authentication","checking "+username+"=="+
76                       userAC.getUserLogin(user)+" && "+password+"=="+
77                       userAC.getUserPassword(user)+" (user="+user+")");
78             return username.equals(userAC.getUserLogin(user)) &&
79                 password.equals(userAC.getUserPassword(user));
80         }
81     }
82
83 }
84
Popular Tags