KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2   Copyright (C) 2001 Laurent Martelli <laurent@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.gui.DisplayContext;
21 import org.objectweb.jac.aspects.gui.GuiAC;
22 import org.objectweb.jac.core.Collaboration;
23 import org.objectweb.jac.core.Display;
24 import org.objectweb.jac.core.rtti.ClassRepository;
25 import org.objectweb.jac.core.rtti.MethodItem;
26 import org.objectweb.jac.util.Log;
27
28 /**
29  * This Authenticator just ask the username of the user without asking
30  * a password. It just trusts the user to enter the correct
31  * username. It needs a DisplayContext attribute in order to be able
32  * to interact with the user.
33  */

34 public class TrustingAuthenticator implements Authenticator {
35     public String JavaDoc authenticate() throws AuthenticationFailedException {
36         DisplayContext context =
37             (DisplayContext)Collaboration.get().getAttribute(GuiAC.DISPLAY_CONTEXT);
38         if (context!=null) {
39             Display display = context.getDisplay();
40             MethodItem method =
41                 ClassRepository.get().getClass(this).getMethod("askUsername");
42             Object JavaDoc[] parameters = new Object JavaDoc[method.getParameterTypes().length];
43             if (!display.showInput(this,method,parameters)) {
44                 return null;
45             }
46             return (String JavaDoc)parameters[0];
47                
48         } else {
49             Log.warning("No display context available, cannot authenticate user");
50             return null;
51         }
52     }
53     public void askUsername(String JavaDoc username) {
54     }
55 }
56
Popular Tags