📄 openidinfocardproviderdata.java
字号:
/*
* Copyright 2005-2008 WSO2, Inc. (http://wso2.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wso2.solutions.identity.openid.infocard;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.rahas.RahasData;
import org.wso2.solutions.identity.IdentityConstants;
import org.wso2.solutions.identity.IdentityProviderException;
import org.wso2.solutions.identity.UserStore;
import org.wso2.solutions.identity.persistence.dataobject.ClaimDO;
import org.wso2.solutions.identity.sts.IdentityProviderData;
public class OpenIDInfoCardProviderData extends IdentityProviderData {
private static Map<String, String> axMapping = new HashMap<String, String>();
static {
axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.EMAIL_NS,
IdentityConstants.CLAIM_EMAIL_ADDRESS);
axMapping.put(
IdentityConstants.OpenId.ExchangeAttributes.POSTAL_CODE_NS,
IdentityConstants.CLAIM_POSTAL_CODE);
axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.NICK_NAME_NS,
IdentityConstants.CLAIM_NICKNAME);
axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.COUNTRY_NS,
IdentityConstants.CLAIM_COUNTRY);
axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.FULL_NAME_NS,
IdentityConstants.OpenId.SimpleRegAttributes.FULL_NAME);
axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.DOB_NS,
IdentityConstants.OpenId.SimpleRegAttributes.DOB_NS);
axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.TIMEZONE_NS,
IdentityConstants.OpenId.SimpleRegAttributes.TIMEZONE_NS);
axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.GENDER_NS,
IdentityConstants.OpenId.SimpleRegAttributes.GENDER_NS);
axMapping.put(IdentityConstants.OpenId.ExchangeAttributes.LANGUAGE_NS,
IdentityConstants.OpenId.SimpleRegAttributes.LANGUAGE_NS);
}
/**
* This provides a mapping between http://schema.openid.net/ and
* http://axschema.org
* @param val schema name-space URL
* @return mapped value
*/
protected String getMappedAxSchema(String val) {
if (axMapping.containsKey(val)) {
return axMapping.get(val);
}
return val;
}
/**
* Populate CardSpace specific meta-data.
* @param data WS-Trust information in the issue request.
* @throws IdentityProviderException
* @throws ClassNotFoundException
*/
public OpenIDInfoCardProviderData(RahasData data)
throws IdentityProviderException, ClassNotFoundException {
super(data);
}
/**
* This overrides the base class functionality to suit the OpenID related
* functionality.
*/
protected void populateClaimValues(RahasData rahasData)
throws IdentityProviderException {
UserStore connector = null;
Iterator iterator = null;
List<String> list = null;
OpenIDRequestedClaimData requestedClaimData = null;
String userId = null;
Map<String, String> mapValues = null;
ClaimDO claimDO = null;
String attrId = null;
String claimVal = null;
ClaimDO claim = null;
connector = UserStore.getInstance();
// Get the column names for the URIs
iterator = requestedClaims.values().iterator();
list = new ArrayList<String>();
// First we need to figure-out which attributed we need to retrieve from
// the user store.
while (iterator.hasNext()) {
requestedClaimData = (OpenIDRequestedClaimData) iterator.next();
claim = (ClaimDO) claimObjs
.get(getMappedAxSchema(requestedClaimData.uri));
if (claim != null
&& !claim.getUri().equals(IdentityConstants.CLAIM_PPID)) {
list.add(claim.getAttrId());
}
}
// Get the user id.
userId = getUserIdentifier();
// Get the claims values corresponding to the user from the user store.
mapValues = connector.getClaimValues(userId, list);
iterator = requestedClaims.values().iterator();
// Iterate through the claim values retrieved and requestedClaims will
// be populated with the corresponding values.
while (iterator.hasNext()) {
requestedClaimData = (OpenIDRequestedClaimData) iterator.next();
claimDO = ((ClaimDO) this.claimObjs
.get(getMappedAxSchema(requestedClaimData.uri)));
attrId = claimDO.getAttrId();
claimVal = (String) mapValues.get(attrId);
requestedClaimData.value = claimVal;
requestedClaimData.openIDTag = claimDO.getOpenIDTag();
}
}
/**
* This overrides the base class functionality to suit the OpenID related
* functionality.
*/
protected RequestedClaimData getRequestedClaim() {
return new OpenIDRequestedClaimData();
}
/**
* This class is related to the OpenID functionality. All the claims which
* support OpenID should have OpenIDTag defined for it.
*/
public class OpenIDRequestedClaimData extends RequestedClaimData {
public String openIDTag;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -