Coverage Report - org.kuali.rice.ksb.security.admin.web.JavaSecurityManagementAction
 
Classes in this File Line Coverage Branch Coverage Complexity
JavaSecurityManagementAction
0%
0/43
0%
0/4
2.667
 
 1  
 /*
 2  
  * Copyright 2007-2008 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
 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  
 package org.kuali.rice.ksb.security.admin.web;
 17  
 
 18  
 import java.io.ByteArrayOutputStream;
 19  
 import java.io.IOException;
 20  
 import java.security.KeyStore;
 21  
 import java.security.KeyStoreException;
 22  
 import java.security.NoSuchAlgorithmException;
 23  
 import java.security.cert.CertificateException;
 24  
 import java.util.Collection;
 25  
 
 26  
 import javax.servlet.http.HttpServletRequest;
 27  
 import javax.servlet.http.HttpServletResponse;
 28  
 
 29  
 import org.apache.struts.action.ActionForm;
 30  
 import org.apache.struts.action.ActionForward;
 31  
 import org.apache.struts.action.ActionMapping;
 32  
 import org.apache.struts.action.ActionMessages;
 33  
 import org.kuali.rice.core.util.JSTLConstants;
 34  
 import org.kuali.rice.core.util.RiceConstants;
 35  
 import org.kuali.rice.ksb.messaging.web.KSBAction;
 36  
 import org.kuali.rice.ksb.security.admin.ExportServlet;
 37  
 import org.kuali.rice.ksb.security.admin.KeyStoreEntryDataContainer;
 38  
 import org.kuali.rice.ksb.service.KSBServiceLocator;
 39  
 
 40  
 
 41  
 /**
 42  
  * Struts action for admin users to manage keys and keystore files for client applications 
 43  
  * 
 44  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 45  
  *
 46  
  */
 47  0
 public class JavaSecurityManagementAction extends KSBAction {
 48  
 
 49  0
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(JavaSecurityManagementAction.class);
 50  
 
 51  
     /**
 52  
      * @see org.kuali.rice.ksb.messaging.web.KSBAction#establishRequiredState(javax.servlet.http.HttpServletRequest, org.apache.struts.action.ActionForm)
 53  
      */
 54  
     @Override
 55  
     public ActionMessages establishRequiredState(HttpServletRequest request, ActionForm form) throws Exception {
 56  0
         request.setAttribute("rice_constant", new JSTLConstants(RiceConstants.class));
 57  0
         request.setAttribute("entryListPageSize", 30);
 58  0
         Collection<KeyStoreEntryDataContainer> keyStoreEntryList = KSBServiceLocator.getJavaSecurityManagementService().getListOfModuleKeyStoreEntries();
 59  0
         LOG.info("Found " + keyStoreEntryList.size() + " entries in module keystore");
 60  0
         request.setAttribute("keyStoreEntryList", keyStoreEntryList);
 61  0
         return null;
 62  
     }
 63  
 
 64  
     /**
 65  
      * @see org.kuali.rice.ksb.messaging.web.KSBAction#start(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 66  
      */
 67  
     @Override
 68  
     public ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 69  0
         return mapping.findForward("report");
 70  
     }
 71  
 
 72  
     /**
 73  
      *  Method to sort the list of keystore entries
 74  
      */
 75  
     public ActionForward sort(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 76  0
         return mapping.findForward("report");
 77  
     }
 78  
 
 79  
     /**
 80  
      *  Clear the form
 81  
      */
 82  
     public ActionForward clear(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 83  0
         form = new JavaSecurityManagementForm();
 84  0
         return mapping.findForward("restart");
 85  
     }
 86  
 
 87  
     /**
 88  
      *  Remove the entry associated with the given alias parameter
 89  
      */
 90  
     public ActionForward removeEntry(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 91  0
         String aliasToRemove = request.getParameter("aliasToRemove");
 92  0
         LOG.info("Removing alias " + aliasToRemove + " from module keystore file");
 93  0
         KSBServiceLocator.getJavaSecurityManagementService().removeClientCertificate(aliasToRemove);
 94  0
         return mapping.findForward("restart");
 95  
     }
 96  
 
 97  
     public ActionForward generateClientKeyStore(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 98  0
         JavaSecurityManagementForm managementForm = (JavaSecurityManagementForm)form;
 99  0
         ActionMessages errors = managementForm.validateGenerateClientKeystore(mapping, request);
 100  0
         if (errors == null || errors.isEmpty()) {
 101  0
             KeyStore clientKeyStore = KSBServiceLocator.getJavaSecurityManagementService().generateClientKeystore(managementForm.getAlias(), managementForm.getPassword());
 102  0
             byte[] data = {};
 103  0
             ByteArrayOutputStream baos = null;
 104  
             try {
 105  0
                 baos = new ByteArrayOutputStream();
 106  0
                 clientKeyStore.store(baos, managementForm.getPassword().toCharArray());
 107  0
                 data = baos.toByteArray();
 108  0
             } catch (KeyStoreException e) {
 109  0
                 e.printStackTrace();
 110  0
                 throw new RuntimeException(e);
 111  0
             } catch (NoSuchAlgorithmException e) {
 112  0
                 e.printStackTrace();
 113  0
                 throw new RuntimeException(e);
 114  0
             } catch (CertificateException e) {
 115  0
                 e.printStackTrace();
 116  0
                 throw new RuntimeException(e);
 117  
             } finally {
 118  0
                 try {
 119  0
                     baos.close();
 120  0
                 } catch (IOException e) {}
 121  0
             }
 122  
 
 123  0
             form = new JavaSecurityManagementForm();
 124  0
             request.getSession().setAttribute(ExportServlet.CLIENT_KEYSTORE_DATA, data);
 125  0
             return new ActionForward(ExportServlet.generateExportPath(managementForm.getAlias() + "_keystore", request), true);
 126  
         } else {
 127  
             // found at least one error
 128  0
             saveErrors(request, errors);
 129  0
             return mapping.findForward("report");
 130  
         }
 131  
     }
 132  
 }