1 //
2 // Copyright (c) 2003, Caltha - Gajda, Krzewski, Mach, Potempski Sp.J.
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 // * Neither the name of the Caltha - Gajda, Krzewski, Mach, Potempski Sp.J.
14 // nor the names of its contributors may be used to endorse or promote products
15 // derived from this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
21 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23 // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 // POSSIBILITY OF SUCH DAMAGE.
27 //
28
29 package org.objectledge.authentication;
30
31 import java.security.Principal;
32
33 import org.objectledge.context.Context;
34
35 /***
36 * The authentication context contains all information about web application user.
37 *
38 * @author <a href="mailto:pablo@caltha.pl">Pawel Potempski</a>
39 * @author <a href="mailto:dgajda@caltha.pl">Damian Gajda</a>
40 * @version $Id: AuthenticationContext.java,v 1.1 2004/06/29 13:40:13 zwierzem Exp $
41 */
42 public class AuthenticationContext
43 {
44 /***
45 * Useful method to retrieve authentication context from context.
46 *
47 * @param context the context.
48 * @return the authentication context.
49 */
50 public static AuthenticationContext getAuthenticationContext(Context context)
51 {
52 return (AuthenticationContext)context.getAttribute(AuthenticationContext.class);
53 }
54
55 /*** the user. */
56 private Principal user;
57
58 /*** is the user authenticated */
59 private boolean authenticated;
60
61 /***
62 * Construct new authentication context.
63 */
64 public AuthenticationContext()
65 {
66 this.user = null;
67 this.authenticated = false;
68 }
69
70 /***
71 * Returns the user performing the request.
72 *
73 * @return the user.
74 */
75 public Principal getUserPrincipal()
76 {
77 return user;
78 }
79
80 /***
81 * Checks whether user is authenticated by system.
82 *
83 * @return <code>true</code> if the current user is not an anounymous.
84 */
85 public boolean isUserAuthenticated()
86 {
87 return authenticated;
88 }
89
90 /***
91 * Sets the user principal.
92 *
93 * @param user the current authenticated user.
94 * @param authenticated <code>true</code> if named user is authenticated.
95 */
96 public void setUserPrincipal(Principal user, boolean authenticated)
97 {
98 this.user = user;
99 this.authenticated = authenticated;
100 }
101 }