KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > methodhead > shim > LoginAction


1 /*
2  * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
3  *
4  * This file is part of TransferCM.
5  *
6  * TransferCM is free software; you can redistribute it and/or modify it under the
7  * terms of the GNU General Public License as published by the Free Software
8  * Foundation; either version 2 of the License, or (at your option) any later
9  * version.
10  *
11  * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
18  * Fifth Floor, Boston, MA 02110-1301 USA
19  */

20
21 package com.methodhead.shim;
22
23 import org.apache.struts.action.Action;
24 import org.apache.struts.action.ActionMapping;
25 import org.apache.struts.action.ActionForm;
26 import org.apache.struts.action.ActionForward;
27 import org.apache.log4j.Logger;
28
29 import javax.servlet.http.HttpServletRequest JavaDoc;
30 import javax.servlet.http.HttpServletResponse JavaDoc;
31
32 import com.methodhead.aikp.IntKey;
33 import com.methodhead.auth.AuthPolicy;
34 import com.methodhead.util.OperationContext;
35 import com.methodhead.sitecontext.SiteContext;
36 import com.methodhead.auth.AuthUtil;
37 import org.apache.commons.lang.StringUtils;
38
39 public class LoginAction
40 extends
41   com.methodhead.auth.LoginAction {
42
43   // constructors /////////////////////////////////////////////////////////////
44

45   // constants ////////////////////////////////////////////////////////////////
46

47   // classes //////////////////////////////////////////////////////////////////
48

49   // methods //////////////////////////////////////////////////////////////////
50

51   protected ActionForward doLogin(
52     OperationContext op,
53     AuthPolicy policy )
54   throws
55     Exception JavaDoc {
56
57     //
58
// log in as normal
59
//
60
ActionForward forward = super.doLogin( op, policy );
61
62     //
63
// successful login?
64
//
65
if ( AuthUtil.getUser( op.request ) != null ) {
66
67       //
68
// has a site been specified?
69
//
70
String JavaDoc site = ( String JavaDoc )op.form.get( "site" );
71
72       if ( !StringUtils.isBlank( site ) ) {
73
74         if ( logger_.isDebugEnabled() ) {
75           logger_.debug( "Setting up shim session for site \"" + site + "\"" );
76         }
77
78         //
79
// attempt to load a site context
80
//
81
SiteContext context = new SiteContext();
82
83         String JavaDoc path = "";
84         if ( site.indexOf( "/" ) != -1 ) {
85           String JavaDoc[] strings = site.split( "/" );
86           if ( strings.length == 2 ) {
87             site = strings[ 0 ];
88             path = strings[ 1 ];
89           }
90         }
91
92         if ( context.loadForDomainAndPath( site, path ) )
93           ShimUtils.setUpShimSession( op.request, context );
94       }
95     }
96
97     return forward;
98   }
99
100   protected ActionForward doLogout(
101     OperationContext op,
102     AuthPolicy policy )
103   throws
104     Exception JavaDoc {
105
106     ActionForward forward = super.doLogout( op, policy );
107
108     if ( logger_.isDebugEnabled() ) {
109       logger_.debug( "Tearing down shim session" );
110     }
111
112     ShimUtils.tearDownShimSession( op.request );
113
114     return forward;
115   }
116
117   // properties ///////////////////////////////////////////////////////////////
118

119   // attributes ///////////////////////////////////////////////////////////////
120

121   private static Logger logger_ = Logger.getLogger( LoginAction.class );
122 }
123
Popular Tags