1 /*
2 jGuard is a security framework based on top of jaas (java authentication and authorization security).
3 it is written for web applications, to resolve simply, access control problems.
4 version $Name$
5 http://sourceforge.net/projects/jguard/
6
7 Copyright (C) 2004 Charles GAY
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
23
24 jGuard project home page:
25 http://sourceforge.net/projects/jguard/
26
27 */
28
29 package net.sf.jguard.core.authentication.schemes;
30
31 import java.security.PermissionCollection;
32 import java.util.Collection;
33 import java.util.List;
34 import javax.security.auth.callback.Callback;
35 import javax.security.auth.callback.UnsupportedCallbackException;
36 import javax.security.auth.spi.LoginModule;
37 import net.sf.jguard.core.authentication.AccessContext;
38 import net.sf.jguard.core.authentication.AuthenticationException;
39
40 /**
41 * represents the way a user authenticate against a challenge <b>through a SPECIFIC underlying technology</b>.
42 * for example, a challenge like a username and password token, can be
43 * enforced in different ways(FORM and BASIC for example), and with different
44 * underlying technologies (HttpServlet and Swing for example).
45 * Note that multiple exchanges can be encountered between client and server to establish
46 * a securized communication. These exchanges are <b>NOT</b> decided by any {@link AuthenticationSchemeHandler}
47 * implementations but by {@link LoginModule}s which enforce an Authentication Scheme.
48 * AuthenticationSchemeHandler only help the loginModule to communicate with the client
49 * through its supported underlying technology.
50 * @author <a href="mailto:diabolo512@users.sourceforge.net">Charles Gay</a>
51 */
52 public interface AuthenticationSchemeHandler {
53
54 /**
55 * unique name of the Authentication Scheme.
56 * @return
57 */
58 public String getName();
59
60
61 /**
62 * return Callbacks classes needed by LoginModules to authenticate the client.
63 * @return
64 */
65 public Collection<Class> getCallbackTypes();
66
67
68 /**
69 * evaluate if the user <b>tries</b> to answer to the challenge.
70 * @param context
71 * @return
72 */
73 public boolean answerToChallenge(AccessContext context);
74
75
76 /**
77 * create a challenge in the underlying technology way.
78 * @param context
79 * @throws net.sf.jguard.core.authentication.AuthenticationException
80 */
81 public void buildChallenge(AccessContext accessContext)throws AuthenticationException;
82
83 public PermissionCollection getGrantedPermissions();
84
85 /**
86 * translate in the underlying technology the authentication success.
87 * @param context
88 */
89 public void authenticationSucceed(AccessContext context)throws AuthenticationException;
90
91 /**
92 * translate in the underlying technology the authentication failure.
93 * @param context
94 */
95 public void authenticationFailed(AccessContext context)throws AuthenticationException;
96
97
98 public void handleSchemeCallbacks(AccessContext context,List<Callback> cbks)throws UnsupportedCallbackException;
99 }