本文整理汇总了Java中org.openid4java.message.ax.FetchResponse类的典型用法代码示例。如果您正苦于以下问题:Java FetchResponse类的具体用法?Java FetchResponse怎么用?Java FetchResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FetchResponse类属于org.openid4java.message.ax包,在下文中一共展示了FetchResponse类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: setAttributeExchangeValues
import org.openid4java.message.ax.FetchResponse; //导入依赖的package包/类
/**
* Populate the response with claim values. If we can't find the required values with us, we
* simply avoid sending them. An Identity Provider MAY return any subset of the following fields
* in response to the query.
*
* @param claimValues Claim values.
* @throws MessageException
*/
protected void setAttributeExchangeValues(FetchResponse response,
Map<String, OpenIDClaimDTO> claimValues) throws MessageException {
Iterator<Entry<String, OpenIDClaimDTO>> iterator = null;
Entry<String, OpenIDClaimDTO> entry = null;
OpenIDClaimDTO claim = null;
iterator = claimValues.entrySet().iterator();
while (iterator.hasNext()) {
entry = iterator.next();
claim = entry.getValue();
response.addAttribute(claim.getClaimUri(), claim.getClaimValue());
}
}
示例3: 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);
}
}
示例4: createProfile
import org.openid4java.message.ax.FetchResponse; //导入依赖的package包/类
@Override
protected YahooOpenIdProfile createProfile(final AuthSuccess authSuccess) throws MessageException, HttpAction {
final YahooOpenIdProfile profile = new YahooOpenIdProfile();
if (authSuccess.hasExtension(AxMessage.OPENID_NS_AX)) {
final FetchResponse fetchResp = (FetchResponse) authSuccess.getExtension(AxMessage.OPENID_NS_AX);
for (final String name : profile.getAttributesDefinition().getPrimaryAttributes()) {
profile.addAttribute(name, fetchResp.getAttributeValue(name));
}
}
return profile;
}
示例5: processAxExtension
import org.openid4java.message.ax.FetchResponse; //导入依赖的package包/类
private Message processAxExtension(Message token, final AuthRequest authRequest) throws MessageException {
if (authRequest.hasExtension(AxMessage.OPENID_NS_AX)) {
MessageExtension extension = authRequest.getExtension(AxMessage.OPENID_NS_AX);
if (extension instanceof FetchRequest) {
final FetchRequest fetchRequest = (FetchRequest) extension;
final Map userDataMap = getValidUser().getUserDataMap();
final FetchResponse fetchResponse = FetchResponse.createFetchResponse(fetchRequest, userDataMap);
token.addExtension(fetchResponse, "ax");
} else {
throw new UnsupportedOperationException("TODO: if (ext instanceof StoreRequest)");
}
}
return token;
}
示例6: addAttributes
import org.openid4java.message.ax.FetchResponse; //导入依赖的package包/类
/**
* Add attributes to the response message.
*
* @param response
* the response message to add to
* @throws MessageException
* if add failed
*/
private void addAttributes(final Message response, Persona persona)
throws MessageException {
if (authRequest.hasExtension(AxMessage.OPENID_NS_AX)) {
MessageExtension ext = authRequest
.getExtension(AxMessage.OPENID_NS_AX);
if (ext instanceof FetchRequest) {
FetchRequest fetchReq = (FetchRequest) ext;
FetchResponse fetchResp = FetchResponse.createFetchResponse();
@SuppressWarnings("unchecked")
Map<String, String> attributes = (Map<String, String>) fetchReq
.getAttributes();
Map<String, String> typeValueMap = persona.toTypeValueMap();
Map<String, String> aliasValueMap = persona.toAliasValueMap();
for (Map.Entry<String, String> entry : attributes.entrySet()) {
String alias = entry.getKey();
String type = entry.getValue();
String value = typeValueMap.get(type);
if (value == null) {
value = aliasValueMap.get(alias);
}
if (value != null) {
fetchResp.addAttribute(alias, type, value);
}
Attribute attribute = persona.getAttributeByType(type);
if (attribute != null) {
for (String v : attribute.getValues()) {
fetchResp.addAttribute(alias, type, v);
}
}
}
response.addExtension(fetchResp);
} else { // if (ext instanceof StoreRequest)
throw new UnsupportedOperationException(ext.getClass()
+ " is unsupported.");
}
}
}
示例7: isAuthenticationValid
import org.openid4java.message.ax.FetchResponse; //导入依赖的package包/类
/**
* Validates the authentication.
*
* @param a_oRequest The request containing the authentication information.
* @return true if the authentication is valid, otherwise false.
* @throws OpenIDException
* @author zschwenk
*/
public String isAuthenticationValid(HttpServletRequest a_oRequest)
throws OpenIDException
{
String identifier = null;
// extract the parameters from the authentication response
// (which comes in as a HTTP request from the OpenID provider)
ParameterList lstResponse =
new ParameterList(a_oRequest.getParameterMap());
// retrieve the previously stored discovery information
DiscoveryInformation discovered = (DiscoveryInformation)a_oRequest.getSession().getAttribute("openid-disc");
// extract the receiving URL from the HTTP request
StringBuffer receivingURL = a_oRequest.getRequestURL();
String queryString = a_oRequest.getQueryString();
if (queryString != null && queryString.length() > 0)
receivingURL.append("?").append(a_oRequest.getQueryString());
// verify the response; ConsumerManager needs to be the same
// (static) instance used to place the authentication request
VerificationResult verification = m_oManager.verify(
receivingURL.toString(),
lstResponse, 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);
if (fetchResp.getAttributeValue("email") != null) {
this.email = fetchResp.getAttributeValue("email");
}
if (fetchResp.getAttributeValue("altemail") != null && this.email == null) {
this.email = fetchResp.getAttributeValue("altemail");
}
if (fetchResp.getAttributeValue("first") != null) {
this.name = fetchResp.getAttributeValue("first");
}
String userName = (this.name == null) ? "" : this.name+" ";
if (fetchResp.getAttributeValue("last") != null) {
userName += fetchResp.getAttributeValue("last");
this.name = userName;
}
}
identifier = verified.getIdentifier();
}
return identifier;
}
示例8: 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("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();
HttpSession session = httpReq.getSession(true);
session.setAttribute("openid_identifier", authSuccess.getIdentity());
if (authSuccess.hasExtension(AxMessage.OPENID_NS_AX))
{
FetchResponse fetchResp = (FetchResponse) authSuccess.getExtension(AxMessage.OPENID_NS_AX);
session.setAttribute("emailFromFetch", fetchResp.getAttributeValues("email").get(0));
}
if (authSuccess.hasExtension(SRegMessage.OPENID_NS_SREG))
{
SRegResponse sregResp = (SRegResponse) authSuccess.getExtension(SRegMessage.OPENID_NS_SREG);
session.setAttribute("emailFromSReg", sregResp.getAttributeValue("email"));
}
return verified; // success
}
}
catch (OpenIDException e)
{
// present error to the user
throw new RuntimeException("wrap:" + e.getMessage(), e);
}
return null;
}
示例9: 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;
}