📄 realmconfigadmin.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;import java.util.Iterator;import java.util.Map;import java.util.Set;import java.util.Map.Entry;import org.wso2.solutions.identity.IdentityProviderConstants;import org.wso2.solutions.identity.IdentityProviderException;import org.wso2.solutions.identity.UserStore;import org.wso2.solutions.identity.persistence.IPPersistenceManager;import org.wso2.solutions.identity.persistence.dataobject.RealmConfigurationDO;import org.wso2.solutions.identity.persistence.dataobject.RealmConfigurationPropertyDO;import org.wso2.solutions.identity.persistence.dataobject.RealmDO;import org.wso2.solutions.identity.users.wsas.WSASRealm;import org.wso2.usermanager.custom.jdbc.JDBCRealm;import org.wso2.usermanager.custom.ldap.LDAPRealm;import org.wso2.usermanager.readwrite.DefaultRealm;public class RealmConfigAdmin { public void createNewRealmConfiguration(String realmClassName, String configName, Map properties) throws IdentityProviderException { IPPersistenceManager db = IPPersistenceManager.getPersistanceManager(); RealmDO realm = db.getRealm(realmClassName); RealmConfigurationDO realmConfig = new RealmConfigurationDO(); realmConfig.setRealm(realm); realmConfig.setName(configName); db.create(realmConfig); Set entries = properties.entrySet(); for (Iterator iterator = entries.iterator(); iterator.hasNext();) { java.util.Map.Entry<String, String> entry = (Entry<String, String>)iterator.next(); RealmConfigurationPropertyDO propDo = new RealmConfigurationPropertyDO(); propDo.setName(entry.getKey()); propDo.setValue(entry.getValue()); propDo.setConfig(realmConfig); db.create(propDo); } } public boolean setDefaultRealmConfiguration(String configName) throws IdentityProviderException { IPPersistenceManager db = IPPersistenceManager.getPersistanceManager(); UserStore.getInstance().changeRalm(configName); // Now reset claim mappings ClaimsAdmin claimsAdmin = new ClaimsAdmin(); claimsAdmin.resetClaimMappings(); RealmConfigurationDO effectiveConfig = db .getEffectiveRealmConfiguration(); effectiveConfig.setEffective(false); db.update(effectiveConfig); RealmConfigurationDO config = db.getRealmConfiguration(configName); config.setEffective(true); db.update(config); // Disable user registration & OpenID registration for WSAS sample, JDBC and LDAP realms String realmClassName = config.getRealm().getClassName(); if (realmClassName.equals(JDBCRealm.class.getName()) || realmClassName.equals(LDAPRealm.class.getName()) || realmClassName.equals(WSASRealm.class.getName())) { ParameterAdmin paramAdmin = new ParameterAdmin(); if (paramAdmin .getParameter(IdentityProviderConstants.PARAM_NAME_ALLOW_USER_REGISTRATION) != null) { paramAdmin .removeParam(IdentityProviderConstants.PARAM_NAME_ALLOW_USER_REGISTRATION); } if (paramAdmin .getParameter(IdentityProviderConstants.PARAM_NAME_ENABLE_OPENID_REGISTRATION) != null) { paramAdmin .removeParam(IdentityProviderConstants.PARAM_NAME_ENABLE_OPENID_REGISTRATION); } return true; } else if (realmClassName.equals(DefaultRealm.class.getName())) { ParameterAdmin paramAdmin = new ParameterAdmin(); paramAdmin .createOrUpdatearameter( IdentityProviderConstants.PARAM_NAME_ALLOW_USER_REGISTRATION, null); paramAdmin .createOrUpdatearameter( IdentityProviderConstants.PARAM_NAME_ENABLE_OPENID_REGISTRATION, null); } return false; } public RealmConfigurationDO getRealmConfiguration(String name) throws IdentityProviderException { IPPersistenceManager db = IPPersistenceManager.getPersistanceManager(); RealmConfigurationDO config = db.getRealmConfiguration(name); return config; } public void updateRealmConfigurationProperties(Set properties) throws IdentityProviderException { IPPersistenceManager db = IPPersistenceManager.getPersistanceManager(); Iterator ite = properties.iterator(); while (ite.hasNext()) { RealmConfigurationPropertyDO rdo = (RealmConfigurationPropertyDO) ite .next(); db.update(rdo); } } public void deleteRealmConfiguration(RealmConfigurationDO config) throws IdentityProviderException { IPPersistenceManager db = IPPersistenceManager.getPersistanceManager(); db.delete(config); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -