KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > discRack > pres > services > LoginServices


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: LoginServices.java,v 1.4 2004/02/05 10:24:50 slobodan Exp $
22  */

23 package org.enhydra.barracuda.discRack.pres.services;
24
25 import java.util.*;
26 import javax.servlet.*;
27 import javax.servlet.http.*;
28
29 import org.enhydra.barracuda.core.event.*;
30 import org.enhydra.barracuda.plankton.data.*;
31 import org.enhydra.barracuda.core.util.http.*;
32
33 import org.enhydra.barracuda.discRack.biz.person.Person;
34
35 /**
36  * This class provides basic Login services. You can see whether
37  * the user is logged in, get the current user (Person), log them in
38  * or out.
39  */

40 public class LoginServices {
41
42     //private constants
43
private static String JavaDoc PERSON = LoginServices.class.getName()+".Person";
44
45     /**
46      * See if the current user is actually logged in
47      */

48     public static boolean isLoggedIn(HttpSession session) {
49 //Debug.println (new LoginServices(),0,"isLoggedIn:"+session.getAttribute(PERSON));
50
return (session.getAttribute(PERSON)!=null);
51     }
52
53     /**
54      * Get the Person record for the current user
55      */

56     public static Person getCurrentUser(HttpSession session) {
57         return (Person) session.getAttribute(PERSON);
58     }
59
60     /**
61      * Actually log a user in by storing the Person account in the
62      * session
63      */

64     public static void logIn(HttpSession session, Person person) {
65 //Debug.println (new LoginServices(),0,"logging in:"+person);
66
session.setAttribute(PERSON, person);
67     }
68
69     /**
70      * Actually log a user out by removing the Person account from the
71      * session
72      */

73     public static void logOut(HttpSession session) {
74 //Debug.println (new LoginServices(),0,"logging out");
75
session.removeAttribute(PERSON);
76     }
77 }
78
Popular Tags