Java tutorial
/* Copyright (C) 2009 NTT DATA Corporation This program is free software; you can redistribute it and/or Modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ package com.clustercontrol.accesscontrol.util; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.eclipse.jface.dialogs.MessageDialog; import com.clustercontrol.accesscontrol.bean.PrivilegeConstant; import com.clustercontrol.util.HinemosMessage; import com.clustercontrol.util.Messages; import com.clustercontrol.ws.access.InvalidRole_Exception; import com.clustercontrol.ws.access.SystemPrivilegeInfo; /** * ????????? * * @version 4.0.0 */ public class SystemPrivilegePropertyUtil { /** ? */ private static Log m_log = LogFactory.getLog(SystemPrivilegePropertyUtil.class); /** ?key=????value=?key=?value=? */ private static Map<String, Map<String, SystemPrivilegeInfo>> m_systemPrivilegeAllMngMap = new ConcurrentHashMap<>(); /** */ private static Map<String, String> m_messageMap = new HashMap<>(); /** */ private static final String KEY_SYSTEM_PRIVILEGE_FUNCTION_PREFIX = "system_privilege.function."; private static final String KEY_SYSTEM_PRIVILEGE_PRIVILEGE_PREFIX = "system_privilege.privilege."; private static void createSystemPrivilegeMap(String managerName) { if (managerName != null && managerName.length() > 0) { Map<String, SystemPrivilegeInfo> systemPrivilegeMap = m_systemPrivilegeAllMngMap.get(managerName); if (systemPrivilegeMap == null) { systemPrivilegeMap = new ConcurrentHashMap<>(); List<SystemPrivilegeInfo> systemPrivilegeInfoList = new ArrayList<>(); // ?? try { AccessEndpointWrapper wrapper = AccessEndpointWrapper.getWrapper(managerName); systemPrivilegeInfoList = wrapper.getSystemPrivilegeInfoListByEditType( PrivilegeConstant.SYSTEMPRIVILEGE_EDITTYPE_DIALOG); } catch (InvalidRole_Exception e) { // ??? MessageDialog.openInformation(null, Messages.getString("message"), Messages.getString("message.accesscontrol.16")); } catch (Exception e) { // ? m_log.warn("getOwnUserList(), " + HinemosMessage.replace(e.getMessage()), e); MessageDialog.openError(null, Messages.getString("failed"), Messages.getString("message.hinemos.failure.unexpected") + ", " + HinemosMessage.replace(e.getMessage())); } // ?? for (SystemPrivilegeInfo systemPrivilegeInfo : systemPrivilegeInfoList) { systemPrivilegeMap.put(getSystemPrivilegeMessage(systemPrivilegeInfo), systemPrivilegeInfo); } // ? m_systemPrivilegeAllMngMap.put(managerName, systemPrivilegeMap); } } return; } /** * ??? * @param managerName ??? * @return Messages.getString("repository.read", locale) ?? */ public static List<String> getSystemPrivilegeNameList(String managerName) { createSystemPrivilegeMap(managerName); List<String> list = new ArrayList<>(); if (m_systemPrivilegeAllMngMap.get(managerName) != null) { list = new ArrayList<String>(m_systemPrivilegeAllMngMap.get(managerName).keySet()); } return list; } /** * ??? * @param managerName ??? * @param systemPrivilegeInfo * @return [SystemFunction Message] - [SystemPrivilege Message] */ public static String getSystemPrivilegeName(String managerName, SystemPrivilegeInfo systemPrivilegeInfo) { createSystemPrivilegeMap(managerName); if (m_systemPrivilegeAllMngMap.get(managerName) != null) { for (Map.Entry<String, SystemPrivilegeInfo> entry : m_systemPrivilegeAllMngMap.get(managerName) .entrySet()) { if (systemPrivilegeInfo.getSystemFunction().equals(entry.getValue().getSystemFunction()) && systemPrivilegeInfo.getSystemPrivilege().equals(entry.getValue().getSystemPrivilege())) { return entry.getKey(); } } } return null; } /** * * @param managerName ??? * @param [SystemFunction Message] - [SystemPrivilege Message] * @return SyFunctionConstant.REPOSITORY + SystemPrivilegeMode.READ.name() ? */ public static SystemPrivilegeInfo getFunctionPrivilege(String managerName, String value) { createSystemPrivilegeMap(managerName); if (m_systemPrivilegeAllMngMap.get(managerName) != null) { return m_systemPrivilegeAllMngMap.get(managerName).get(value); } else { return null; } } /** * * ??? * * @param systemPrivilegeInfo ? * @return */ private static String getSystemPrivilegeMessage(SystemPrivilegeInfo systemPrivilegeInfo) { String message = ""; if (systemPrivilegeInfo != null) { Locale locale = Locale.getDefault(); String functionKey = KEY_SYSTEM_PRIVILEGE_FUNCTION_PREFIX + systemPrivilegeInfo.getSystemFunction().toLowerCase(locale); String functionmessage = m_messageMap.get(functionKey); // ????????? if (functionmessage == null || functionmessage.length() == 0) { functionmessage = Messages.getString(functionKey, locale); m_messageMap.put(functionKey, functionmessage); } String privilegeKey = KEY_SYSTEM_PRIVILEGE_PRIVILEGE_PREFIX + systemPrivilegeInfo.getSystemPrivilege().toLowerCase(locale); String privilegemessage = m_messageMap.get(privilegeKey); // ????????? if (privilegemessage == null || privilegemessage.length() == 0) { privilegemessage = Messages.getString(privilegeKey, locale); m_messageMap.put(privilegeKey, privilegemessage); } message = String.format("%s - %s", functionmessage, privilegemessage); } return message; } }