本文整理汇总了Java中org.openid4java.message.ax.FetchResponse.getAttributeValues方法的典型用法代码示例。如果您正苦于以下问题:Java FetchResponse.getAttributeValues方法的具体用法?Java FetchResponse.getAttributeValues怎么用?Java FetchResponse.getAttributeValues使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openid4java.message.ax.FetchResponse
的用法示例。
在下文中一共展示了FetchResponse.getAttributeValues方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: receiveAttributeExchange
import org.openid4java.message.ax.FetchResponse; //导入方法依赖的package包/类
/**
* @param httpReq
* @param authSuccess
* @throws MessageException
*/
private void receiveAttributeExchange(HttpServletRequest httpReq,
AuthSuccess authSuccess) throws MessageException {
if (authSuccess.hasExtension(AxMessage.OPENID_NS_AX)) {
FetchResponse fetchResp = (FetchResponse) authSuccess
.getExtension(AxMessage.OPENID_NS_AX);
// List emails = fetchResp.getAttributeValues("email");
// String email = (String) emails.get(0);
List aliases = fetchResp.getAttributeAliases();
Map attributes = new LinkedHashMap();
for (Iterator iter = aliases.iterator(); iter.hasNext();) {
String alias = (String) iter.next();
List values = fetchResp.getAttributeValues(alias);
if (values.size() > 0) {
String[] arr = new String[values.size()];
values.toArray(arr);
attributes.put(alias, StringUtils.join(arr));
}
}
httpReq.setAttribute("attributes", attributes);
}
}
示例2: receiveAttributeExchange
import org.openid4java.message.ax.FetchResponse; //导入方法依赖的package包/类
/**
* @param model
* @param authSuccess
* @throws MessageException
*/
private void receiveAttributeExchange(Map<Object, Object> model, AuthSuccess authSuccess) throws MessageException {
if (authSuccess.hasExtension(AxMessage.OPENID_NS_AX)) {
FetchResponse fetchResp = (FetchResponse) authSuccess.getExtension(AxMessage.OPENID_NS_AX);
List<String> aliases = fetchResp.getAttributeAliases();
Map<String, String> attributes = new LinkedHashMap<>();
for (String alias : aliases) {
List<String> values = fetchResp.getAttributeValues(alias);
if (values.size() > 0) {
String[] arr = new String[values.size()];
values.toArray(arr);
attributes.put(alias, arr[0]);
}
}
model.put("attributes", attributes);
}
}
示例3: verifyResponse
import org.openid4java.message.ax.FetchResponse; //导入方法依赖的package包/类
public Identifier verifyResponse(HttpServletRequest httpReq) {
try {
// extract the parameters from the authentication response
// (which comes in as a HTTP request from the OpenID provider)
ParameterList response = new ParameterList(httpReq.getParameterMap());
// retrieve the previously stored discovery information
DiscoveryInformation discovered = (DiscoveryInformation) httpReq.getSession().getAttribute(OpenIdConstants.OPENID_DISC);
// extract the receiving URL from the HTTP request
StringBuffer receivingURL = httpReq.getRequestURL();
String queryString = httpReq.getQueryString();
if (queryString != null && queryString.length() > 0)
receivingURL.append("?").append(httpReq.getQueryString());
// verify the response; ConsumerManager needs to be the same
// (static) instance used to place the authentication request
VerificationResult verification = manager.verify(receivingURL.toString(), response, discovered);
// examine the verification result and extract the verified
// identifier
Identifier verified = verification.getVerifiedId();
if (verified != null) {
AuthSuccess authSuccess = (AuthSuccess) verification.getAuthResponse();
if (authSuccess.hasExtension(AxMessage.OPENID_NS_AX)) {
FetchResponse fetchResp = (FetchResponse) authSuccess.getExtension(AxMessage.OPENID_NS_AX);
List<?> emails = fetchResp.getAttributeValues("email");
String email = (String) emails.get(0);
httpReq.getSession().setAttribute(OpenIdConstants.OPENID_SESSION_VAR, new OpenIDUser(email));
}
return verified; // success
}
} catch (OpenIDException e) {
// present error to the user
}
return null;
}