Author: channa
Date: Wed Jan 16 21:41:27 2008
New Revision: 12371
Log:
Adding the option to specify primary user in server.xml if local browser is not
available. Deleting admin created by wsas if redundant.
Modified:
trunk/mashup/java/modules/core/conf/server.xml
trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java
trunk/mashup/java/modules/core/src/org/wso2/mashup/transport/MashupServerInitializer.java
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/RegistrationBean.java
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/utils/RegistryUtils.java
trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/mashup/deployer/JSDeployer.java
Modified: trunk/mashup/java/modules/core/conf/server.xml
==============================================================================
--- trunk/mashup/java/modules/core/conf/server.xml (original)
+++ trunk/mashup/java/modules/core/conf/server.xml Wed Jan 16 21:41:27 2008
@@ -141,7 +141,14 @@
-->
<RememberMePeriod>14</RememberMePeriod>
</SessionManagement>
-
+
+ <!--User to setup the primary (admin) user account when browser based
local setup is not possible-->
+ <PrimaryUserConfig>
+ <!--Set CreatePrimary to 'true' to activate option-->
+ <CreatePrimary>false</CreatePrimary>
+ <PrimaryUser>admin</PrimaryUser>
+ <PrimaryPassword>admin</PrimaryPassword>
+ </PrimaryUserConfig>
<!--
Functions related to the Management Console
-->
Modified:
trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java
==============================================================================
--- trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java
(original)
+++ trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java
Wed Jan 16 21:41:27 2008
@@ -105,5 +105,9 @@
public static final String FAULTY_MASHUP = "faulty_mashup";
+ public static final String PRIMARY_USER_CONFIG = "PrimaryUserConfig";
+ public static final String CREATE_PRIMARY_USER = "CreatePrimary";
+ public static final String PRIMARY_USER = "PrimaryUser";
+ public static final String PRIMARY_PASSWORD = "PrimaryPassword";
public static final String LOCALHOST = "localhost";
}
Modified:
trunk/mashup/java/modules/core/src/org/wso2/mashup/transport/MashupServerInitializer.java
==============================================================================
---
trunk/mashup/java/modules/core/src/org/wso2/mashup/transport/MashupServerInitializer.java
(original)
+++
trunk/mashup/java/modules/core/src/org/wso2/mashup/transport/MashupServerInitializer.java
Wed Jan 16 21:41:27 2008
@@ -23,20 +23,22 @@
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.log4j.Logger;
import org.wso2.mashup.MashupConstants;
+import org.wso2.mashup.webapp.utils.RegistryUtils;
import org.wso2.registry.Registry;
import org.wso2.registry.RegistryConstants;
import org.wso2.registry.RegistryException;
import org.wso2.registry.secure.SecureRegistry;
import org.wso2.usermanager.Realm;
import org.wso2.usermanager.UserManagerException;
+import org.wso2.usermanager.UserStoreAdmin;
import org.wso2.utils.ServerException;
import org.wso2.wsas.ServerInitializer;
import org.wso2.wsas.admin.service.SecurityScenarioConfigAdmin;
import org.wso2.wsas.persistence.PersistenceManager;
import org.wso2.wsas.persistence.dataobject.KeyStoreDO;
+import org.wso2.wsas.persistence.dataobject.ServiceDO;
import org.wso2.wsas.persistence.dataobject.ServiceGroupDO;
import org.wso2.wsas.persistence.dataobject.ServiceIdentifierDO;
-import org.wso2.wsas.persistence.dataobject.ServiceDO;
import org.wso2.wsas.persistence.exception.ServiceGroupNotFoundException;
import org.wso2.wsas.util.WsasUtils;
@@ -92,6 +94,13 @@
new String[] { },
new String[] {
MashupConstants.MASHUP_USER_ROLE });
+ // Delete wsas-created 'admin' user, as a primary user is
explicitly created.
+ UserStoreAdmin userStoreAdmin = realm.getUserStoreAdmin();
+ if (userStoreAdmin.isExistingUser(RegistryConstants.ADMIN_USER) &&
+ !RegistryUtils.isUserPrimary(realm,
RegistryConstants.ADMIN_USER)) {
+ userStoreAdmin.deleteUser(RegistryConstants.ADMIN_USER);
+ }
+
// Applying a dummy tag so that searching works
// https://wso2.org/jira/browse/REGISTRY-24
SecureRegistry secureRegistry =
Modified:
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/RegistrationBean.java
==============================================================================
---
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/RegistrationBean.java
(original)
+++
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/RegistrationBean.java
Wed Jan 16 21:41:27 2008
@@ -163,7 +163,7 @@
adminName, adminEmail, "System
Administrator");
// Assign system user the 'admin' role and make primary.
userStoreAdmin.addUserToRole(userName,
RegistryConstants.ADMIN_ROLE);
- makeUserPrimary(realm, userName);
+ RegistryUtils.makeUserPrimary(realm, userName);
MashupUtils.setInitialSetupComplete(true);
} catch (UserManagerException e) {
log.error("Error creating admin user in user manager", e);
@@ -175,27 +175,6 @@
}
/**
- * Gets the profile for a given user and makes him/her primary.
- *
- * @param realm Registry realm.
- * @param userName User to be made primary.
- */
- private void makeUserPrimary(Realm realm, String userName) throws
UserManagerException {
- try {
- // Get the user's properties.
- UserStoreAdmin userStoreAdmin = realm.getUserStoreAdmin();
- Map userProps = userStoreAdmin.getUserProperties(userName);
-
- // Set the 'primary' property.
- userProps.put(MashupConstants.PRIMARY, String.valueOf(true));
- userStoreAdmin.setUserProperties(userName, userProps);
- } catch (UserManagerException e) {
- log.error("Error getting user properties", e);
- throw new UserManagerException("Could not make user primary", e);
- }
- }
-
- /**
* Return any added error messages.
*
* @param key Key to identify error.
Modified:
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/utils/RegistryUtils.java
==============================================================================
---
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/utils/RegistryUtils.java
(original)
+++
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/utils/RegistryUtils.java
Wed Jan 16 21:41:27 2008
@@ -559,6 +559,22 @@
}
/**
+ * Gets the profile for a given user and makes him/her primary.
+ *
+ * @param realm Registry realm.
+ * @param userName User to be made primary.
+ */
+ public static void makeUserPrimary(Realm realm, String userName) throws
UserManagerException {
+ // Get the user's properties.
+ UserStoreAdmin userStoreAdmin = realm.getUserStoreAdmin();
+ Map userProps = userStoreAdmin.getUserProperties(userName);
+
+ // Set the 'primary' property.
+ userProps.put(MashupConstants.PRIMARY, String.valueOf(true));
+ userStoreAdmin.setUserProperties(userName, userProps);
+ }
+
+ /**
* Gets the profile for a given user and returns if he ir she is the
primary user.
*
* @param realm Registry realm.
Modified:
trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/mashup/deployer/JSDeployer.java
==============================================================================
---
trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/mashup/deployer/JSDeployer.java
(original)
+++
trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/mashup/deployer/JSDeployer.java
Wed Jan 16 21:41:27 2008
@@ -649,6 +649,9 @@
}
private void initRegistry() throws MashupFault {
+ boolean createPrimary;
+ String primaryName = null;
+ String primaryPassword;
ServerConfiguration serverConfig = ServerConfiguration.getInstance();
@@ -716,6 +719,16 @@
us.addRole(RegistryConstants.EVERYONE_ROLE);
}
+ createPrimary =
Boolean.parseBoolean(serverConfig.getFirstProperty(MashupConstants.PRIMARY_USER_CONFIG
+ "." +
+ MashupConstants.CREATE_PRIMARY_USER));
+ if (createPrimary && !MashupUtils.isInitialSetupComplete()) {
+ primaryName =
serverConfig.getFirstProperty(MashupConstants.PRIMARY_USER_CONFIG + "." +
+ MashupConstants.PRIMARY_USER);
+ primaryPassword =
serverConfig.getFirstProperty(MashupConstants.PRIMARY_USER_CONFIG + "." +
+ MashupConstants.PRIMARY_PASSWORD);
+ us.addUser(primaryName, primaryPassword);
+ }
+
RegistryDataSource datasource = new
RegistryDataSource(registryUrl, registryDriverClass,
registryUsername,
registryPassword);
JDBCRegistry registry = new JDBCRegistry(datasource, realm);
@@ -907,7 +920,17 @@
// Create the 'shared' user profile
RegistryUtils.createUser(secureRegistry, realm,
MashupConstants.SHARED_USER,
- "Shared", "none", "Shared Mashups");
+ "Shared", "none", "Shared Mashups");
+
+ if (createPrimary && !MashupUtils.isInitialSetupComplete()) {
+ //Create the admin profile using information from a config
file.
+ RegistryUtils.createUser(secureRegistry, realm,
primaryName, primaryName, "none",
+ "System Administrator");
+ // Assign system user the 'admin' role and make primary.
+ us.addUserToRole(primaryName,
RegistryConstants.ADMIN_ROLE);
+ RegistryUtils.makeUserPrimary(realm, primaryName);
+ MashupUtils.setInitialSetupComplete(true);
+ }
}
} catch (UserManagerException e) {
e.printStackTrace();
_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev