本文整理汇总了Java中org.openid4java.message.ax.FetchRequest类的典型用法代码示例。如果您正苦于以下问题:Java FetchRequest类的具体用法?Java FetchRequest怎么用?Java FetchRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FetchRequest类属于org.openid4java.message.ax包,在下文中一共展示了FetchRequest类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addAttributeExchangeToAuthRequest
import org.openid4java.message.ax.FetchRequest; //导入依赖的package包/类
/**
* Attribute exchange example.
*
* @param httpReq
* @param authReq
* @throws MessageException
* @see <a href="http://code.google.com/p/openid4java/wiki/AttributeExchangeHowTo">Attribute Exchange HowTo</a>
* @see <a href="http://openid.net/specs/openid-attribute-exchange-1_0.html">OpenID Attribute Exchange 1.0 - Final</a>
*/
private void addAttributeExchangeToAuthRequest(HttpServletRequest httpReq,
AuthRequest authReq) throws MessageException {
String[] aliases = httpReq.getParameterValues("alias");
String[] typeUris = httpReq.getParameterValues("typeUri");
String[] counts = httpReq.getParameterValues("count");
FetchRequest fetch = FetchRequest.createFetchRequest();
for (int i = 0, l = typeUris == null ? 0 : typeUris.length; i < l; i++) {
String typeUri = typeUris[i];
if (StringUtils.isNotBlank(typeUri)) {
String alias = aliases[i];
boolean required = httpReq.getParameter("required" + i) != null;
int count = NumberUtils.toInt(counts[i], 1);
fetch.addAttribute(alias, typeUri, required, count);
}
}
authReq.addExtension(fetch);
}
示例2: getFetchRequest
import org.openid4java.message.ax.FetchRequest; //导入依赖的package包/类
@Override
protected FetchRequest getFetchRequest() throws MessageException {
final FetchRequest fetchRequest = FetchRequest.createFetchRequest();
fetchRequest.addAttribute(YahooOpenIdAttributesDefinition.EMAIL,
"http://axschema.org/contact/email", true);
fetchRequest.addAttribute(YahooOpenIdAttributesDefinition.FULLNAME,
"http://axschema.org/namePerson", true);
fetchRequest.addAttribute(YahooOpenIdAttributesDefinition.LANGUAGE,
"http://axschema.org/pref/language", true);
fetchRequest.addAttribute(YahooOpenIdAttributesDefinition.PROFILEPICTURE,
"http://axschema.org/media/image/default", true);
logger.debug("fetchRequest: {}", fetchRequest);
return fetchRequest;
}
示例3: retrieveRedirectAction
import org.openid4java.message.ax.FetchRequest; //导入依赖的package包/类
@Override
@SuppressWarnings("rawtypes")
protected RedirectAction retrieveRedirectAction(final WebContext context) throws HttpAction {
final String userIdentifier = getUser(context);
CommonHelper.assertNotBlank("openIdUser", userIdentifier);
try {
// perform discovery on the user-supplied identifier
final List discoveries = this.consumerManager.discover(userIdentifier);
// attempt to associate with the OpenID provider
// and retrieve one service endpoint for authentication
final DiscoveryInformation discoveryInformation = this.consumerManager.associate(discoveries);
// save discovery information in session
context.setSessionAttribute(getDiscoveryInformationSessionAttributeName(), discoveryInformation);
// create authentication request to be sent to the OpenID provider
final AuthRequest authRequest = this.consumerManager.authenticate(discoveryInformation,
computeFinalCallbackUrl(context));
// create fetch request for attributes
final FetchRequest fetchRequest = getFetchRequest();
if (fetchRequest != null) {
authRequest.addExtension(fetchRequest);
}
final String redirectionUrl = authRequest.getDestinationUrl(true);
logger.debug("redirectionUrl: {}", redirectionUrl);
return RedirectAction.redirect(redirectionUrl);
} catch (final OpenIDException e) {
throw new TechnicalException("OpenID exception", e);
}
}
示例4: InfocardInvocation
import org.openid4java.message.ax.FetchRequest; //导入依赖的package包/类
/**
* Creates an InfocardInvocation object from an Attribute Exchange
* Fetch Request.
* <p>
* Attriute type URIs are mapped to Infocard claim URIs.
* Attribute value count and update_url features are cannot be
* expressed in InfocardInvocation data structures.
*
* @param fetch The Fetch Request.
*/
public InfocardInvocation(FetchRequest fetch)
{
_requiredClaims.add(OpenIDTokenType.OPENID_CLAIM);
_tokenType = OpenIDTokenType.OPENID20_TOKEN;
_requiredClaims.addAll(fetch.getAttributes(true).values());
_optionalClaims.addAll(fetch.getAttributes(false).values());
if (DEBUG)
_log.debug("Created " + _tokenType +
" token type InfocardInvocation from a FetchRequest.");
}
示例5: processAxExtension
import org.openid4java.message.ax.FetchRequest; //导入依赖的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: requestHandler
import org.openid4java.message.ax.FetchRequest; //导入依赖的package包/类
@Path("/Request")
@GET
@POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response requestHandler(@Context HttpServletRequest request, @Context HttpServletResponse response,
@QueryParam("idRequest") String idReq) throws Exception {
try {
byte[] decodedIdreq = Base64.decodeBase64(idReq);
IdentityRequest idRequest = (IdentityRequest) jsonToObject(decodedIdreq, IdentityRequest.class);
log.debug("openid_identifier_operation : ", idRequest.getIdentifier());
log.debug("instantiating manager");
log.debug("manager instantiated ");
String returnToUrl = idRequest.getReturnToUrl();
log.debug("getting list of discoveries");
List discoveries = manager.discover(idRequest.getIdentifier());
log.debug("retrieving descovered");
DiscoveryInformation discovered = manager.associate(discoveries);
log.debug("saving request");
request.getSession().setAttribute("openid-disc", discovered);
log.debug("instantiating AuthRequest");
AuthRequest authReq = manager.authenticate(discovered, returnToUrl, idRequest.getRealm());
FetchRequest fetch = FetchRequest.createFetchRequest();
if (idRequest.getAxschema().contains("axschema")) {
fetch.addAttribute("nickname", "http://axschema.org/namePerson/friendly", true);
fetch.addAttribute("fullname", "http://axschema.org/namePerson", true);
fetch.addAttribute("email", "http://axschema.org/contact/email", true);
fetch.addAttribute("gender", "http://axschema.org/person/gender", true);
fetch.addAttribute("language", "http://axschema.org/pref/language", true);
fetch.addAttribute("timezone", "http://axschema.org/pref/timezone", true);
fetch.addAttribute("image", "http://axschema.org/media/image/default", true);
} else {
fetch.addAttribute("firstname", "http://schema.openid.net/namePerson/first", true);
fetch.addAttribute("lastname", "http://schema.openid.net/namePerson/last", true);
fetch.addAttribute("email", "http://schema.openid.net/contact/email", true);
fetch.addAttribute("country", "http://axschema.org/contact/country/home", true);
fetch.addAttribute("language", "http://axschema.org/pref/language", true);
}
log.debug("adding fetch data");
authReq.addExtension(fetch);
log.debug("redirecting");
response.sendRedirect(authReq.getDestinationUrl(true));
log.debug("reterning build");
return Response.ok().build();
} catch (ConsumerException e) {
log.debug("Error occured : ", e.getMessage(), " ", e.getCause());
OxChooserError error = new OxChooserError();
error.setDescription("An Error occured , request didnt go through.");
return Response.status(400).entity(error).build();
} finally {
identity.logout();
}
}
示例7: addAttributes
import org.openid4java.message.ax.FetchRequest; //导入依赖的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.");
}
}
}
示例8: createAuthenticationRequest
import org.openid4java.message.ax.FetchRequest; //导入依赖的package包/类
/**
* Creates a new Authentication Request.
* @param a_sOpenIdUrl The user's Open ID URL.
* @param a_oRequest The request to use
* @return The ActionForward used to forward a user to their OpenID provider.
* @throws OpenIDException
* @author zschwenk
*/
public String createAuthenticationRequest(String a_sOpenIdUrl, HttpServletRequest a_oRequest)
throws OpenIDException
{
// Custom realm verifier - http://groups.google.com/group/openid4java/browse_thread/thread/ccd874fee1c0720c
//RealmVerifier oRealmVerifier = new RealmVerifier();
//m_oManager.setRealmVerifier(oRealmVerifier);
// configure the return_to URL where your application will receive
// the authentication responses from the OpenID provider
String sReturnURL = UrlHelper.buildUrl(RETURN_ACTION, a_oRequest,null,null,a_oRequest.getScheme(),false,false,true);
// --- Forward proxy setup (only if needed) ---
// ProxyProperties proxyProps = new ProxyProperties();
// proxyProps.setProxyName("proxy.example.com");
// proxyProps.setProxyPort(8080);
// HttpClientFactory.setProxyProperties(proxyProps);
// perform discovery on the user-supplied identifier
List discoveries = m_oManager.discover(a_sOpenIdUrl);
// attempt to associate with the OpenID provider
// and retrieve one service endpoint for authentication
DiscoveryInformation discovered = m_oManager.associate(discoveries);
// store the discovery information in the user's session
a_oRequest.getSession().setAttribute("openid-disc", discovered);
// obtain a AuthRequest message to be sent to the OpenID provider
AuthRequest authReq = m_oManager.authenticate(discovered, sReturnURL);
// Attribute Exchange example: fetching the 'email' attribute
FetchRequest fetch = FetchRequest.createFetchRequest();
fetch.addAttribute("email","http://axschema.org/contact/email",true);
fetch.addAttribute("altemail","http://schema.openid.net/contact/email",true);
fetch.addAttribute("first","http://axschema.org/namePerson/first",true);
fetch.addAttribute("last","http://axschema.org/namePerson/last",true);
fetch.addAttribute("username","http://axschema.org/namePerson/friendly",true);
// attach the extension to the authentication request
authReq.addExtension(fetch);
//
// if (! discovered.isVersion2() )
// {
// // Option 1: GET HTTP-redirect to the OpenID Provider endpoint
// // The only method supported in OpenID 1.x
// // redirect-URL usually limited ~2048 bytes
//
// afOpenId = new ActionForward(authReq.getDestinationUrl(true), true);
// }
// else
// {
// // Option 2: HTML FORM Redirection (Allows payloads >2048 bytes)
//
// afOpenId = new ActionForward(authReq.getDestinationUrl(true), true);
// a_oRequest.getSession().setAttribute("parameterMap", authReq.getParameterMap());
// a_oRequest.getSession().setAttribute("destinationUrl", authReq.getDestinationUrl(true));
// }
return authReq.getDestinationUrl(true);
}
示例9: authRequest
import org.openid4java.message.ax.FetchRequest; //导入依赖的package包/类
public String authRequest(String userSuppliedString,
HttpServletRequest httpReq,
HttpServletResponse httpResp)
throws IOException
{
try
{
// --- Forward proxy setup (only if needed) ---
// ProxyProperties proxyProps = new ProxyProperties();
// proxyProps.setProxyName("proxy.example.com");
// proxyProps.setProxyPort(8080);
// HttpClientFactory.setProxyProperties(proxyProps);
// perform discovery on the user-supplied identifier
List discoveries = manager.discover(userSuppliedString);
// attempt to associate with the OpenID provider
// and retrieve one service endpoint for authentication
DiscoveryInformation discovered = manager.associate(discoveries);
// store the discovery information in the user's session
httpReq.getSession().setAttribute("openid-disc", discovered);
// obtain a AuthRequest message to be sent to the OpenID provider
AuthRequest authReq = manager.authenticate(discovered, returnToUrl);
// Attribute Exchange example: fetching the 'email' attribute
FetchRequest fetch = FetchRequest.createFetchRequest();
fetch.addAttribute("email", // attribute alias
"http://schema.openid.net/contact/email", // type URI
true); // required
// attach the extension to the authentication request
authReq.addExtension(fetch);
// example using Simple Registration to fetching the 'email' attribute
SRegRequest sregReq = SRegRequest.createFetchRequest();
sregReq.addAttribute("email", true);
authReq.addExtension(sregReq);
if (! discovered.isVersion2() )
{
// Option 1: GET HTTP-redirect to the OpenID Provider endpoint
// The only method supported in OpenID 1.x
// redirect-URL usually limited ~2048 bytes
httpResp.sendRedirect(authReq.getDestinationUrl(true));
return null;
}
else
{
// Option 2: HTML FORM Redirection (Allows payloads >2048 bytes)
//RequestDispatcher dispatcher =
// getServletContext().getRequestDispatcher("formredirection.jsp");
//httpReq.setAttribute("prameterMap", response.getParameterMap());
//httpReq.setAttribute("destinationUrl", response.getDestinationUrl(false));
//dispatcher.forward(request, response);
}
}
catch (OpenIDException e)
{
// present error to the user
throw new RuntimeException("wrap:" + e.getMessage(), e);
}
return null;
}
示例10: buildFetchReq
import org.openid4java.message.ax.FetchRequest; //导入依赖的package包/类
private ModelAndView buildFetchReq(String identifier, HttpSession session, String return_to)
throws OpenIDException
{
_logger.info("Building auth + fetch request for: " + identifier);
Map<String,Object> model = new HashMap<String,Object>();
List discoveries;
String errorMsg = "";
try
{
discoveries = _consumerManager.discover(identifier);
}
catch (DiscoveryException e)
{
_logger.error("Error while performing HTML discovery on "
+ identifier, e);
discoveries = null;
errorMsg = "<br /><br /><em>" + e.getMessage() + "</em>";
}
if (discoveries == null || discoveries.size() == 0)
{
_logger.error("Discovery failed on: " + identifier);
model.put("message", "The " + identifier + " identifier could not be resolved." + errorMsg);
return new ModelAndView(_loginView, model);
}
DiscoveryInformation discovered = _consumerManager.associate(discoveries);
// store the discovery information in the session for later use
session.setAttribute("discovered", discovered);
FetchRequest fetch = FetchRequest.createFetchRequest();
for (String typeUri : _attributes.keySet())
{
fetch.addAttribute(_attributes.get(typeUri), typeUri, false);
}
AuthRequest req = _consumerManager.authenticate(discovered, return_to);
req.addExtension(fetch);
model.put("message", req);
_logger.info("Sending fetch request / auto-post view...");
return new ModelAndView(_postView, model);
}
示例11: connectWithOpenId
import org.openid4java.message.ax.FetchRequest; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@RequestMapping("/openid/connect")
public String connectWithOpenId(
@RequestParam(defaultValue="false") boolean login,
@RequestParam("openid_identifier") String openidIdentifier,
@RequestParam(required=false) String timezoneId,
HttpSession session, HttpServletRequest request, Map<String, Object> model) {
try {
List<?> discoveries = manager.discover(openidIdentifier);
// attempt to associate with the OpenID provider
// and retrieve one service endpoint for authentication
DiscoveryInformation discovered = manager.associate(discoveries);
// store the discovery information in the user's session
session.setAttribute(OPENID_DISCOVERY_KEY, discovered);
// obtain a AuthRequest message to be sent to the OpenID provider
AuthRequest authReq = manager.authenticate(discovered, useSsl ? secureReturnUrl : returnUrl);
// Attribute Exchange example: fetching the 'email' attribute
FetchRequest fetch = FetchRequest.createFetchRequest();
fetch.addAttribute(EMAIL, "http://axschema.org/contact/email", true);
fetch.addAttribute(FULLNAME, "http://axschema.org/namePerson", true);
fetch.addAttribute(FIRST_NAME,
"http://axschema.org/namePerson/first", true);
fetch.addAttribute(LAST_NAME,
"http://axschema.org/namePerson/last", true);
fetch.addAttribute(USERNAME,
"http://axschema.org/namePerson/friendly", true);
fetch.addAttribute(DATE_OF_BIRTH, "http://axschema.org/birthDate",
false);
fetch.addAttribute(COUNTRY,
"http://axschema.org/contact/country/home", false);
fetch.addAttribute(LANGUAGE, "http://axschema.org/pref/language",
false);
fetch.addAttribute(TIMEZONE, "http://axschema.org/pref/timezone",
false);
// attach the extension to the authentication request
authReq.addExtension(fetch);
String url = authReq.getDestinationUrl(false);
model.putAll(authReq.getParameterMap());
if (!login) {
session.setAttribute(IS_REGISTRATION_KEY, Boolean.TRUE);
}
session.setAttribute(WebConstants.CURRENT_TIMEZONE_ID, timezoneId);
return "redirect:" + url;
} catch (Exception ex) {
logger.warn("Problem with OpenID initiation", ex);
WebUtils.addError(request, "openIdProblem");
return "login";
}
}
示例12: authRequest
import org.openid4java.message.ax.FetchRequest; //导入依赖的package包/类
private String authRequest(final String userSuppliedString,
final String returnToUrl) throws IOException {
try {
// perform discovery on the user-supplied identifier
List discoveries = manager.discover(userSuppliedString);
// attempt to associate with the OpenID provider
// and retrieve one service endpoint for authentication
discovered = manager.associate(discoveries);
// // store the discovery information in the user's session
// httpReq.getSession().setAttribute("openid-disc", discovered);
// obtain a AuthRequest message to be sent to the OpenID provider
AuthRequest authReq = manager.authenticate(discovered, returnToUrl);
// Attribute Exchange example: fetching the 'email' attribute
FetchRequest fetch = FetchRequest.createFetchRequest();
// Using axschema
fetch.addAttribute("emailax", "http://axschema.org/contact/email",
true);
fetch.addAttribute("firstnameax",
"http://axschema.org/namePerson/first", true);
fetch.addAttribute("lastnameax",
"http://axschema.org/namePerson/last", true);
fetch.addAttribute("fullnameax", "http://axschema.org/namePerson",
true);
fetch.addAttribute("email",
"http://schema.openid.net/contact/email", true);
// Using schema.openid.net (for compatibility)
fetch.addAttribute("firstname",
"http://schema.openid.net/namePerson/first", true);
fetch.addAttribute("lastname",
"http://schema.openid.net/namePerson/last", true);
fetch.addAttribute("fullname",
"http://schema.openid.net/namePerson", true);
// attach the extension to the authentication request
authReq.addExtension(fetch);
return authReq.getDestinationUrl(true);
} catch (OpenIDException e) {
e.printStackTrace();
}
return null;
}
示例13: authRequest
import org.openid4java.message.ax.FetchRequest; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void authRequest(String openidServiceId, String returnToUrl, HttpServletRequest httpReq, HttpServletResponse httpResp) throws IOException, ServletException {
try {
// --- Forward proxy setup (only if needed) ---
// ProxyProperties proxyProps = new ProxyProperties();
// proxyProps.setProxyName("proxy.example.com");
// proxyProps.setProxyPort(8080);
// HttpClientFactory.setProxyProperties(proxyProps);
// perform discovery on the user-supplied identifier
List<?> discoveries = manager.discover(openidServiceId);
// attempt to associate with the OpenID provider
// and retrieve one service endpoint for authentication
DiscoveryInformation discovered = manager.associate(discoveries);
// store the discovery information in the user's session
httpReq.getSession().setAttribute(OpenIdConstants.OPENID_DISC, discovered);
// obtain a AuthRequest message to be sent to the OpenID provider
AuthRequest authReq = manager.authenticate(discovered, returnToUrl);
// Attribute Exchange example: fetching the 'email' attribute
FetchRequest fetch = FetchRequest.createFetchRequest();
fetch.addAttribute("email",
// attribute alias
"http://schema.openid.net/contact/email", // type URI
true); // required
// attach the extension to the authentication request
authReq.addExtension(fetch);
if (!discovered.isVersion2()) {
// Option 1: GET HTTP-redirect to the OpenID Provider endpoint
// The only method supported in OpenID 1.x
// redirect-URL usually limited ~2048 bytes
httpResp.sendRedirect(authReq.getDestinationUrl(true));
} else {
// Option 2: HTML FORM Redirection (Allows payloads >2048 bytes)
sendFormRedirect(httpResp, authReq.getDestinationUrl(false), (Map<String,String>)authReq.getParameterMap());
}
} catch (OpenIDException e) {
e.printStackTrace(System.err);
}
}
示例14: getFetchRequest
import org.openid4java.message.ax.FetchRequest; //导入依赖的package包/类
/**
* Get a fetch request for attributes.
*
* @return a fetch request for attributes
* @throws MessageException an OpenID exception
*/
protected abstract FetchRequest getFetchRequest() throws MessageException;