KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > policyframework > actions > PrincipalInformationAction


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.policyframework.actions;
21
22 import java.util.Arrays JavaDoc;
23
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25 import javax.servlet.http.HttpServletResponse JavaDoc;
26
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29 import org.apache.struts.action.ActionForm;
30 import org.apache.struts.action.ActionForward;
31 import org.apache.struts.action.ActionMapping;
32
33 import com.sslexplorer.core.UserDatabaseManager;
34 import com.sslexplorer.core.actions.AuthenticatedDispatchAction;
35 import com.sslexplorer.policyframework.Principal;
36 import com.sslexplorer.policyframework.forms.PrincipalInformationForm;
37 import com.sslexplorer.security.Constants;
38 import com.sslexplorer.security.LogonControllerFactory;
39 import com.sslexplorer.security.Role;
40 import com.sslexplorer.security.SessionInfo;
41
42 /**
43  * Action that display details about a {@link Principal}.
44  *
45  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
46  */

47 public class PrincipalInformationAction extends AuthenticatedDispatchAction {
48
49     final static Log log = LogFactory.getLog(PrincipalInformationAction.class);
50
51     /* (non-Javadoc)
52      * @see org.apache.struts.actions.DispatchAction#unspecified(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
53      */

54     public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
55             try {
56                 String JavaDoc principalType = request.getParameter("principalType");
57                 String JavaDoc principalName = request.getParameter("principalName");
58                 Principal principal;
59                 if("account".equals(principalType)) {
60                     principal = UserDatabaseManager.getInstance().getUserDatabase(LogonControllerFactory.getInstance().getUser(request).getRealm()).getAccount(principalName);
61                 } else if("role".equals(principalType)) {
62                     principal = UserDatabaseManager.getInstance().getUserDatabase(LogonControllerFactory.getInstance().getUser(request).getRealm()).getRole(principalName);
63                 } else {
64                     throw new Exception JavaDoc();
65                 }
66                 request.setAttribute(Constants.REQ_ATTR_INFO_RESOURCE, principal);
67                 return principalInformation(mapping, form, request, response);
68             } catch (Exception JavaDoc e) {
69               log.error("Failed to get principal information. ", e);
70               response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
71             }
72             return null;
73         }
74         
75     /**
76      * @param mapping
77      * @param form
78      * @param request
79      * @param response
80      * @return ActionForward
81      * @throws Exception
82      */

83     public ActionForward principalInformation(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
84         PrincipalInformationForm informationForm = (PrincipalInformationForm) form;
85         Principal principal = (Principal) request.getAttribute(Constants.REQ_ATTR_INFO_RESOURCE);
86         informationForm.initialise(principal);
87         String JavaDoc principalType = request.getParameter("principalType");
88         if("role".equals(principalType)) {
89             informationForm.setAccounts(Arrays.asList(UserDatabaseManager.getInstance().getUserDatabase(LogonControllerFactory.getInstance().getUser(request).getRealm()).getUsersInRole((Role)principal)));
90         }
91         return mapping.findForward("display");
92     }
93     
94     /* (non-Javadoc)
95      * @see com.sslexplorer.core.actions.CoreAction#getNavigationContext(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
96      */

97     public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
98         return SessionInfo.MANAGEMENT_CONSOLE_CONTEXT;
99     }
100 }
Popular Tags