Author: prabath
Date: Fri Feb 29 04:06:02 2008
New Revision: 14359
Log:
rp url normalizing
Modified:
trunk/solutions/identity/modules/samples/servlet-filter/src/main/webapp/openidinfocardloggedin.jsp
trunk/solutions/identity/modules/token-verifier-core/src/main/java/org/wso2/solutions/identity/relyingparty/openid/OpenIDConsumer.java
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/action/OpenIDAuthVerificationAction.java
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/action/OpenIDUserApprovalAction.java
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/webapp/jsp/openidinfocardlogin.jsp
Modified:
trunk/solutions/identity/modules/samples/servlet-filter/src/main/webapp/openidinfocardloggedin.jsp
==============================================================================
---
trunk/solutions/identity/modules/samples/servlet-filter/src/main/webapp/openidinfocardloggedin.jsp
(original)
+++
trunk/solutions/identity/modules/samples/servlet-filter/src/main/webapp/openidinfocardloggedin.jsp
Fri Feb 29 04:06:02 2008
@@ -19,11 +19,11 @@
<form name="frm" id="frm" method="post"
action="openidinfocardloggedin.jsp">
<input type="hidden" name="InfoCardSignin" value="Log
in" /><br/>
- <OBJECT type="application/x-informationCard" name="xmlToken">
+ <OBJECT type="application/x-informationCard" name="xmlToken">
<PARAM Name="tokenType"
Value="http://specs.openid.net/auth/2.0">
- <PARAM Name="requiredClaims"
Value="http://schema.openid.net/2007/05/claims/identifier
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/country">
- <PARAM Name="optionalClaims"
value="http://schema.openid.net/2007/05/claims/dob
http://schema.openid.net/2007/05/claims/gender
http://schema.openid.net/2007/05/claims/language
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/postalcode
http://schema.openid.net/2007/05/claims/timezone">
- </OBJECT>
+ <PARAM Name="requiredClaims"
Value="http://schema.openid.net/2007/05/claims/identifier
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/country">
+ <PARAM Name="optionalClaims"
value="http://axschema.org/birthDate http://axschema.org/person/gender
http://axschema.org/namePerson/friendly http://axschema.org/pref/language
http://axschema.org/contact/postalCode/home http://axschema.org/pref/timezone">
+ </OBJECT>
</form>
<script language="JavaScript" type="text/JavaScript">
Modified:
trunk/solutions/identity/modules/token-verifier-core/src/main/java/org/wso2/solutions/identity/relyingparty/openid/OpenIDConsumer.java
==============================================================================
---
trunk/solutions/identity/modules/token-verifier-core/src/main/java/org/wso2/solutions/identity/relyingparty/openid/OpenIDConsumer.java
(original)
+++
trunk/solutions/identity/modules/token-verifier-core/src/main/java/org/wso2/solutions/identity/relyingparty/openid/OpenIDConsumer.java
Fri Feb 29 04:06:02 2008
@@ -1,6 +1,7 @@
package org.wso2.solutions.identity.relyingparty.openid;
import java.io.IOException;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -37,6 +38,8 @@
private ConsumerManager manager;
private static OpenIDConsumer consumer;
+ private static Map axMapping = new HashMap();
+
/**
* Creates an instance of OpenIDConsumer
* @throws RelyingPartyException
@@ -57,6 +60,27 @@
// Not enforcing RP realm discovery
// since this new feature is not deployed in openid4java.
manager.getRealmVerifier().setEnforceRpId(false);
+
+ axMapping.put(
+ IdentityConstants.OpenId.ExchangeAttributes.POSTAL_CODE_NS,
+ IdentityConstants.OpenId.ExchangeAttributes.POSTAL_CODE);
+ axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.NICK_NAME_NS,
+ IdentityConstants.OpenId.ExchangeAttributes.NICK_NAME);
+ axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.LANGUAGE_NS,
+ IdentityConstants.OpenId.ExchangeAttributes.LANGUAGE);
+ axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.GENDER_NS,
+ IdentityConstants.OpenId.ExchangeAttributes.GENDER);
+ axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.COUNTRY_NS,
+ IdentityConstants.OpenId.ExchangeAttributes.COUNTRY);
+ axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.DOB_NS,
+ IdentityConstants.OpenId.ExchangeAttributes.DOB);
+ axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.FULL_NAME_NS,
+ IdentityConstants.OpenId.ExchangeAttributes.FULL_NAME);
+ axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.TIMEZONE_NS,
+ IdentityConstants.OpenId.ExchangeAttributes.TIMEZONE);
+ axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.EMAIL_NS,
+ IdentityConstants.OpenId.ExchangeAttributes.EMAIL);
+
}
/**
@@ -271,7 +295,7 @@
// Received an xmlToken from the identity selector.
ParameterList openidResp = extractFromInfocardPost(request);
try {
- processOpenIDResp(request, session, openidResp);
+ processOpenIDInfocardResponse(request, session, openidResp);
} catch (OpenIDException e) {
// Present error to the user.
throw new RelyingPartyException(e.getMessage(), e);
@@ -351,7 +375,7 @@
* @throws OpenIDException
* @throws RelyingPartyException
*/
- protected void processOpenIDResp(HttpServletRequest request,
+ protected void processOpenIDInfocardResponse(HttpServletRequest request,
HttpSession session, ParameterList openidResp)
throws OpenIDException, RelyingPartyException {
@@ -365,10 +389,12 @@
discovered = (DiscoveryInformation) session.getAttribute("discovered");
receivingURL = request.getRequestURL();
-
- /*receivingURL = new StringBuffer(openidResp
- .getParameterValue(IdentityConstants.OpenId.ATTR_RETURN_TO));
*/
-
+
+ /*
+ * receivingURL = new StringBuffer(openidResp
+ * .getParameterValue(IdentityConstants.OpenId.ATTR_RETURN_TO));
+ */
+
queryString = request.getQueryString();
if (queryString != null && queryString.length() > 0)
@@ -399,23 +425,16 @@
authSuccess = (AuthSuccess) authResponse;
- if (authSuccess.hasExtension(AxMessage.OPENID_NS_AX)) {
+ FetchResponse fetchResp = null;
- FetchResponse fetchResp = null;
+ if (authSuccess.hasExtension(AxMessage.OPENID_NS_AX)) {
extension = authSuccess.getExtension(AxMessage.OPENID_NS_AX);
- fetchResp = (FetchResponse) extension;
- setRequestAttributes(fetchResp, request);
+ if (extension != null && extension instanceof FetchResponse) {
- } else if (authSuccess
-
.hasExtension(IdentityConstants.OpenId.SimpleRegAttributes.NS_SREG)) {
-
- SRegResponse regResponse = null;
- extension = authSuccess
-
.getExtension(IdentityConstants.OpenId.SimpleRegAttributes.NS_SREG);
-
- regResponse = (SRegResponse) extension;
- setRequestAttributes(regResponse, request);
+ fetchResp = (FetchResponse) extension;
+ setOpenIDInfocardReqAttributes(fetchResp, request);
+ }
}
}
}
@@ -488,10 +507,8 @@
for (Object alias : aliases) {
values = response.getAttributeValues((String) alias);
- request.setAttribute((String) alias,
- (String) values.get(0));
+ request.setAttribute((String) alias, (String) values.get(0));
}
-
}
/**
@@ -514,4 +531,31 @@
request.setAttribute(key, attributes.get(key));
}
}
+
+ /**
+ * Set request attributes for OpenID attribute exchange
+ * @param response FetchResponse
+ * @param request HttpServletRequest
+ */
+ private void setOpenIDInfocardReqAttributes(FetchResponse response,
+ HttpServletRequest request) {
+
+ List aliases = null;
+ List values = null;
+ String key = null;
+
+ aliases = response.getAttributeAliases();
+
+ for (Object alias : aliases) {
+ values = response.getAttributeValues((String) alias);
+
+ if (axMapping.containsKey((String) alias)) {
+ key = (String) axMapping.get(alias);
+ } else {
+ key = (String) alias;
+ }
+
+ request.setAttribute(key, (String) values.get(0));
+ }
+ }
}
Modified:
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/action/OpenIDAuthVerificationAction.java
==============================================================================
---
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/action/OpenIDAuthVerificationAction.java
(original)
+++
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/action/OpenIDAuthVerificationAction.java
Fri Feb 29 04:06:02 2008
@@ -80,12 +80,9 @@
}
if
(requestParam.hasParameter(IdentityConstants.OpenId.ATTR_RETURN_TO)) {
-
rpUrl = requestParam.getParameter(
IdentityConstants.OpenId.ATTR_RETURN_TO).getValue();
- if (rpUrl != null && rpUrl.indexOf("?") > 0) {
- rpUrl = rpUrl.substring(0, rpUrl.indexOf("?"));
- }
+ rpUrl = UserUtil.getRelyingPartyUrl(rpUrl);
} else {
addErrorMessage(getText("returnTo_required"));
return ERROR;
@@ -262,36 +259,17 @@
String rpUrl = requestParam
.getParameterValue(IdentityConstants.OpenId.ATTR_RETURN_TO);
- URI uri = null;
- URL url = null;
-
- try {
- uri = new URI(rpUrl);
- } catch (URISyntaxException e) {
- throw new RelyingPartyException(
- IdentityConstants.ErrorCodes.INVALID_OPENID_RETURNTO);
- }
-
- try {
- url = uri.normalize().toURL();
- url = new URL(url.getProtocol().toLowerCase(), url.getHost()
- .toLowerCase(), url.getPort(), url.getPath());
- rpUrl = url.toString();
-
- } catch (MalformedURLException e) {
- throw new RelyingPartyException(
- IdentityConstants.ErrorCodes.INVALID_OPENID_RETURNTO);
- }
+ rpUrl = UserUtil.getRelyingPartyUrl(rpUrl);
+ OpenIDUserRPDO[] rpdos = null;
+ OpenIDUserRPDO rpdo = null;
+
try {
db = IPPersistenceManager.getPersistanceManager();
} catch (IdentityProviderException e) {
throw new RelyingPartyException("dbConnectionFailure");
}
- OpenIDUserRPDO[] rpdos = null;
- OpenIDUserRPDO rpdo = null;
-
// Get matching data, related to the requested RP.
rpdos = db.getOpenIDUserRP(UserUtil.getUserName(openID), rpUrl);
Modified:
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/action/OpenIDUserApprovalAction.java
==============================================================================
---
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/action/OpenIDUserApprovalAction.java
(original)
+++
trunk/solutions/identity/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/action/OpenIDUserApprovalAction.java
Fri Feb 29 04:06:02 2008
@@ -68,6 +68,8 @@
.getParameterValue(IdentityConstants.OpenId.ATTR_RETURN_TO);
String openididentity = requestp
.getParameterValue(IdentityConstants.OpenId.ATTR_IDENTITY);
+
+ rpUrl = UserUtil.getRelyingPartyUrl(rpUrl);
if (openididentity == null || rpUrl == null) {
addErrorMessage(getText("openid_required"));
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
Fri Feb 29 04:06:02 2008
@@ -1,5 +1,9 @@
package org.wso2.solutions.identity.user.ui.util;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -25,9 +29,7 @@
/**
* Get the user name corresponding to a given OpenID
- *
- * @param openID
- * OpenID used to log in
+ * @param openID OpenID used to log in
* @return Corresponding user name
* @throws RelyingPartyException
*/
@@ -85,11 +87,8 @@
/**
* Verify user name/password authentication.
- *
- * @param username
- * User name
- * @param password
- * Password
+ * @param username User name
+ * @param password Password
* @return true if user successfully authenticated
*/
public static boolean doLogin(String username, String password) {
@@ -104,7 +103,6 @@
/**
* Verify user information card authentication.
- *
* @param ActionContext
* @return true if user successfully authenticated
* @throws RelyingPartyException
@@ -156,9 +154,7 @@
/**
* Get OpenID corresponding to a given PPID
- *
- * @param ppid
- * PPID of the self-issued information card
+ * @param ppid PPID of the self-issued information card
* @return OpenID corresponding to the given PPID
* @throws RelyingPartyException
*/
@@ -234,4 +230,29 @@
IdentityConstants.ErrorCodes.NO_OPENID_FOUND);
}
+ public static String getRelyingPartyUrl(String rpUrl)
+ throws RelyingPartyException {
+
+ URI uri = null;
+ URL url = null;
+
+ try {
+ uri = new URI(rpUrl);
+ } catch (URISyntaxException e) {
+ throw new RelyingPartyException(
+ IdentityConstants.ErrorCodes.INVALID_OPENID_RETURNTO);
+ }
+
+ try {
+ url = uri.normalize().toURL();
+ url = new URL(url.getProtocol().toLowerCase(), url.getHost()
+ .toLowerCase(), url.getPort(), url.getPath());
+ return url.toString();
+
+ } catch (MalformedURLException e) {
+ throw new RelyingPartyException(
+ IdentityConstants.ErrorCodes.INVALID_OPENID_RETURNTO);
+ }
+ }
+
}
Modified:
trunk/solutions/identity/modules/user-ui/src/main/webapp/jsp/openidinfocardlogin.jsp
==============================================================================
---
trunk/solutions/identity/modules/user-ui/src/main/webapp/jsp/openidinfocardlogin.jsp
(original)
+++
trunk/solutions/identity/modules/user-ui/src/main/webapp/jsp/openidinfocardlogin.jsp
Fri Feb 29 04:06:02 2008
@@ -15,7 +15,7 @@
<OBJECT type="application/x-informationCard" name="xmlToken">
<PARAM Name="tokenType"
Value="http://specs.openid.net/auth/2.0">
<PARAM Name="requiredClaims"
Value="http://schema.openid.net/2007/05/claims/identifier
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/country">
- <PARAM Name="optionalClaims"
value="http://schema.openid.net/2007/05/claims/dob
http://schema.openid.net/2007/05/claims/gender
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nickname
http://schema.openid.net/2007/05/claims/language
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/postalcode
http://schema.openid.net/2007/05/claims/timezone">
+ <PARAM Name="optionalClaims"
value="http://axschema.org/birthDate http://axschema.org/person/gender
http://axschema.org/namePerson/friendly http://axschema.org/pref/language
http://axschema.org/contact/postalCode/home http://axschema.org/pref/timezone">
</OBJECT>
</form>
<script language="JavaScript" type="text/JavaScript">
_______________________________________________
Identity-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/identity-dev