本文整理汇总了Java中org.openid4java.message.sreg.SRegRequest.createFetchRequest方法的典型用法代码示例。如果您正苦于以下问题:Java SRegRequest.createFetchRequest方法的具体用法?Java SRegRequest.createFetchRequest怎么用?Java SRegRequest.createFetchRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openid4java.message.sreg.SRegRequest
的用法示例。
在下文中一共展示了SRegRequest.createFetchRequest方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addSimpleRegistrationToAuthRequest
import org.openid4java.message.sreg.SRegRequest; //导入方法依赖的package包/类
/**
* Simple Registration Extension example.
*
* @param httpReq
* @param authReq
* @throws MessageException
* @see <a href="http://code.google.com/p/openid4java/wiki/SRegHowTo">Simple Registration HowTo</a>
* @see <a href="http://openid.net/specs/openid-simple-registration-extension-1_0.html">OpenID Simple Registration Extension 1.0</a>
*/
private void addSimpleRegistrationToAuthRequest(HttpServletRequest httpReq,
AuthRequest authReq) throws MessageException {
// Attribute Exchange example: fetching the 'email' attribute
// FetchRequest fetch = FetchRequest.createFetchRequest();
SRegRequest sregReq = SRegRequest.createFetchRequest();
String[] attributes = { "nickname", "email", "fullname", "dob",
"gender", "postcode", "country", "language", "timezone" };
for (int i = 0, l = attributes.length; i < l; i++) {
String attribute = attributes[i];
String value = httpReq.getParameter(attribute);
if (OPTIONAL_VALUE.equals(value)) {
sregReq.addAttribute(attribute, false);
} else if (REQUIRED_VALUE.equals(value)) {
sregReq.addAttribute(attribute, true);
}
}
// attach the extension to the authentication request
if (!sregReq.getAttributes().isEmpty()) {
authReq.addExtension(sregReq);
}
}
示例2: authorizationRequest
import org.openid4java.message.sreg.SRegRequest; //导入方法依赖的package包/类
/**
* Send authorization request to OpenID server
* @param userSuppliedString - OpenID username/login
* @param req - current request object
* @param res - current response object
* @return - true if sent, false if error
* @throws IOException - other problem
*/
public boolean authorizationRequest(String userSuppliedString, HttpServletRequest req, HttpServletResponse res) throws IOException {
try {
List discoveries = manager.discover(userSuppliedString);
DiscoveryInformation discovered = manager.associate(discoveries);
req.getSession().setAttribute("openid-disc", discovered);
AuthRequest authReq = manager.authenticate(discovered, returnToUrl);
SRegRequest sregReq = SRegRequest.createFetchRequest();
sregReq.addAttribute("email", true);
sregReq.addAttribute("fullname", true);
authReq.addExtension(sregReq);
res.sendRedirect(authReq.getDestinationUrl(true));
return true;
} catch (OpenIDException ex) {
// logger.error("Exception in authRequest with '" + userSuppliedString + "'", ex);
}
return false;
}
示例3: authRequest
import org.openid4java.message.sreg.SRegRequest; //导入方法依赖的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;
}