Author: prabath
Date: Mon Jan 21 02:07:11 2008
New Revision: 12598
Log:
removed hard-coded claim values
Modified:
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/sts/OpenIDTokenIssuer.java
Modified:
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/sts/OpenIDTokenIssuer.java
==============================================================================
---
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/sts/OpenIDTokenIssuer.java
(original)
+++
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/sts/OpenIDTokenIssuer.java
Mon Jan 21 02:07:11 2008
@@ -3,6 +3,7 @@
import java.io.ByteArrayInputStream;
import java.text.DateFormat;
import java.util.Date;
+import java.util.Iterator;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -19,25 +20,21 @@
import org.apache.ws.security.util.XmlSchemaDateFormat;
import org.openid4java.association.Association;
import org.openid4java.association.AssociationException;
-import org.openid4java.consumer.InMemoryConsumerAssociationStore;
import org.openid4java.message.Message;
import org.openid4java.message.MessageException;
import org.openid4java.message.Parameter;
import org.openid4java.message.ParameterList;
-import org.openid4java.server.InMemoryServerAssociationStore;
-import org.openid4java.server.IncrementalNonceGenerator;
-import org.openid4java.server.NonceGenerator;
-import org.openid4java.server.ServerAssociationStore;
import org.opensaml.SAMLAssertion;
import org.opensaml.SAMLException;
import org.w3c.dom.Document;
import org.wso2.solutions.identity.IdentityConstants;
-import org.wso2.solutions.identity.IdentityProviderConstants;
import org.wso2.solutions.identity.IdentityProviderException;
-import org.wso2.solutions.identity.openid.OpenIDInfoCardToken;
import org.wso2.solutions.identity.openid.OpenIDProvider;
+import org.wso2.solutions.identity.openid.infocard.OpenIDInfoCardProviderData;
+import org.wso2.solutions.identity.openid.infocard.OpenIDInfoCardToken;
+import
org.wso2.solutions.identity.openid.infocard.OpenIDInfoCardProviderData.OpenIDRequestedClaimData;
import org.wso2.solutions.identity.sts.IdentityProviderData.RequestedClaimData;
public class OpenIDTokenIssuer extends IdentityTokenIssuer {
@@ -140,7 +137,7 @@
* @return
* @throws MessageException
*/
- private OMElement createOpenIdToken(OMElement rstrElem)
+ protected OMElement createOpenIdToken(OMElement rstrElem)
throws MessageException {
OMElement rdt = IdentityProviderUtil
.createOpenIdToken(rstrElem, ipData);
@@ -199,194 +196,89 @@
throw new MessageException(e.getMessage());
}
- params.set(new Parameter(
- IdentityConstants.OpenId.ExchangeAttributes.EXT,
- IdentityConstants.OpenId.ExchangeAttributes.NS_AX));
-
- params.set(new Parameter(
- IdentityConstants.OpenId.ExchangeAttributes.MODE,
- IdentityConstants.OpenId.ExchangeAttributes.FETCH_RESPONSE));
+ setSimpleAttributeParams(params);
- if (ipData.requestedClaims
- .containsKey(IdentityProviderConstants.ATTR_NS_SURNAME)) {
-
- params
- .set(new Parameter(
- IdentityConstants.OpenId.ExchangeAttributes.TYPE
- +
IdentityConstants.OpenId.ExchangeAttributes.SURNAME,
-
IdentityConstants.OpenId.ExchangeAttributes.SURNAME_NS));
- params
- .set(new Parameter(
- IdentityConstants.OpenId.ExchangeAttributes.VALUE
- +
IdentityConstants.OpenId.ExchangeAttributes.SURNAME,
- ((RequestedClaimData) ipData.requestedClaims
-
.get(IdentityProviderConstants.ATTR_NS_SURNAME)).value));
- }
-
- if (ipData.requestedClaims
- .containsKey(IdentityProviderConstants.ATTR_NS_GIVEN_NAME)) {
- params
- .set(new Parameter(
- IdentityConstants.OpenId.ExchangeAttributes.TYPE
- +
IdentityConstants.OpenId.ExchangeAttributes.GIVEN_NAME,
-
IdentityConstants.OpenId.ExchangeAttributes.GIVEN_NAME_NS));
- params
- .set(new Parameter(
- IdentityConstants.OpenId.ExchangeAttributes.VALUE
- +
IdentityConstants.OpenId.ExchangeAttributes.GIVEN_NAME,
- ((RequestedClaimData) ipData.requestedClaims
-
.get(IdentityProviderConstants.ATTR_NS_GIVEN_NAME)).value));
- }
-
- if (ipData.requestedClaims
- .containsKey(IdentityProviderConstants.ATTR_NS_EMAIL_ADDRESS))
{
- params
- .set(new Parameter(
- IdentityConstants.OpenId.ExchangeAttributes.TYPE
- +
IdentityConstants.OpenId.ExchangeAttributes.EMAIL,
-
IdentityConstants.OpenId.ExchangeAttributes.EMAIL_NS));
- params
- .set(new Parameter(
- IdentityConstants.OpenId.ExchangeAttributes.VALUE
- +
IdentityConstants.OpenId.ExchangeAttributes.EMAIL,
- ((RequestedClaimData) ipData.requestedClaims
-
.get(IdentityProviderConstants.ATTR_NS_EMAIL_ADDRESS)).value));
- }
+ message = Message.createMessage(params);
- if (ipData.requestedClaims
-
.containsKey(IdentityProviderConstants.ATTR_NS_STREET_ADDRESS)) {
- params
- .set(new Parameter(
- IdentityConstants.OpenId.ExchangeAttributes.TYPE
- +
IdentityConstants.OpenId.ExchangeAttributes.STREET_ADDRESS,
-
IdentityConstants.OpenId.ExchangeAttributes.STREET_ADDRESS_NS));
- params
- .set(new Parameter(
- IdentityConstants.OpenId.ExchangeAttributes.VALUE
- +
IdentityConstants.OpenId.ExchangeAttributes.STREET_ADDRESS,
- ((RequestedClaimData) ipData.requestedClaims
-
.get(IdentityProviderConstants.ATTR_NS_STREET_ADDRESS)).value));
+ token = new OpenIDInfoCardToken(message);
- }
+ rdt.setText(token.getToken());
- if (ipData.requestedClaims
- .containsKey(IdentityProviderConstants.ATTR_NS_CITY)) {
- params.set(new Parameter(
- IdentityConstants.OpenId.ExchangeAttributes.TYPE
- + IdentityConstants.OpenId.ExchangeAttributes.CITY,
- IdentityConstants.OpenId.ExchangeAttributes.CITY_NS));
- params
- .set(new Parameter(
- IdentityConstants.OpenId.ExchangeAttributes.VALUE
- +
IdentityConstants.OpenId.ExchangeAttributes.CITY,
- ((RequestedClaimData) ipData.requestedClaims
-
.get(IdentityProviderConstants.ATTR_NS_CITY)).value));
+ return rdt;
+ }
- }
+ /**
+ *
+ * @param params
+ */
+ protected void setAttributeExchangeParams(ParameterList params) {
- if (ipData.requestedClaims
- .containsKey(IdentityProviderConstants.ATTR_NS_STATE)) {
- params
- .set(new Parameter(
- IdentityConstants.OpenId.ExchangeAttributes.TYPE
- +
IdentityConstants.OpenId.ExchangeAttributes.STATE,
-
IdentityConstants.OpenId.ExchangeAttributes.STATE_NS));
- params
- .set(new Parameter(
- IdentityConstants.OpenId.ExchangeAttributes.VALUE
- +
IdentityConstants.OpenId.ExchangeAttributes.STATE,
- ((RequestedClaimData) ipData.requestedClaims
-
.get(IdentityProviderConstants.ATTR_NS_STATE)).value));
+ Iterator iterator = null;
+ String key = null;
+ OpenIDRequestedClaimData claim = null;
- }
+ params.set(new Parameter(
+ IdentityConstants.OpenId.ExchangeAttributes.EXT,
+ IdentityConstants.OpenId.ExchangeAttributes.NS_AX));
- if (ipData.requestedClaims
- .containsKey(IdentityProviderConstants.ATTR_NS_POSTAL_CODE)) {
- params
- .set(new Parameter(
- IdentityConstants.OpenId.ExchangeAttributes.TYPE
- +
IdentityConstants.OpenId.ExchangeAttributes.POSTAL_CODE,
-
IdentityConstants.OpenId.ExchangeAttributes.POSTAL_CODE_NS));
- params
- .set(new Parameter(
- IdentityConstants.OpenId.ExchangeAttributes.VALUE
- +
IdentityConstants.OpenId.ExchangeAttributes.POSTAL_CODE,
- ((RequestedClaimData) ipData.requestedClaims
-
.get(IdentityProviderConstants.ATTR_NS_POSTAL_CODE)).value));
+ params.set(new Parameter(
+ IdentityConstants.OpenId.ExchangeAttributes.MODE,
+ IdentityConstants.OpenId.ExchangeAttributes.FETCH_RESPONSE));
- }
+ params.set(new Parameter(
+ IdentityConstants.OpenId.SimpleRegAttributes.OP_SREG,
+ IdentityConstants.OpenId.SimpleRegAttributes.NS_SREG));
- if (ipData.requestedClaims
- .containsKey(IdentityProviderConstants.ATTR_NS_COUNTRY)) {
- params
- .set(new Parameter(
- IdentityConstants.OpenId.ExchangeAttributes.TYPE
- +
IdentityConstants.OpenId.ExchangeAttributes.COUNTRY,
-
IdentityConstants.OpenId.ExchangeAttributes.COUNTRY_NS));
- params
- .set(new Parameter(
- IdentityConstants.OpenId.ExchangeAttributes.VALUE
- +
IdentityConstants.OpenId.ExchangeAttributes.COUNTRY,
- ((RequestedClaimData) ipData.requestedClaims
-
.get(IdentityProviderConstants.ATTR_NS_COUNTRY)).value));
+ iterator = ipData.requestedClaims.keySet().iterator();
+ while (iterator.hasNext()) {
+ key = (String) iterator.next();
+ claim = (OpenIDRequestedClaimData) ipData.requestedClaims.get(key);
+
+ if (claim.openIDTag != null) {
+ params.set(new Parameter(
+ IdentityConstants.OpenId.ExchangeAttributes.TYPE
+ + claim.openIDTag, claim.uri));
+ params.set(new Parameter(
+ IdentityConstants.OpenId.ExchangeAttributes.VALUE
+ + claim.openIDTag, claim.value));
+ }
}
+ }
- if (ipData.requestedClaims
- .containsKey(IdentityProviderConstants.ATTR_NS_HOME_PHONE)) {
- params
- .set(new Parameter(
- IdentityConstants.OpenId.ExchangeAttributes.TYPE
- +
IdentityConstants.OpenId.ExchangeAttributes.HOME_PHONE,
-
IdentityConstants.OpenId.ExchangeAttributes.HOME_PHONE_NS));
- params
- .set(new Parameter(
- IdentityConstants.OpenId.ExchangeAttributes.VALUE
- +
IdentityConstants.OpenId.ExchangeAttributes.HOME_PHONE,
- ((RequestedClaimData) ipData.requestedClaims
-
.get(IdentityProviderConstants.ATTR_NS_HOME_PHONE)).value));
-
- }
+ /**
+ *
+ * @param params
+ */
+ protected void setSimpleAttributeParams(ParameterList params) {
- if (ipData.requestedClaims
- .containsKey(IdentityProviderConstants.ATTR_NS_WORK_PHONE)) {
- params
- .set(new Parameter(
- IdentityConstants.OpenId.ExchangeAttributes.TYPE
- +
IdentityConstants.OpenId.ExchangeAttributes.WORK_PHONE,
-
IdentityConstants.OpenId.ExchangeAttributes.WORK_PHONE_NS));
- params
- .set(new Parameter(
- IdentityConstants.OpenId.ExchangeAttributes.VALUE
- +
IdentityConstants.OpenId.ExchangeAttributes.WORK_PHONE,
- ((RequestedClaimData) ipData.requestedClaims
-
.get(IdentityProviderConstants.ATTR_NS_WORK_PHONE)).value));
+ Iterator iterator = null;
+ String key = null;
+ OpenIDRequestedClaimData claim = null;
- }
+ params.set(new Parameter(
+ IdentityConstants.OpenId.SimpleRegAttributes.OP_SREG,
+ IdentityConstants.OpenId.SimpleRegAttributes.NS_SREG));
- if (ipData.requestedClaims
- .containsKey(IdentityProviderConstants.ATTR_NS_MOBILE_PHONE)) {
- params
- .set(new Parameter(
- IdentityConstants.OpenId.ExchangeAttributes.TYPE
- +
IdentityConstants.OpenId.ExchangeAttributes.MOBILE_PHONE,
-
IdentityConstants.OpenId.ExchangeAttributes.MOBILE_PHONE_NS));
- params
- .set(new Parameter(
- IdentityConstants.OpenId.ExchangeAttributes.VALUE
- +
IdentityConstants.OpenId.ExchangeAttributes.MOBILE_PHONE,
- ((RequestedClaimData) ipData.requestedClaims
-
.get(IdentityProviderConstants.ATTR_NS_MOBILE_PHONE)).value));
+ iterator = ipData.requestedClaims.keySet().iterator();
+ while (iterator.hasNext()) {
+ key = (String) iterator.next();
+ claim = (OpenIDRequestedClaimData) ipData.requestedClaims.get(key);
+
+ if (claim.openIDTag != null)
+ params.set(new Parameter(
+ IdentityConstants.OpenId.SimpleRegAttributes.SREG
+ + claim.openIDTag, claim.value));
}
+ }
- message = Message.createMessage(params);
-
- token = new OpenIDInfoCardToken(message);
-
- rdt.setText(token.getToken());
-
- return rdt;
+ /**
+ *
+ */
+ protected IdentityProviderData getIdentityProviderData(RahasData rahasData)
+ throws Exception {
+ return new OpenIDInfoCardProviderData(rahasData);
}
}
_______________________________________________
Identity-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/identity-dev