001/**
002 * Copyright 2005-2015 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.ksb.security.admin.web;
017
018import java.security.KeyStoreException;
019
020import javax.servlet.http.HttpServletRequest;
021
022import org.apache.commons.lang.StringUtils;
023import org.apache.struts.action.ActionErrors;
024import org.apache.struts.action.ActionForm;
025import org.apache.struts.action.ActionMapping;
026import org.apache.struts.action.ActionMessage;
027import org.kuali.rice.ksb.service.KSBServiceLocator;
028
029/**
030 * Struts action form for the {@link JavaSecurityManagementAction} 
031 * 
032 * @author Kuali Rice Team (rice.collab@kuali.org)
033 *
034 */
035public class JavaSecurityManagementForm extends ActionForm {
036
037    private static final long serialVersionUID = -46462912979586142L;
038
039    private String alias;
040    private String password;
041    private String passwordVerify;
042    
043    /**
044     * This method is used to check for completeness of the form as well as verification of the desired password
045     */
046    public ActionErrors validateGenerateClientKeystore(ActionMapping mapping, HttpServletRequest request) {
047        ActionErrors errors = new ActionErrors();
048        // check that all data is filled in
049        if (StringUtils.isBlank(getAlias())) {
050            errors.add("property", new ActionMessage("Alias must have a valid value.",false));
051        }
052        if (StringUtils.isBlank(getPassword()) || StringUtils.isBlank(getPasswordVerify()) ) {
053            errors.add("property", new ActionMessage("Password must have a valid value in both fields.",false));
054        }
055        if (errors.isEmpty()) {
056            // if password and passwordVerify are not equal error out
057            if (!StringUtils.equals(getPassword(), getPasswordVerify())) {
058                errors.add("property", new ActionMessage("Passwords do not match.",false));
059            }
060        }
061        if (errors.isEmpty()) {
062            try {
063                if (KSBServiceLocator.getJavaSecurityManagementService().isAliasInKeystore(getAlias())) {
064                    errors.add("property", new ActionMessage("Alias '" + getAlias() + "' already exists in keystore.",false));
065                }
066            } catch (KeyStoreException e) {
067                errors.add("property", new ActionMessage("Could not check keystore file for alias '" + getAlias(),false));
068            }
069        }
070        return errors;
071    }
072
073    public String getAlias() {
074        return this.alias;
075    }
076    public void setAlias(String alias) {
077        if (alias == null) {
078            this.alias = null;
079        } else {
080            this.alias = alias.trim();
081        }
082    }
083    public String getPassword() {
084        return this.password;
085    }
086    public void setPassword(String password) {
087        this.password = password;
088    }
089    public String getPasswordVerify() {
090        return this.passwordVerify;
091    }
092    public void setPasswordVerify(String passwordVerify) {
093        this.passwordVerify = passwordVerify;
094    }
095
096}