Author: channa
Date: Mon Jan 14 17:20:03 2008
New Revision: 12230
Log:
Added initial setup page, which allows administrator to self register. Text and
formatting to be added to make it as attractive as a typical welcome page, as
it is the first page displayed on server access.
Added:
trunk/mashup/java/modules/www/register_admin.jsp
Modified:
trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java
trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupUtils.java
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/RegistrationBean.java
trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/mashup/deployer/JSDeployer.java
trunk/mashup/java/modules/www/index.jsp
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
Mon Jan 14 17:20:03 2008
@@ -40,8 +40,6 @@
public static String QUARTZ_FUNCTION_SCHEDULER = "FunctionScheduler";
- public static String ADMIN_PASSWORD = "admin";
-
public static final String EMAIL_RELAY_HOST = "email_relay_host";
public static final String REG_VALIDATION_URL =
"registration_validation_url";
public static final String EMAIL_FROM_ADDRESS = "email_from_address";
@@ -93,4 +91,5 @@
public static final String MASHUP_USER_ROLE = "mashup_user";
public static final String SELF_REGISTRATION_ENABLED =
"self_registration_enabled";
+ public static final String INITIAL_SETUP_COMPLETE =
"initial_setup_complete";
}
Modified:
trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupUtils.java
==============================================================================
--- trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupUtils.java
(original)
+++ trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupUtils.java
Mon Jan 14 17:20:03 2008
@@ -402,4 +402,25 @@
return success;
}
+
+ /**
+ * Sets the initial setup status.
+ *
+ * @param status true indicates that the initial setup of the server has
been done.
+ */
+ public static void setInitialSetupComplete(boolean status) {
+ PersistenceManager pm = new PersistenceManager();
+ pm.updateConfigurationProperty(MashupConstants.INITIAL_SETUP_COMPLETE,
+ String.valueOf(status));
+ }
+
+ /**
+ * Gets the initial setup status.
+ * @return true if initial setup has been completed.
+ */
+ public static boolean isInitialSetupComplete() {
+ PersistenceManager pm = new PersistenceManager();
+ String status =
pm.getConfigurationProperty(MashupConstants.INITIAL_SETUP_COMPLETE);
+ return "true".equals(status);
+ }
}
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
Mon Jan 14 17:20:03 2008
@@ -18,6 +18,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.mashup.MashupConstants;
+import org.wso2.mashup.utils.MashupUtils;
import org.wso2.mashup.webapp.userprofile.ManageUsers;
import org.wso2.mashup.webapp.utils.RegistryUtils;
import org.wso2.registry.RegistryConstants;
@@ -48,6 +49,7 @@
private String password;
private String confirmedPassword;
private String emailId;
+ private boolean adminCreation;
private Hashtable errors;
public String getUserName() {
@@ -90,6 +92,14 @@
this.emailId = emailId;
}
+ public boolean isAdminCreation() {
+ return adminCreation;
+ }
+
+ public void setAdminCreation(boolean adminCreation) {
+ this.adminCreation = adminCreation;
+ }
+
/**
* Initialize bean values.
*/
@@ -128,6 +138,43 @@
}
/**
+ * Accepts users information submitted and creates the admin ID.
+ */
+ public void createAdmin(HttpServletRequest request) throws
UserManagerException,
+ RegistryException {
+ ServletContext context = request.getSession().getServletContext();
+ JDBCRegistry jdbcRegistry = (JDBCRegistry) context.getAttribute(
+ RegistryConstants.REGISTRY);
+ Realm realm = (Realm)
context.getAttribute(RegistryConstants.REGISTRY_REALM);
+ SecureRegistry registry = new
SecureRegistry(MashupConstants.SYSTEM_USER,
+
MashupConstants.SYSTEM_USER_PASSWORD,
+ jdbcRegistry, realm);
+ try {
+ // Get an instance of the user store admin and create the user.
+ UserStoreAdmin userStoreAdmin = realm.getUserStoreAdmin();
+ userStoreAdmin.addUser(userName, password);
+
+ // Create the admin user profile.
+ RegistryUtils.createUser(registry, realm, userName,
+ fullName, "none", "System Administrator");
+ // Assign system user the 'admin' role.
+ userStoreAdmin.addUserToRole(userName,
RegistryConstants.ADMIN_ROLE);
+
+ // Delete redundant 'admin' user in registry, if it exists.
+ if (userStoreAdmin.isExistingUser(RegistryConstants.ADMIN_USER)) {
+ userStoreAdmin.deleteUser(RegistryConstants.ADMIN_USER);
+ }
+ MashupUtils.setInitialSetupComplete(true);
+ } catch (UserManagerException e) {
+ log.error("Error creating admin user in user manager", e);
+ throw new UserManagerException("Could not create admin user", e);
+ } catch (RegistryException e) {
+ log.error("Error adding admin user resources", e);
+ throw new RegistryException("Could not create admin user", e);
+ }
+ }
+
+ /**
* Return any added error messages.
*
* @param key Key to identify error.
@@ -186,7 +233,7 @@
return "true".equals(status);
}
- /**
+ /**
* Authorizes user to the registry by granting him a role, then adding a
user directory and
* creating a profile granting user edit access.
*
@@ -208,8 +255,8 @@
String eMail = (String) userProps.get(MashupConstants.EMAIL_ID);
// Create secure registry instance using the admin ID.
- SecureRegistry secureRegistry = new
SecureRegistry(RegistryConstants.ADMIN_USER,
-
MashupConstants.ADMIN_PASSWORD,
+ SecureRegistry secureRegistry = new
SecureRegistry(MashupConstants.SYSTEM_USER,
+
MashupConstants.SYSTEM_USER_PASSWORD,
jdbcRegistry,
realm);
// Add user to registry.
RegistryUtils.createUser(secureRegistry, realm, userName,
fullName, eMail, fullName);
@@ -259,10 +306,13 @@
valid = false;
}
- if (emailId.equals("")) {
- errors.put("emailId", "E-mail ID cannot be empty.");
- emailId = "";
- valid = false;
+ // E-mail ID is not required for creating the admin profile.
+ if (!adminCreation) {
+ if (emailId.equals("")) {
+ errors.put("emailId", "E-mail ID cannot be empty.");
+ emailId = "";
+ valid = false;
+ }
}
// Expensive operation, so do only once all other data has been
validated.
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
Mon Jan 14 17:20:03 2008
@@ -687,7 +687,6 @@
if (!us.isExistingUser(RegistryConstants.ANONYMOUS_USER)) {
us.addUser(RegistryConstants.ANONYMOUS_USER,
RegistryConstants.ANONYMOUS_PASSWORD);
- us.addUser(RegistryConstants.ADMIN_USER,
MashupConstants.ADMIN_PASSWORD);
us.addUser(RegistryConstants.SYSTEM_USER,
RegistryConstants.SYSTEM_PASSWORD);
us.addUser(MashupConstants.SAMPLES_USER,
MashupConstants.SAMPLES_USER_PASSWORD);
us.addUser(MashupConstants.SHARED_USER,
MashupConstants.SHARED_USER_PASSWORD);
@@ -874,15 +873,11 @@
RegistryConstants.ANONYMOUS_USER,
"Visitor", "none",
"Anonymous user");
- // Create the admin user profile.
- RegistryUtils.createUser(secureRegistry, realm,
RegistryConstants.ADMIN_USER,
- "Administrator", "none", "System administrator");
- // Assign admin user the 'admin' role.
- us.addUserToRole(RegistryConstants.ADMIN_USER,
RegistryConstants.ADMIN_ROLE);
-
// Create the system user profile.
RegistryUtils.createUser(secureRegistry, realm,
MashupConstants.SYSTEM_USER,
"System", "none", "System User");
+ // Assign system user the 'admin' role.
+ us.addUserToRole(MashupConstants.SYSTEM_USER,
RegistryConstants.ADMIN_ROLE);
// Create the 'Samples' user and profile.
RegistryUtils.createUser(secureRegistry, realm,
MashupConstants.SAMPLES_USER,
Modified: trunk/mashup/java/modules/www/index.jsp
==============================================================================
--- trunk/mashup/java/modules/www/index.jsp (original)
+++ trunk/mashup/java/modules/www/index.jsp Mon Jan 14 17:20:03 2008
@@ -14,20 +14,51 @@
* limitations under the License.
--%>
<%@ page errorPage="error.jsp" %>
+<%@ page import="com.sun.syndication.feed.synd.SyndContent" %>
+<%@ page import="com.sun.syndication.feed.synd.SyndContentImpl" %>
+<%@ page import="com.sun.syndication.feed.synd.SyndEntry" %>
+<%@ page import="com.sun.syndication.feed.synd.SyndEntryImpl" %>
+<%@ page import="com.sun.syndication.feed.synd.SyndFeed" %>
+<%@ page import="com.sun.syndication.feed.synd.SyndFeedImpl" %>
+<%@ page import="com.sun.syndication.io.SyndFeedOutput" %>
+<%@ page import="org.apache.axis2.context.ConfigurationContext" %>
<%@ page import="org.wso2.mashup.MashupConstants" %>
+<%@ page import="org.wso2.mashup.utils.MashupUtils" %>
<%@ page import="org.wso2.mashup.utils.QueryResult" %>
<%@ page import="org.wso2.mashup.utils.QueryResults" %>
+<%@ page import="org.wso2.mashup.webapp.identity.InfoCardHandler" %>
+<%@ page import="org.wso2.mashup.webapp.identity.RegistrationBean" %>
+<%@ page import="org.wso2.mashup.webapp.userprofile.ManageUsers" %>
<%@ page import="org.wso2.mashup.webapp.userprofile.User" %>
<%@ page import="org.wso2.mashup.webapp.userprofile.UserQuery" %>
<%@ page import="org.wso2.mashup.webapp.utils.QueryParamUtils" %>
<%@ page import="org.wso2.mashup.webapp.utils.RegistryUtils" %>
-<%@ page import="org.wso2.registry.LogEntry" %>
+<%@ page import="org.wso2.registry.Comment" %>
<%@ page import="org.wso2.registry.Registry" %>
<%@ page import="org.wso2.registry.RegistryConstants" %>
+<%@ page import="org.wso2.registry.RegistryException" %>
+<%@ page import="org.wso2.registry.Resource" %>
+<%@ page import="org.wso2.registry.Tag" %>
+<%@ page import="org.wso2.registry.jdbc.JDBCRegistry" %>
+<%@ page import="org.wso2.registry.secure.SecureRegistry" %>
+<%@ page import="org.wso2.usermanager.Realm" %>
+<%@ page import="org.wso2.usermanager.UserManagerException" %>
+<%@ page import="org.wso2.usermanager.UserStoreAdmin" %>
+<%@ page import="org.wso2.wsas.ServerManager" %>
+<%@ page import="javax.servlet.ServletContext" %>
+<%@ page import="java.io.BufferedReader" %>
+<%@ page import="java.io.FileReader" %>
+<%@ page import="java.net.URL" %>
+<%@ page import="java.net.URLDecoder" %>
<%@ page import="java.util.ArrayList" %>
+<%@ page import="java.util.Date" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.List" %>
+<%@ page import="java.util.Map" %>
<%
+ if (!MashupUtils.isInitialSetupComplete()) {
+ response.sendRedirect("register_admin.jsp?firstcall=true");
+ }
Registry registry = RegistryUtils.getRegistry(request);
User userProfile =
RegistryUtils.getUserProfile(RegistryUtils.getCurrentUser(registry), registry);
Added: trunk/mashup/java/modules/www/register_admin.jsp
==============================================================================
--- (empty file)
+++ trunk/mashup/java/modules/www/register_admin.jsp Mon Jan 14 17:20:03 2008
@@ -0,0 +1,108 @@
+<%--
+ * Copyright 2006,2007 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.
+--%>
+<%@ page errorPage="error.jsp" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@ page import="org.wso2.mashup.utils.MashupUtils" %>
+<%@ page import="org.wso2.mashup.webapp.utils.RegistryUtils" %>
+<%@ page import="org.wso2.registry.Registry" %>
+<%
+ Registry registry = RegistryUtils.getRegistry(request);
+ String firstCall = request.getParameter("firstcall");
+%>
+<jsp:useBean id="registrationHandler"
class="org.wso2.mashup.webapp.identity.RegistrationBean"
+ scope="request">
+ <jsp:setProperty name="registrationHandler" property="*"/>
+ <jsp:setProperty name="registrationHandler" property="adminCreation"
value="true"/>
+</jsp:useBean>
+<%
+ if (MashupUtils.isInitialSetupComplete()) {
+ response.sendRedirect("index.jsp");
+ }
+
+ if (!"true".equals(firstCall)) {
+ if (registrationHandler.isInputValid(request)) {
+ registrationHandler.createAdmin(request);
+ response.sendRedirect("index.jsp");
+ }
+ }
+%>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html>
+<head>
+ <title>Mashups.wso2.org</title>
+ <!-- Required CSS -->
+ <link href="css/styles.css" rel="stylesheet" type="text/css"/>
+ <script language="javascript" src="js/common.js"
type="text/javascript"></script>
+ <script language="javascript"
+ type="text/javascript">userLoggedOn =
<%=RegistryUtils.isLoggedIn(registry) %>;</script>
+</head>
+<body>
+<div id="page">
+ <% String thisPage = "index.jsp"; %>
+ <%@ include file="header.jsp" %>
+ <div id="search"></div>
+ <div id="content" style="height:400px; ">
+ <div class="mashup_title">Initial Server Setup</div>
+ <br />
+ <form name="formRegisterAdmin" method='post'
action="register_admin.jsp">
+ <table width="100%" border="0" cellpadding="3"
cellspacing="0" >
+ <tr>
+ <td width="130"><label><strong>User Name:<font
color="#FF0000">*</font></strong></label></td>
+ <td><input type="text" name="userName"
+
value="<%=registrationHandler.getUserName()%>"/>
+ <br><font
color="#FF0000"><%=registrationHandler.getErrorMessage("userName")%></font>
+ </td>
+ </tr>
+ <tr>
+ <td width="130"><label><strong>Full Name:<font
color="#FF0000">*</font></strong></label></td>
+ <td><input type="text" name="fullName"
+
value="<%=registrationHandler.getFullName()%>"/>
+ <br><font
color="#FF0000"><%=registrationHandler.getErrorMessage("fullName")%></font>
+ </td>
+ </tr>
+ <tr>
+ <td><label><strong>Password:<font
color="#FF0000">*</font></strong></label></td>
+ <td><input type="password" name="password"
+
value="<%=registrationHandler.getPassword()%>"/>
+ <br><font
color="#FF0000"><%=registrationHandler.getErrorMessage("password")%></font>
+ </td>
+ </tr>
+ <tr>
+ <td><label><strong>Confirmation Password:<font
color="#FF0000">*</font></strong></label></td>
+ <td><input type="password"
+
name="confirmedPassword"<%=registrationHandler
+ .getConfirmedPassword()%>"/>
+ <br><font
color="#FF0000"><%=registrationHandler
+
.getErrorMessage("confirmedPassword")%></font>
+ </td>
+ </tr>
+ <tr>
+ <td> </td>
+ <td><input type="submit"
value="Register"/></td>
+ </tr>
+ <tr>
+ <td> </td>
+ <td align="center"></td>
+ </tr>
+ </table>
+ <strong><font color="#FF0000">*</font></strong>
Required fields
+ </form>
+ <br>
+ </div>
+ <%@ include file="footer.jsp" %>
+</div>
+</body>
+</html>
_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev