KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webapp > admin > valve > SaveSingleSignOnValveAction


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

16
17 package org.apache.webapp.admin.valve;
18
19 import java.util.Locale JavaDoc;
20 import java.io.IOException JavaDoc;
21 import javax.management.Attribute JavaDoc;
22 import javax.management.MBeanServer JavaDoc;
23 import javax.management.MBeanServerFactory JavaDoc;
24 import javax.management.QueryExp JavaDoc;
25 import javax.management.Query JavaDoc;
26 import javax.management.ObjectInstance JavaDoc;
27 import javax.management.ObjectName JavaDoc;
28 import javax.management.JMException JavaDoc;
29 import javax.servlet.ServletException JavaDoc;
30 import javax.servlet.http.HttpServletRequest JavaDoc;
31 import javax.servlet.http.HttpServletResponse JavaDoc;
32 import javax.servlet.http.HttpSession JavaDoc;
33 import org.apache.struts.action.Action;
34 import org.apache.struts.action.ActionError;
35 import org.apache.struts.action.ActionErrors;
36 import org.apache.struts.action.ActionForm;
37 import org.apache.struts.action.ActionForward;
38 import org.apache.struts.action.ActionMapping;
39 import org.apache.struts.util.MessageResources;
40 import org.apache.webapp.admin.ApplicationServlet;
41
42 /**
43  * The <code>Action</code> that completes <em>Add Valve</em> and
44  * <em>Edit Valve</em> transactions for Single Sign On valve.
45  *
46  * @author Manveen Kaur
47  * @version $Revision: 1.9 $ $Date: 2004/10/18 06:37:55 $
48  */

49
50 public final class SaveSingleSignOnValveAction extends Action {
51
52
53     // ----------------------------------------------------- Instance Variables
54

55     /**
56      * The MBeanServer we will be interacting with.
57      */

58     private MBeanServer JavaDoc mBServer = null;
59     
60     // --------------------------------------------------------- Public Methods
61

62     
63     /**
64      * Process the specified HTTP request, and create the corresponding HTTP
65      * response (or forward to another web component that will create it).
66      * Return an <code>ActionForward</code> instance describing where and how
67      * control should be forwarded, or <code>null</code> if the response has
68      * already been completed.
69      *
70      * @param mapping The ActionMapping used to select this instance
71      * @param actionForm The optional ActionForm bean for this request (if any)
72      * @param request The HTTP request we are processing
73      * @param response The HTTP response we are creating
74      *
75      * @exception IOException if an input/output error occurs
76      * @exception ServletException if a servlet exception occurs
77      */

78     public ActionForward execute(ActionMapping mapping,
79                                  ActionForm form,
80                                  HttpServletRequest JavaDoc request,
81                                  HttpServletResponse JavaDoc response)
82         throws IOException JavaDoc, ServletException JavaDoc {
83         
84         // Acquire the resources that we need
85
HttpSession JavaDoc session = request.getSession();
86         Locale JavaDoc locale = getLocale(request);
87         MessageResources resources = getResources(request);
88         
89         // Acquire a reference to the MBeanServer containing our MBeans
90
try {
91             mBServer = ((ApplicationServlet) getServlet()).getServer();
92         } catch (Throwable JavaDoc t) {
93             throw new ServletException JavaDoc
94             ("Cannot acquire MBeanServer reference", t);
95         }
96         
97         // Identify the requested action
98
SingleSignOnValveForm vform = (SingleSignOnValveForm) form;
99         String JavaDoc adminAction = vform.getAdminAction();
100         String JavaDoc vObjectName = vform.getObjectName();
101         String JavaDoc parent = vform.getParentObjectName();
102         String JavaDoc valveType = vform.getValveType();
103                
104         // Perform a "Create Valve" transaction (if requested)
105
if ("Create".equals(adminAction)) {
106
107             try {
108                 // Ensure that only one single sign on valve exists
109
ObjectName JavaDoc pname = new ObjectName JavaDoc(parent);
110                 ObjectName JavaDoc oname =
111                         new ObjectName JavaDoc(pname.getDomain() +
112                                     ":type=Valve,name=SingleSignOn");
113                 
114                 if (mBServer.isRegistered(oname)) {
115                     ActionErrors errors = new ActionErrors();
116                     errors.add("singleSignOnValve",
117                                new ActionError("error.singleSignOn.exists"));
118                     saveErrors(request, errors);
119                     return (new ActionForward(mapping.getInput()));
120                 }
121             } catch (Exception JavaDoc e) {
122                 getServlet().log
123                     (resources.getMessage(locale, "users.error.invoke",
124                                           adminAction), e);
125                 response.sendError
126                     (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
127                      resources.getMessage(locale, "users.error.invoke",
128                                           adminAction));
129                 return (null);
130
131             }
132             
133             vObjectName = ValveUtil.createValve(parent, valveType,
134                                 response, request, mapping,
135                                 (ApplicationServlet) getServlet());
136                       
137         }
138
139         // Perform attribute updates as requested
140
String JavaDoc attribute = null;
141     
142         // Forward to the success reporting page
143
session.removeAttribute(mapping.getAttribute());
144         return (mapping.findForward("Save Successful"));
145     }
146 }
147
Popular Tags