Author: prabath
Date: Mon Feb 11 07:21:09 2008
New Revision: 13591
Log:
infocard login to OP, verification
Modified:
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/util/UserUtil.java
Modified:
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/util/UserUtil.java
==============================================================================
---
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/util/UserUtil.java
(original)
+++
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/util/UserUtil.java
Mon Feb 11 07:21:09 2008
@@ -13,6 +13,7 @@
import org.wso2.solutions.identity.UserStore;
import org.wso2.solutions.identity.admin.RegisteredInfoCardInfoAdmin;
import org.wso2.solutions.identity.admin.ReportAdmin;
+import org.wso2.solutions.identity.persistence.IPPersistenceManager;
import org.wso2.solutions.identity.persistence.dataobject.ActionDO;
import
org.wso2.solutions.identity.persistence.dataobject.RegisteredInfoCardInfoDO;
import org.wso2.solutions.identity.relyingparty.TokenVerifierConstants;
@@ -52,14 +53,13 @@
String user = (String) iterator.next();
mapValues = userStore.getClaimValues(user, null);
- if (mapValues != null) {
+ if (mapValues != null && !mapValues.isEmpty()) {
// User has defined claims!
String claimId = (String) mapValues
.get(IdentityConstants.CLAIM_OPENID);
- if (mapValues != null && !mapValues.isEmpty()
- && claimId != null) {
+ if (claimId != null) {
if (openID.indexOf(claimId) >= 0
&& openID.endsWith(claimId.substring(claimId
.length() - 1))) {
@@ -96,10 +96,10 @@
*
* @param request
* @return
- * @throws IdentityProviderException
+ * @throws IdentityProviderException
*/
- public static boolean verifyInfoCardLogin(ActionContext context)
- throws IdentityProviderException {
+ public static boolean verifyInfoCardLogin(ActionContext context,
+ String openID) throws IdentityProviderException {
HttpServletRequest request = (HttpServletRequest) context
.get(StrutsStatics.HTTP_REQUEST);
@@ -125,14 +125,77 @@
}
if (info != null && info.getIssuerInfo().equals(issuerInfo)) {
- context.getSession().put(UIConstants.USER, info.getUserId());
- context.getSession().put(UIConstants.PPID, ppid);
- ReportAdmin.record(info.getUserId(),
- ActionDO.ACTION_USER_LOG_IN_CARD, "PPID=" + ppid);
- return true;
+ try {
+ if (openID.equals(getOpenID(ppid))) {
+ context.getSession()
+ .put(UIConstants.USER, info.getUserId());
+ context.getSession().put(UIConstants.PPID, ppid);
+ ReportAdmin.record(info.getUserId(),
+ ActionDO.ACTION_USER_LOG_IN_CARD, "PPID=" + ppid);
+ return true;
+ } else {
+ return false;
+ }
+ } catch (Exception e) {
+ return false;
+ }
} else {
return false;
}
}
+ public static String getOpenID(String ppid) throws ServerException,
+ Exception {
+
+ UserStore userStore = null;
+ List users = null;
+
+ userStore = UserStore.getInstance();
+ users = userStore.getAllUserNames();
+
+ if (users == null)
+ // TODO: Define a custom exception or use a more appropriate one.
+ throw new Exception("No users found");
+
+ Map mapValues = null;
+ Iterator iterator = null;
+
+ iterator = users.iterator();
+
+ while (iterator.hasNext()) {
+
+ String user = (String) iterator.next();
+ mapValues = userStore.getClaimValues(user, null);
+
+ if (mapValues != null && !mapValues.isEmpty()) {
+
+ // User has defined claims!
+ String claimId = (String) mapValues
+ .get(IdentityConstants.CLAIM_OPENID);
+ String currentppid = (String) mapValues
+ .get(IdentityConstants.CLAIM_PPID);
+
+ if (currentppid == null) {
+ // this is a user signed up with user-name/password and
later
+ // registered an infocard.
+ IPPersistenceManager db = IPPersistenceManager
+ .getPersistanceManager();
+ RegisteredInfoCardInfoDO[] infocards = null;
+ infocards = db.getAllRegistedInfoCardInfoForUser(user);
+
+ for (RegisteredInfoCardInfoDO infocard : infocards) {
+ if (ppid.equals(infocard.getPpid()))
+ return claimId;
+ }
+ }
+
+ if (ppid.equals(currentppid))
+ return claimId;
+ }
+ }
+
+ // TODO: Define a custom exception or use a more appropriate one.
+ throw new Exception("No OpenID found for the given ppid");
+ }
+
}
_______________________________________________
Identity-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/identity-dev