Author: channa
Date: Mon Dec 3 05:16:54 2007
New Revision: 10435
Log:
Moved registration into class; adding registered user to 'Everyone' role.
Renamed InfoCard handler class to add 'card association with user' feature.
Added:
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/InfoCardHandler.java
- copied, changed from r10406,
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/InfoCardSignIn.java
Removed:
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/InfoCardSignIn.java
Modified:
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/Registration.java
trunk/mashup/java/modules/www/org/infocardaccept.jsp
trunk/mashup/java/modules/www/org/mashup.jsp
trunk/mashup/java/modules/www/org/register_self.jsp
trunk/mashup/java/modules/www/org/registration_result.jsp
trunk/mashup/java/modules/www/org/search.jsp
trunk/mashup/java/modules/www/org/signin.jsp
trunk/mashup/java/modules/www/org/signout.jsp
trunk/mashup/java/modules/www/org/tag_cloud.jsp
trunk/mashup/java/modules/www/org/user.jsp
trunk/mashup/java/modules/www/org/validate.jsp
Copied:
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/InfoCardHandler.java
(from r10406,
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/InfoCardSignIn.java)
==============================================================================
---
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/InfoCardSignIn.java
(original)
+++
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/InfoCardHandler.java
Mon Dec 3 05:16:54 2007
@@ -17,16 +17,25 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.wso2.mashup.MashupConstants;
+import org.wso2.registry.RegistryConstants;
+import org.wso2.registry.RegistryException;
+import org.wso2.registry.jdbc.JDBCRegistry;
+import org.wso2.registry.secure.SecureRegistry;
import org.wso2.solutions.identity.IdentityConstants;
import org.wso2.solutions.identity.relyingparty.TokenVerifierConstants;
+import org.wso2.usermanager.Realm;
+import org.wso2.usermanager.UserManagerException;
+import org.wso2.usermanager.UserStoreReader;
+import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
/**
* Encapsulates the infocard based sign-in process logic.
*/
-public class InfoCardSignIn {
- private static final Log log = LogFactory.getLog(InfoCardSignIn.class);
+public class InfoCardHandler {
+ private static final Log log = LogFactory.getLog(InfoCardHandler.class);
/**
* Retrieves the infocard parameters and uses the ppid to validate the
user.
@@ -50,12 +59,30 @@
// If information has been retrieved, proceed with ppid
validation.
if (givenName != null && surname != null && email != null && ppid
!= null) {
- log.info("Parameters retrieved from infocard"
+ givenName + ":" + surname + ":" +
+ log.info("Parameters retrieved from infocard" + givenName +
":" + surname + ":" +
email + ":" + ppid);
- //todo: get the ppid from the info card and use it to verify
the user in the DB.
-
- success = true;
+ ServletContext context =
request.getSession().getServletContext();
+ JDBCRegistry jdbcRegistry =
+ (JDBCRegistry)
context.getAttribute(RegistryConstants.REGISTRY);
+ Realm realm = (Realm)
context.getAttribute(RegistryConstants.REGISTRY_REALM);
+ try {
+ UserStoreReader storeReader = realm.getUserStoreReader();
+ String[] userNames =
storeReader.getUserNamesWithPropertyValue("ppid", ppid);
+
+ // Only one person with PPID in the infocard, so get
secure registry for user.
+ if (userNames.length == 1) {
+ SecureRegistry secureRegistry = new
SecureRegistry(userNames[0],
+
jdbcRegistry, realm);
+
request.getSession().setAttribute(MashupConstants.USER_REGISTRY,
+ secureRegistry);
+ success = true;
+ }
+ } catch (UserManagerException e) {
+ log.error("Error retrieving user associated with info
card", e);
+ } catch (RegistryException e) {
+ log.error("Error getting secure registry instance for
user", e);
+ }
} else {
log.error("Required parameters not provided by info card");
}
Modified:
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/Registration.java
==============================================================================
---
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/Registration.java
(original)
+++
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/Registration.java
Mon Dec 3 05:16:54 2007
@@ -13,16 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.wso2.mashup.webapp.identity;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.mashup.MashupConstants;
import org.wso2.usermanager.UserManagerException;
+import org.wso2.usermanager.Realm;
import org.wso2.usermanager.verification.email.EmailVerifier;
+import org.wso2.registry.RegistryConstants;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.ServletContext;
import java.util.HashMap;
import java.util.Map;
@@ -66,4 +68,50 @@
}
return success;
}
+
+ /**
+ * Verify the self registered user via the confirmation string received
from the e-mail URL.
+ *
+ * @param request Servlet request.
+ * @return true if user is successfully validated.
+ */
+ public static boolean validate(HttpServletRequest request) {
+ boolean isVerified = false;
+ String confValue = request.getParameter("confirmation");
+ String userName;
+
+ if (confValue != null) {
+ try {
+ EmailVerifier verifier = new EmailVerifier();
+
+ // Authorize confirmed user if verification succeeds.
+ userName = verifier.getUserName(confValue);
+ if (verifier.confirmUser(confValue)) {
+ isVerified = authorizeUser(request, userName);
+ }
+ } catch (UserManagerException e) {
+ log.error("Error verifying user registration", e);
+ }
+ }
+ return isVerified;
+ }
+
+ /**
+ * Authorize user to use the secure registry.
+ *
+ * @param userName Identifier of user to be authorized.
+ */
+ private static boolean authorizeUser(HttpServletRequest request, String
userName) {
+ boolean isAuthorized = false;
+ ServletContext context = request.getSession().getServletContext();
+ Realm realm = (Realm)
context.getAttribute(RegistryConstants.REGISTRY_REALM);
+
+ try {
+ realm.getUserStoreAdmin().addUserToRole(userName,
RegistryConstants.EVERYONE_ROLE);
+ isAuthorized = true;
+ } catch (UserManagerException e) {
+ log.error("Error adding user to role", e);
+ }
+ return isAuthorized;
+ }
}
Modified: trunk/mashup/java/modules/www/org/infocardaccept.jsp
==============================================================================
--- trunk/mashup/java/modules/www/org/infocardaccept.jsp (original)
+++ trunk/mashup/java/modules/www/org/infocardaccept.jsp Mon Dec 3
05:16:54 2007
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
--%>
-<%@ page import="org.wso2.mashup.webapp.identity.InfoCardSignIn" %>
+<%@ page import="org.wso2.mashup.webapp.identity.InfoCardHandler" %>
<%@ page import="org.wso2.mashup.webapp.utils.RegistryUtils" %>
<%@ page import="org.wso2.registry.Registry" %>
<%@ page import="java.net.URLDecoder" %>
@@ -43,7 +43,7 @@
boolean success;
// If infocard authentication has been used, call bean method.
- success = InfoCardSignIn.signIn(request);
+ success = InfoCardHandler.signIn(request);
%>
<% if (success) {
response.sendRedirect(bounceback);
Modified: trunk/mashup/java/modules/www/org/mashup.jsp
==============================================================================
--- trunk/mashup/java/modules/www/org/mashup.jsp (original)
+++ trunk/mashup/java/modules/www/org/mashup.jsp Mon Dec 3 05:16:54 2007
@@ -24,7 +24,7 @@
<%@ page import="org.wso2.mashup.MashupConstants" %>
<%@ page import="org.wso2.mashup.utils.QueryResult" %>
<%@ page import="org.wso2.mashup.utils.QueryResults" %>
-<%@ page import="org.wso2.mashup.webapp.identity.InfoCardSignIn" %>
+<%@ page import="org.wso2.mashup.webapp.identity.InfoCardHandler" %>
<%@ page import="org.wso2.mashup.webapp.identity.Registration" %>
<%@ page import="org.wso2.mashup.webapp.userprofile.User" %>
<%@ page import="org.wso2.mashup.webapp.userprofile.UserQuery" %>
Modified: trunk/mashup/java/modules/www/org/register_self.jsp
==============================================================================
--- trunk/mashup/java/modules/www/org/register_self.jsp (original)
+++ trunk/mashup/java/modules/www/org/register_self.jsp Mon Dec 3 05:16:54 2007
@@ -24,7 +24,7 @@
<%@ page import="org.wso2.mashup.MashupConstants" %>
<%@ page import="org.wso2.mashup.utils.QueryResult" %>
<%@ page import="org.wso2.mashup.utils.QueryResults" %>
-<%@ page import="org.wso2.mashup.webapp.identity.InfoCardSignIn" %>
+<%@ page import="org.wso2.mashup.webapp.identity.InfoCardHandler" %>
<%@ page import="org.wso2.mashup.webapp.identity.Registration" %>
<%@ page import="org.wso2.mashup.webapp.userprofile.User" %>
<%@ page import="org.wso2.mashup.webapp.userprofile.UserQuery" %>
Modified: trunk/mashup/java/modules/www/org/registration_result.jsp
==============================================================================
--- trunk/mashup/java/modules/www/org/registration_result.jsp (original)
+++ trunk/mashup/java/modules/www/org/registration_result.jsp Mon Dec 3
05:16:54 2007
@@ -24,7 +24,7 @@
<%@ page import="org.wso2.mashup.MashupConstants" %>
<%@ page import="org.wso2.mashup.utils.QueryResult" %>
<%@ page import="org.wso2.mashup.utils.QueryResults" %>
-<%@ page import="org.wso2.mashup.webapp.identity.InfoCardSignIn" %>
+<%@ page import="org.wso2.mashup.webapp.identity.InfoCardHandler" %>
<%@ page import="org.wso2.mashup.webapp.identity.Registration" %>
<%@ page import="org.wso2.mashup.webapp.userprofile.User" %>
<%@ page import="org.wso2.mashup.webapp.userprofile.UserQuery" %>
@@ -75,7 +75,7 @@
<tr>
<td align="center" height="175">
<% if (Registration.register(request)) { %>
- <div class="login-error">Please check mail and click on
the link sent.</div>
+ <div class="login-error">Self-registration successful.
Please check mail and click on the link sent.</div>
<% } else { %>
<div class="login-error">Self-registration failed. Please
try again.</div>
<% } %>
Modified: trunk/mashup/java/modules/www/org/search.jsp
==============================================================================
--- trunk/mashup/java/modules/www/org/search.jsp (original)
+++ trunk/mashup/java/modules/www/org/search.jsp Mon Dec 3 05:16:54 2007
@@ -23,7 +23,7 @@
%><%@ page import="org.wso2.mashup.MashupConstants"
%><%@ page import="org.wso2.mashup.utils.QueryResult"
%><%@ page import="org.wso2.mashup.utils.QueryResults"
-%><%@ page import="org.wso2.mashup.webapp.identity.InfoCardSignIn"
+%><%@ page import="org.wso2.mashup.webapp.identity.InfoCardHandler"
%><%@ page import="org.wso2.mashup.webapp.identity.Registration"
%><%@ page import="org.wso2.mashup.webapp.userprofile.User"
%><%@ page import="org.wso2.mashup.webapp.userprofile.UserQuery"
Modified: trunk/mashup/java/modules/www/org/signin.jsp
==============================================================================
--- trunk/mashup/java/modules/www/org/signin.jsp (original)
+++ trunk/mashup/java/modules/www/org/signin.jsp Mon Dec 3 05:16:54 2007
@@ -24,7 +24,7 @@
<%@ page import="org.wso2.mashup.MashupConstants" %>
<%@ page import="org.wso2.mashup.utils.QueryResult" %>
<%@ page import="org.wso2.mashup.utils.QueryResults" %>
-<%@ page import="org.wso2.mashup.webapp.identity.InfoCardSignIn" %>
+<%@ page import="org.wso2.mashup.webapp.identity.InfoCardHandler" %>
<%@ page import="org.wso2.mashup.webapp.identity.Registration" %>
<%@ page import="org.wso2.mashup.webapp.userprofile.User" %>
<%@ page import="org.wso2.mashup.webapp.userprofile.UserQuery" %>
@@ -68,30 +68,6 @@
String nameProvided = request.getParameter("userName");
String passwordProvided = request.getParameter("password");
if (firsttime != null) {
- /*
- // If infocard authentication has been used, get information that
way.
- String auth = (String)
request.getAttribute(TokenVerifierConstants.SERVLET_ATTR_STATE);
- if (auth != null) {
- // If authentication successful, retrieve details.
- if (TokenVerifierConstants.STATE_SUCCESS.equals(auth)) {
- String givenName = (String)
request.getAttribute("givenname");
- String surname = (String) request.getAttribute("surname");
- String email = (String) request.getAttribute("emailaddress");
- if (givenName == null || surname == null || email == null) {
- return ActionSupport.ERROR;
- } else {
- //todo: get the ppid from the info card and use it to
verify the user in the DB.
-
- }
-
- } else {
- String reason =
- (String)
request.getAttribute(TokenVerifierConstants.FAILURE_REASON);
- return ActionSupport.ERROR;
- }
- } else {
- */
-
try {
ServletContext context = request.getSession().getServletContext();
@@ -110,9 +86,6 @@
} catch (RegistryException e) {
success = false;
}
- /*
- }
- */
}
%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
Modified: trunk/mashup/java/modules/www/org/signout.jsp
==============================================================================
--- trunk/mashup/java/modules/www/org/signout.jsp (original)
+++ trunk/mashup/java/modules/www/org/signout.jsp Mon Dec 3 05:16:54 2007
@@ -23,7 +23,7 @@
<%@ page import="org.wso2.mashup.MashupConstants" %>
<%@ page import="org.wso2.mashup.utils.QueryResult" %>
<%@ page import="org.wso2.mashup.utils.QueryResults" %>
-<%@ page import="org.wso2.mashup.webapp.identity.InfoCardSignIn" %>
+<%@ page import="org.wso2.mashup.webapp.identity.InfoCardHandler" %>
<%@ page import="org.wso2.mashup.webapp.identity.Registration" %>
<%@ page import="org.wso2.mashup.webapp.userprofile.User" %>
<%@ page import="org.wso2.mashup.webapp.userprofile.UserQuery" %>
Modified: trunk/mashup/java/modules/www/org/tag_cloud.jsp
==============================================================================
--- trunk/mashup/java/modules/www/org/tag_cloud.jsp (original)
+++ trunk/mashup/java/modules/www/org/tag_cloud.jsp Mon Dec 3 05:16:54 2007
@@ -24,7 +24,7 @@
<%@ page import="org.wso2.mashup.MashupConstants" %>
<%@ page import="org.wso2.mashup.utils.QueryResult" %>
<%@ page import="org.wso2.mashup.utils.QueryResults" %>
-<%@ page import="org.wso2.mashup.webapp.identity.InfoCardSignIn" %>
+<%@ page import="org.wso2.mashup.webapp.identity.InfoCardHandler" %>
<%@ page import="org.wso2.mashup.webapp.identity.Registration" %>
<%@ page import="org.wso2.mashup.webapp.userprofile.User" %>
<%@ page import="org.wso2.mashup.webapp.userprofile.UserQuery" %>
Modified: trunk/mashup/java/modules/www/org/user.jsp
==============================================================================
--- trunk/mashup/java/modules/www/org/user.jsp (original)
+++ trunk/mashup/java/modules/www/org/user.jsp Mon Dec 3 05:16:54 2007
@@ -24,7 +24,7 @@
<%@ page import="org.wso2.mashup.MashupConstants" %>
<%@ page import="org.wso2.mashup.utils.QueryResult" %>
<%@ page import="org.wso2.mashup.utils.QueryResults" %>
-<%@ page import="org.wso2.mashup.webapp.identity.InfoCardSignIn" %>
+<%@ page import="org.wso2.mashup.webapp.identity.InfoCardHandler" %>
<%@ page import="org.wso2.mashup.webapp.identity.Registration" %>
<%@ page import="org.wso2.mashup.webapp.userprofile.User" %>
<%@ page import="org.wso2.mashup.webapp.userprofile.UserQuery" %>
Modified: trunk/mashup/java/modules/www/org/validate.jsp
==============================================================================
--- trunk/mashup/java/modules/www/org/validate.jsp (original)
+++ trunk/mashup/java/modules/www/org/validate.jsp Mon Dec 3 05:16:54 2007
@@ -13,10 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
--%>
+<%@ page import="org.wso2.mashup.webapp.identity.Registration" %>
<%@ page import="org.wso2.mashup.webapp.utils.RegistryUtils" %>
<%@ page import="org.wso2.registry.Registry" %>
-<%@ page import="org.wso2.usermanager.UserManagerException" %>
-<%@ page import="org.wso2.usermanager.verification.email.EmailVerifier" %>
<%
Registry registry = RegistryUtils.getRegistry(request);
@@ -42,19 +41,8 @@
<tr>
<td align="center" height="175">
<%
- String value = request.getParameter("confirmation");
- boolean isVerified = false;
- if (value != null) {
- try {
- EmailVerifier verifier = new EmailVerifier();
- isVerified = verifier.confirmUser(value);
- } catch (UserManagerException e) {
- %>
- <div class="login-error">Error validating you. Please try
again later.</div>
- <%
- }
- }
- if (isVerified) {
+
+ if (Registration.validate(request)) {
%>
<div>You are successfully validated. You can login now.
</div>
_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev