Author: prabath
Date: Mon Jan 21 01:48:08 2008
New Revision: 12579
Log:
removed hard-coded claim values
Modified:
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/openid/OpenIDProvider.java
Modified:
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/openid/OpenIDProvider.java
==============================================================================
---
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/openid/OpenIDProvider.java
(original)
+++
trunk/solutions/identity/modules/identity-provider/src/main/java/org/wso2/solutions/identity/openid/OpenIDProvider.java
Mon Jan 21 01:48:08 2008
@@ -37,26 +37,6 @@
public static ServerManager manager = new ServerManager();
private String authPage;
- // These are the constants used to represent attributes required by the
- // OpenID.
- private final static String FULL_NAME = "fullname";
- private final static String NICK_NAME = "nickname";
- private final static String GIVEN_NAME = "givenname";
- private final static String SURNAME = "surname";
- private final static String EMAIL = "email";
- private final static String HOME_PHONE = "phone";
- private final static String WORK_PHONE = "phone";
- private final static String MOBILE_PHONE = "phone";
- private final static String ADDRESS = "address";
- private final static String CITY = "city";
- private final static String STATE = "state";
- private final static String COUNTRY = "country";
- private final static String TIMEZONE = "timezone";
- private final static String POSTAL_CODE = "postalcode";
- private final static String DOB = "dob";
- private final static String GENDER = "gender";
- private final static String LANGUAGE = "language";
-
private final static int EXPIRES_IN = 1000;
private static String opAddress = null;
@@ -86,8 +66,7 @@
* @throws AssociationException
*/
public static Association getAssocHandle() throws AssociationException {
- Association association = null;
-
+
return manager.getPrivateAssociations().generate(
org.openid4java.association.Association.TYPE_HMAC_SHA1,
EXPIRES_IN);
@@ -171,14 +150,17 @@
boolean authenticatedAndApproved = false;
String userSelectedClaimedId = null;
String openId = null;
+ String userId = null;
openId = request
.hasParameter(IdentityConstants.OpenId.ATTR_IDENTITY) ?
request
.getParameterValue(IdentityConstants.OpenId.ATTR_IDENTITY)
: null;
+ userId = getUserName(openId);
+
// Authenticate the user.
- authenticatedAndApproved = doLogin(getNickName(openId), httpReq
+ authenticatedAndApproved = doLogin(userId, httpReq
.getParameter(IdentityProviderConstants.OpenId.PASSWORD));
if (!authenticatedAndApproved) {
@@ -212,6 +194,8 @@
Map userDataExt = null;
FetchRequest fetchReq = null;
FetchResponse fetchResp = null;
+ OpenIDProviderData openIDData = null;
+ Map claimValues = null;
fetchReq = (FetchRequest) extensions;
required = fetchReq.getAttributes(true);
@@ -219,8 +203,12 @@
fetchResp = FetchResponse.createFetchResponse(fetchReq,
userDataExt);
- setAttributeExchange(fetchResp, required,
- getUserData(openId));
+ openIDData = new OpenIDProviderData();
+
+ claimValues = openIDData.populateAttributeValues(
+ required, userId);
+
+ openIDData.setAttributeExchangeValues(fetchResp,
claimValues);
message.addExtension(fetchResp);
} else {
@@ -238,7 +226,9 @@
SRegRequest sregReq = null;
List required = null;
Map userDataSReg = null;
+ Map claimValues = null;
SRegResponse response = null;
+ OpenIDProviderData openIDData = null;
sregReq = (SRegRequest) extension;
required = sregReq.getAttributes(true);
@@ -247,8 +237,11 @@
response = SRegResponse.createSRegResponse(sregReq,
userDataSReg);
- setAttributeExchange(response, required,
- getUserData(openId));
+ openIDData = new OpenIDProviderData();
+ claimValues = openIDData.populateAttributeValues(
+ required, userId);
+
+
openIDData.setSimpleAttributeRegistrationValues(response, claimValues);
message.addExtension(response);
@@ -276,201 +269,11 @@
/**
*
- * @param response
- * @param required
- * @param claimValues
- * @throws MessageException
- */
- private void setAttributeExchange(SRegResponse response, List required,
- Map<String, String> claimValues) throws MessageException {
-
- // If we can't find the required values with us, we simply add a null
- // value it.
- // Caller should verify whether he has got non-null values to all
- // required attributes.
- // If not, what to do is up to the caller.
-
- // An Identity Provider MAY return any subset of the following fields
in
- // response to the query.
-
- if (required
- .contains(IdentityConstants.OpenId.SimpleRegAttributes.EMAIL))
{
- response.addAttribute(
- IdentityConstants.OpenId.SimpleRegAttributes.EMAIL,
- claimValues.get(EMAIL));
- }
-
- if (required
-
.contains(IdentityConstants.OpenId.SimpleRegAttributes.NICK_NAME)) {
- response.addAttribute(
- IdentityConstants.OpenId.SimpleRegAttributes.NICK_NAME,
- claimValues.get(NICK_NAME));
- }
-
- if (required
-
.contains(IdentityConstants.OpenId.SimpleRegAttributes.FULL_NAME)) {
- response.addAttribute(
- IdentityConstants.OpenId.SimpleRegAttributes.FULL_NAME,
- claimValues.get(FULL_NAME));
- }
-
- if (required
-
.contains(IdentityConstants.OpenId.SimpleRegAttributes.COUNTRY)) {
- response.addAttribute(
- IdentityConstants.OpenId.SimpleRegAttributes.COUNTRY,
- claimValues.get(COUNTRY));
- }
-
- if (required
-
.contains(IdentityConstants.OpenId.SimpleRegAttributes.POSTAL_CODE)) {
- response.addAttribute(
- IdentityConstants.OpenId.SimpleRegAttributes.POSTAL_CODE,
- claimValues.get(POSTAL_CODE));
- }
-
- if
(required.contains(IdentityConstants.OpenId.SimpleRegAttributes.DOB)) {
- response.addAttribute(
- IdentityConstants.OpenId.SimpleRegAttributes.DOB,
- claimValues.get(DOB));
- }
- if (required
-
.contains(IdentityConstants.OpenId.SimpleRegAttributes.GENDER)) {
- response.addAttribute(
- IdentityConstants.OpenId.SimpleRegAttributes.GENDER,
- claimValues.get(GENDER));
- }
-
- if (required
-
.contains(IdentityConstants.OpenId.SimpleRegAttributes.LANGUAGE)) {
- response.addAttribute(
- IdentityConstants.OpenId.SimpleRegAttributes.LANGUAGE,
- claimValues.get(LANGUAGE));
- }
-
- if (required
-
.contains(IdentityConstants.OpenId.SimpleRegAttributes.TIMEZONE)) {
- response.addAttribute(
- IdentityConstants.OpenId.SimpleRegAttributes.TIMEZONE,
- claimValues.get(TIMEZONE));
- }
-
- }
-
- /**
- *
- * @param response
- * @param required
- * @param claimValues
- * @throws MessageException
- */
- private void setAttributeExchange(FetchResponse response, Map required,
- Map<String, String> claimValues) throws MessageException {
-
- // If we can't find the required values with us, we simply add a null
- // value it.
- // Caller should verify whether he has got non-null values to all
- // required attributes.
- // If not, what to do is up to the caller..
-
- if (required
-
.containsKey(IdentityConstants.OpenId.ExchangeAttributes.EMAIL)) {
- response.addAttribute(
- IdentityConstants.OpenId.ExchangeAttributes.EMAIL,
- IdentityConstants.OpenId.ExchangeAttributes.EMAIL_NS,
- claimValues.get(EMAIL));
- }
-
- if (required
-
.containsKey(IdentityConstants.OpenId.ExchangeAttributes.STREET_ADDRESS)) {
- response
- .addAttribute(
-
IdentityConstants.OpenId.ExchangeAttributes.STREET_ADDRESS,
-
IdentityConstants.OpenId.ExchangeAttributes.STREET_ADDRESS_NS,
- claimValues.get(ADDRESS));
- }
-
- if (required
-
.containsKey(IdentityConstants.OpenId.ExchangeAttributes.CITY)) {
- response.addAttribute(
- IdentityConstants.OpenId.ExchangeAttributes.CITY,
- IdentityConstants.OpenId.ExchangeAttributes.CITY_NS,
- claimValues.get(CITY));
- }
-
- if (required
-
.containsKey(IdentityConstants.OpenId.ExchangeAttributes.COUNTRY)) {
- response.addAttribute(
- IdentityConstants.OpenId.ExchangeAttributes.COUNTRY,
- IdentityConstants.OpenId.ExchangeAttributes.COUNTRY_NS,
- claimValues.get(COUNTRY));
- }
-
- if (required
-
.containsKey(IdentityConstants.OpenId.ExchangeAttributes.GIVEN_NAME)) {
- response.addAttribute(
- IdentityConstants.OpenId.ExchangeAttributes.GIVEN_NAME,
- IdentityConstants.OpenId.ExchangeAttributes.GIVEN_NAME_NS,
- claimValues.get(GIVEN_NAME));
- }
-
- if (required
-
.containsKey(IdentityConstants.OpenId.ExchangeAttributes.SURNAME)) {
- response.addAttribute(
- IdentityConstants.OpenId.ExchangeAttributes.SURNAME,
- IdentityConstants.OpenId.ExchangeAttributes.SURNAME_NS,
- claimValues.get(SURNAME));
- }
-
- if (required
-
.containsKey(IdentityConstants.OpenId.ExchangeAttributes.HOME_PHONE)) {
- response.addAttribute(
- IdentityConstants.OpenId.ExchangeAttributes.HOME_PHONE,
- IdentityConstants.OpenId.ExchangeAttributes.HOME_PHONE_NS,
- claimValues.get(HOME_PHONE));
- }
-
- if (required
-
.containsKey(IdentityConstants.OpenId.ExchangeAttributes.WORK_PHONE)) {
- response.addAttribute(
- IdentityConstants.OpenId.ExchangeAttributes.WORK_PHONE,
- IdentityConstants.OpenId.ExchangeAttributes.WORK_PHONE_NS,
- claimValues.get(WORK_PHONE));
- }
-
- if (required
-
.containsKey(IdentityConstants.OpenId.ExchangeAttributes.MOBILE_PHONE)) {
- response
- .addAttribute(
-
IdentityConstants.OpenId.ExchangeAttributes.MOBILE_PHONE,
-
IdentityConstants.OpenId.ExchangeAttributes.MOBILE_PHONE_NS,
- claimValues.get(MOBILE_PHONE));
- }
-
- if (required
-
.containsKey(IdentityConstants.OpenId.ExchangeAttributes.POSTAL_CODE)) {
- response.addAttribute(
- IdentityConstants.OpenId.ExchangeAttributes.POSTAL_CODE,
- IdentityConstants.OpenId.ExchangeAttributes.POSTAL_CODE_NS,
- claimValues.get(POSTAL_CODE));
- }
-
- if (required
-
.containsKey(IdentityConstants.OpenId.ExchangeAttributes.STATE)) {
- response.addAttribute(
- IdentityConstants.OpenId.ExchangeAttributes.STATE,
- IdentityConstants.OpenId.ExchangeAttributes.STATE_NS,
- claimValues.get(STATE));
- }
-
- }
-
- /**
- *
* @return
* @throws ServerException
* @throws IdentityProviderException
*/
- private String getNickName(String openId) throws ServerException,
+ private String getUserName(String openId) throws ServerException,
IdentityProviderException {
UserStore userStore = null;
@@ -513,187 +316,6 @@
/**
*
- * @param openId
- * @return
- * @throws ServerException
- * @throws IdentityProviderException
- */
- private Map<String, String> getUserData(String openId)
- throws ServerException, IdentityProviderException {
-
- Map<String, String> claimValues = null;
- UserStore userStore = null;
- List claimList = null;
- List users = null;
- Map mapValues = null;
-
- claimValues = new HashMap<String, String>();
-
- userStore = UserStore.getInstance();
- users = userStore.getAllUserNames();
-
- if (users == null)
- throw new IdentityProviderException("No users found");
-
- Iterator iterator = users.iterator();
-
- while (iterator.hasNext()) {
-
- String user = (String) iterator.next();
- mapValues = userStore.getClaimValues(user, null);
-
- if (mapValues != null) {
-
- // User has defined claims!
- String claimId = (String) mapValues
- .get(IdentityConstants.CLAIM_OPENID);
-
- if (mapValues != null && !mapValues.isEmpty()) {
- if (openId.indexOf(claimId) >= 0
- && openId.endsWith(claimId.substring(claimId
- .length() - 1))) {
-
- // first name
- if (mapValues
-
.containsKey(IdentityConstants.CLAIM_GIVEN_NAME))
- claimValues.put(GIVEN_NAME, (String) mapValues
- .get(IdentityConstants.CLAIM_GIVEN_NAME));
- else
- claimValues.put(GIVEN_NAME, "none");
-
- // last name
- if (mapValues
- .containsKey(IdentityConstants.CLAIM_SURNAME))
- claimValues.put(SURNAME, (String) mapValues
- .get(IdentityConstants.CLAIM_SURNAME));
- else
- claimValues.put(SURNAME, "none");
-
- // full name
- if (mapValues
-
.containsKey(IdentityConstants.CLAIM_GIVEN_NAME)
- && mapValues
-
.containsKey(IdentityConstants.CLAIM_SURNAME))
- claimValues
- .put(
- FULL_NAME,
- (String) mapValues
-
.get(IdentityConstants.CLAIM_GIVEN_NAME)
- + " "
- + (String) mapValues
-
.get(IdentityConstants.CLAIM_SURNAME));
- else if (mapValues
-
.containsKey(IdentityConstants.CLAIM_GIVEN_NAME)
- && !mapValues
-
.containsKey(IdentityConstants.CLAIM_SURNAME))
- claimValues.put(FULL_NAME, (String) mapValues
- .get(IdentityConstants.CLAIM_GIVEN_NAME));
- else if (!mapValues
-
.containsKey(IdentityConstants.CLAIM_GIVEN_NAME)
- && mapValues
-
.containsKey(IdentityConstants.CLAIM_SURNAME))
- claimValues.put(FULL_NAME, (String) mapValues
- .get(IdentityConstants.CLAIM_SURNAME));
- else
- claimValues.put(FULL_NAME, "none");
-
- // nick name
- claimValues.put(NICK_NAME, user);
-
- // email address
- if (mapValues
-
.containsKey(IdentityConstants.CLAIM_EMAIL_ADDRESS))
- claimValues
- .put(
- EMAIL,
- (String) mapValues
-
.get(IdentityConstants.CLAIM_EMAIL_ADDRESS));
- else
- claimValues.put(EMAIL, "none");
-
- // home phone
- if (mapValues
-
.containsKey(IdentityConstants.CLAIM_HOME_PHONE))
- claimValues.put(HOME_PHONE, (String) mapValues
- .get(IdentityConstants.CLAIM_HOME_PHONE));
- else
- claimValues.put(HOME_PHONE, "none");
-
- // work phone
- if (mapValues
-
.containsKey(IdentityConstants.CLAIM_WORK_PHONE))
- claimValues.put(WORK_PHONE, (String) mapValues
- .get(IdentityConstants.CLAIM_WORK_PHONE));
- else
- claimValues.put(WORK_PHONE, "none");
-
- // mobile phone
- if (mapValues
-
.containsKey(IdentityConstants.CLAIM_MOBILE_PHONE))
- claimValues.put(MOBILE_PHONE, (String) mapValues
-
.get(IdentityConstants.CLAIM_MOBILE_PHONE));
- else
- claimValues.put(MOBILE_PHONE, "none");
-
- // address
- if (mapValues
-
.containsKey(IdentityConstants.CLAIM_STREET_ADDRESS))
- claimValues
- .put(
- ADDRESS,
- (String) mapValues
-
.get(IdentityConstants.CLAIM_STREET_ADDRESS));
- else
- claimValues.put(ADDRESS, "none");
-
- // city
- if
(mapValues.containsKey(IdentityConstants.CLAIM_CITY))
- claimValues.put(CITY, (String) mapValues
- .get(IdentityConstants.CLAIM_CITY));
- else
- claimValues.put(CITY, "none");
-
- // state
- if (mapValues
- .containsKey(IdentityConstants.CLAIM_STATE))
- claimValues.put(STATE, (String) mapValues
- .get(IdentityConstants.CLAIM_STATE));
- else
- claimValues.put(STATE, "none");
-
- // zipcode
- if (mapValues
-
.containsKey(IdentityConstants.CLAIM_POSTAL_CODE))
- claimValues.put(POSTAL_CODE, (String) mapValues
- .get(IdentityConstants.CLAIM_POSTAL_CODE));
- else
- claimValues.put(POSTAL_CODE, "none");
-
- // country
- if (mapValues
- .containsKey(IdentityConstants.CLAIM_COUNTRY))
- claimValues.put(COUNTRY, (String) mapValues
- .get(IdentityConstants.CLAIM_COUNTRY));
- else
- claimValues.put(COUNTRY, "none");
-
- // TODO: Add values
- claimValues.put(TIMEZONE, "none");
- claimValues.put(DOB, "none");
- claimValues.put(GENDER, "none");
- claimValues.put(LANGUAGE, "none");
-
- break;
- }
- }
- }
- }
-
- return claimValues;
- }
-
- /**
- *
* @param user
* @return
*/
@@ -750,7 +372,16 @@
* @param authPage
*/
public void setAuthPage(String authPage) {
- this.authPage = authPage;
+
+ ServerConfiguration serverConfig = null;
+ String host = null;
+ String httpsPort = null;
+
+ serverConfig = ServerConfiguration.getInstance();
+ host = serverConfig.getFirstProperty("HostName");
+ httpsPort = serverConfig.getFirstProperty("Ports.HTTPS");
+
+ this.authPage = "https://" + host + ":" + httpsPort + "/" + authPage;
}
/**
_______________________________________________
Identity-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/identity-dev