📄 initializer.java
字号:
/* * Copyright 2005,2006 WSO2, Inc. http://www.wso2.org * * 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;import java.util.ArrayList;import java.util.Iterator;import org.apache.axis2.AxisFault;import org.apache.axis2.context.ConfigurationContext;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.wso2.solutions.identity.admin.ClaimsAdmin;import org.wso2.solutions.identity.admin.ConfigurationContextHolder;import org.wso2.solutions.identity.admin.ParameterAdmin;import org.wso2.solutions.identity.admin.STSConfigAdmin;import org.wso2.solutions.identity.i18n.Messages;import org.wso2.solutions.identity.persistence.IPPersistenceManager;import org.wso2.solutions.identity.persistence.dataobject.ActionDO;import org.wso2.solutions.identity.persistence.dataobject.ClaimDO;import org.wso2.solutions.identity.persistence.dataobject.DialectDO;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.persistence.dataobject.RelyingPartyDO;import org.wso2.solutions.identity.users.IdentityDefaultRealm;import org.wso2.solutions.identity.users.wsas.WSASRealm;import org.wso2.usermanager.Realm;import org.wso2.usermanager.custom.jdbc.JDBCRealm;import org.wso2.usermanager.custom.jdbc.JDBCRealmConfig;import org.wso2.usermanager.custom.ldap.LDAPRealm;import org.wso2.usermanager.custom.ldap.LDAPRealmConfig;import org.wso2.usermanager.readwrite.DefaultRealm;import org.wso2.usermanager.readwrite.DefaultRealmConfig;import org.wso2.usermanager.verification.email.EmailVerifier;import org.wso2.usermanager.verification.email.EmailVerifierConfig;import org.wso2.utils.ServerConfiguration;import org.wso2.utils.ServerException;import org.wso2.wsas.ServerInitializer;import org.wso2.wsas.admin.service.UserAdmin;/** * WSO2 WSAS <code>ServerInitializer</code> implementation to carry out * initial configuration setup of the Identity Solution : Identity Provider. */public class Initializer implements ServerInitializer { private static Log log = LogFactory.getLog(Initializer.class); private static Messages messages = Messages .getInstance(IdentityProviderConstants.RESOURCES); /** * {@inheritDoc} Here we carry out all initialization work of the identity * solution : identity provider */ public void init(ConfigurationContext ctx) throws AxisFault, ServerException { log.info(messages.getMessage("initStart")); ConfigurationContextHolder.setConfigurationContext(ctx); try { IPPersistenceManager db = IPPersistenceManager .getPersistanceManager(); // Checking whether the initial startup - at least one dialect must // be there DialectDO[] dialectDOs = db.getAllSupportedDialects(); boolean isInitial = false; if (dialectDOs.length == 0) { isInitial = true; } STSConfigAdmin.configuraServices(isInitial); if (isInitial) { addDialectsAndClaims(); setupRelyingPartyUserAccounts(); addParameters(); setupAllRealms(); addActions(); // Add the globally trusted relying party RelyingPartyDO rp = new RelyingPartyDO(); ServerConfiguration serverConfig = ServerConfiguration .getInstance(); rp.setHostName(serverConfig.getFirstProperty("HostName")); rp.setAlias(serverConfig .getFirstProperty("Security.KeyStore.KeyAlias")); db.create(rp); } initializeEmailVerifier(); } catch (Exception e) { throw new AxisFault(e.getMessage(), e); } log.info(messages.getMessage("initDone")); } private void setupAllRealms() throws Exception { IPPersistenceManager db = IPPersistenceManager.getPersistanceManager(); // Add JDBC realm RealmDO jdbcRealm = new RealmDO(); jdbcRealm.setClassName(JDBCRealm.class.getName()); jdbcRealm.setConfigClassName(JDBCRealmConfig.class.getName()); db.create(jdbcRealm); // Add LDAP realm RealmDO ldapRealm = new RealmDO(); ldapRealm.setClassName(LDAPRealm.class.getName()); ldapRealm.setConfigClassName(LDAPRealmConfig.class.getName()); db.create(ldapRealm); RealmDO wsasRealm = new RealmDO(); wsasRealm.setClassName(WSASRealm.class.getName()); wsasRealm.setConfigClassName(null); db.create(wsasRealm); RealmConfigurationDO wsasRealmConfig = new RealmConfigurationDO(); wsasRealmConfig.setName("wsasRealmForAccessControlSample"); wsasRealmConfig.setRealm(wsasRealm); db.create(wsasRealmConfig); RealmDO defaultRealm = new RealmDO(); defaultRealm.setClassName(IdentityDefaultRealm.class.getName()); defaultRealm.setConfigClassName(DefaultRealmConfig.class.getName()); db.create(defaultRealm); // Add default realm configuration RealmConfigurationDO realmConfig = new RealmConfigurationDO(); realmConfig.setName("defaultRealm"); realmConfig.setRealm(defaultRealm); realmConfig.setEffective(true); db.create(realmConfig); RealmConfigurationPropertyDO prop = new RealmConfigurationPropertyDO(); prop.setConfig(realmConfig); prop.setName("ConnectionURL"); prop.setValue(IdentityProviderConstants.Default.CONNECTION_URL); db.create(prop); prop = new RealmConfigurationPropertyDO(); prop.setConfig(realmConfig); prop.setName("ConnectionUserName"); prop.setValue(IdentityProviderConstants.Default.CONNECTION_USER_NAME); db.create(prop); prop = new RealmConfigurationPropertyDO(); prop.setConfig(realmConfig); prop.setName("ConnectionPassword"); prop.setValue(IdentityProviderConstants.Sample.CONNECTION_PASSWORD); db.create(prop); prop = new RealmConfigurationPropertyDO(); prop.setConfig(realmConfig); prop.setName("DriverName"); prop.setValue(IdentityProviderConstants.Default.DRIVER); db.create(prop); this.setupSampleRealmConfig(db, jdbcRealm); // Enable user registration ParameterAdmin paramAdmin = new ParameterAdmin(); paramAdmin.createOrUpdatearameter( IdentityProviderConstants.PARAM_NAME_ALLOW_USER_REGISTRATION, null); // Enable OpenID registration paramAdmin .createOrUpdatearameter( IdentityProviderConstants.PARAM_NAME_ENABLE_OPENID_REGISTRATION, null); } /** * Setup the user store for the identity provider sample. * @param db * @param jdbcRealm * @throws Exception */ private void setupSampleRealmConfig(IPPersistenceManager db, RealmDO jdbcRealm) throws Exception { // Add sample realm configuration RealmConfigurationDO realmConfig = new RealmConfigurationDO(); realmConfig.setName("sampleRealm"); realmConfig.setRealm(jdbcRealm); db.create(realmConfig); RealmConfigurationPropertyDO prop = new RealmConfigurationPropertyDO(); prop.setConfig(realmConfig); prop.setName("ConnectionURL"); prop.setValue(IdentityProviderConstants.Sample.CONNECTION_URL); db.create(prop); prop = new RealmConfigurationPropertyDO(); prop.setConfig(realmConfig); prop.setName("ConnectionUserName"); prop.setValue(IdentityProviderConstants.Sample.CONNECTION_USER_NAME); db.create(prop); prop = new RealmConfigurationPropertyDO(); prop.setConfig(realmConfig); prop.setName("ConnectionPassword"); prop.setValue(IdentityProviderConstants.Sample.CONNECTION_PASSWORD); db.create(prop); prop = new RealmConfigurationPropertyDO(); prop.setConfig(realmConfig);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -