📄 createrealmconfigurationaction.java
字号:
/* * Copyright 2005-2007 WSO2, Inc. (http://wso2.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.wso2.solutions.identity.admin.ui.action;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.apache.struts2.StrutsStatics;import org.wso2.solutions.identity.admin.RealmConfigAdmin;import org.wso2.solutions.identity.admin.ui.UIConstants;import org.wso2.solutions.identity.admin.ui.action.ShowAddRealmConfigurationAction.ConfigProperty;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpSession;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.List;import com.opensymphony.xwork2.ActionContext;public class CreateRealmConfigurationAction extends ManagedAction { private static final long serialVersionUID = -5877313929595725808L; private static Log log = LogFactory.getLog(CreateRealmConfigurationAction.class); private ArrayList missingProperties; private HashMap propertyMap; public String execute() throws Exception { HttpServletRequest request = (HttpServletRequest) ActionContext .getContext().get(StrutsStatics.HTTP_REQUEST); HttpSession session = request.getSession(); String realmClassName = (String) session .getAttribute(UIConstants.REALM_CLASS_NAME); List configProperties = (List) session .getAttribute(UIConstants.REALM_CONFIG_PROPERTIES); // If something wrong with the session if (realmClassName == null || configProperties == null) { return ERROR; } propertyMap = new HashMap(); missingProperties = new ArrayList(); for (Iterator iterator = configProperties.iterator(); iterator .hasNext();) { ConfigProperty configProp = (ConfigProperty) iterator.next(); String prop = configProp.getPropertyName(); String propValue = request.getParameter(prop); if ((propValue == null || "".equals(propValue.trim())) && configProp.getIsRequired()) { // The property is missing missingProperties.add(prop); } else { propertyMap.put(prop, propValue); } } String configName = request .getParameter(UIConstants.NEW_REALM_CONFIG_NAME); if (configName == null || configName.trim().length() == 0) { missingProperties.add("Configuration Name"); } // If we have any missing properties then show error page if (missingProperties.size() > 0) { for (Iterator iterator = missingProperties.iterator(); iterator .hasNext();) { String propName = (String) iterator.next(); this.addErrorMessage(getText( "add_realm_config_required_prop_missing", new String[] { propName })); } return ERROR; } RealmConfigAdmin admin = new RealmConfigAdmin(); try { admin.createNewRealmConfiguration(realmClassName, configName, propertyMap); } catch (RuntimeException e) { log.error(e.getMessage(), e); this.addErrorMessage(getText(e.getMessage())); return ERROR; } session.setAttribute(UIConstants.REALM_CLASS_NAME, null); return SUCCESS; } public ArrayList getMissingProperties() { return missingProperties; } public HashMap getPropertyMap() { return propertyMap; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -