KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > cactus > sample > SampleServlet


1 /*
2  * ========================================================================
3  *
4  * Copyright 2001-2003 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * ========================================================================
19  */

20 package org.apache.maven.cactus.sample;
21
22 import javax.servlet.http.HttpServlet JavaDoc;
23 import javax.servlet.http.HttpServletRequest JavaDoc;
24 import javax.servlet.http.HttpSession JavaDoc;
25
26 /**
27  * Sample servlet that implements some very simple business logic. The goal is
28  * to provide some functional tests for Cactus and examples for Cactus users.
29  * This servlet simply checks is a user is authenticated
30  *
31  * @version $Id: SampleServlet.java,v 1.3 2004/02/29 16:34:44 vmassol Exp $
32  */

33 public class SampleServlet extends HttpServlet JavaDoc
34 {
35     /**
36      *Take a request object and return whether the user is authenticated o not.
37      *
38      * @param theRequest the HttpServletRequest object
39      *
40      * @return boolean whether the request is by an authenticated user or not
41      *
42      */

43     public boolean isAuthenticated(HttpServletRequest JavaDoc theRequest)
44     {
45         HttpSession JavaDoc session = theRequest.getSession(false);
46
47         if (session == null)
48         {
49             return false;
50         }
51
52         String JavaDoc authenticationAttribute =
53             (String JavaDoc) session.getAttribute("authenticated");
54
55         return Boolean.valueOf(authenticationAttribute).booleanValue();
56     }
57 }
58
Popular Tags