本文整理汇总了Java中org.openid4java.discovery.DiscoveryInformation类的典型用法代码示例。如果您正苦于以下问题:Java DiscoveryInformation类的具体用法?Java DiscoveryInformation怎么用?Java DiscoveryInformation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DiscoveryInformation类属于org.openid4java.discovery包,在下文中一共展示了DiscoveryInformation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: retrieveCredentials
import org.openid4java.discovery.DiscoveryInformation; //导入依赖的package包/类
@Override
protected OpenIdCredentials retrieveCredentials(final WebContext context) throws HttpAction {
final String mode = context.getRequestParameter(OPENID_MODE);
// cancelled authentication
if (CommonHelper.areEquals(mode, CANCEL_MODE)) {
logger.debug("authentication cancelled");
return null;
}
// parameters list returned by the provider
final ParameterList parameterList = new ParameterList(context.getRequestParameters());
// retrieve the previously stored discovery information
final DiscoveryInformation discoveryInformation = (DiscoveryInformation) context
.getSessionAttribute(getDiscoveryInformationSessionAttributeName());
// create credentials
final OpenIdCredentials credentials = new OpenIdCredentials(discoveryInformation, parameterList, getName());
logger.debug("credentials: {}", credentials);
return credentials;
}
示例2: verifyNonce
import org.openid4java.discovery.DiscoveryInformation; //导入依赖的package包/类
/**
* Verifies the nonce in an authentication response.
*
* @param authResp The authentication response containing the nonce
* to be verified.
* @param discovered The discovery information associated with the
* authentication transaction.
* @return True if the nonce is valid, false otherwise.
*/
public boolean verifyNonce(AuthSuccess authResp,
DiscoveryInformation discovered)
{
String nonce = authResp.getNonce();
if (nonce == null) // compatibility mode
nonce = extractConsumerNonce(authResp.getReturnTo(),
discovered.getOPEndpoint().toString());
if (nonce == null) return false;
// using the same nonce verifier for both server and consumer nonces
return (NonceVerifier.OK == _nonceVerifier.seen(
discovered.getOPEndpoint().toString(), nonce));
}
示例3: verifyDiscovered
import org.openid4java.discovery.DiscoveryInformation; //导入依赖的package包/类
/**
* Verifies the dicovery information matches the data received in a
* authentication response from an OpenID Provider.
*
* @param authResp The authentication response to be verified.
* @param discovered The discovery information obtained earlier during
* the discovery stage, associated with the
* identifier(s) in the request. Stateless operation
* is assumed if null.
* @return The discovery information associated with the
* claimed identifier, that can be used further in
* the verification process. Null if the discovery
* on the claimed identifier does not match the data
* in the assertion.
*/
private DiscoveryInformation verifyDiscovered(AuthSuccess authResp,
DiscoveryInformation discovered)
throws DiscoveryException
{
if (authResp == null || authResp.getIdentity() == null)
{
_log.info("Assertion is not about an identifier");
return null;
}
if (authResp.isVersion2())
return verifyDiscovered2(authResp, discovered);
else
return verifyDiscovered1(authResp, discovered);
}
示例4: login
import org.openid4java.discovery.DiscoveryInformation; //导入依赖的package包/类
@Override
public String login() throws LogicException {
try {
// perform discovery on the user-supplied identifier
List<?> discoveries = consumerManager.discover("http://steamcommunity.com/openid");
// attempt to associate with the OpenID provider
// and retrieve one service endpoint for authentication
DiscoveryInformation discovered = consumerManager.associate(discoveries);
// store the discovery information in the user's session for later use
// leave out for stateless operation / if there is no session
getSession().setAttribute("discovered", discovered);
// obtain a AuthRequest message to be sent to the OpenID provider
AuthRequest authReq = consumerManager.authenticate(discovered, getServletContext().getInitParameter("callback.url"));
String result = authReq.getDestinationUrl(true);
return result;
} catch (MessageException | ConsumerException | DiscoveryException e) {
e.printStackTrace();
return null;
}
}
示例5: authorizationRequest
import org.openid4java.discovery.DiscoveryInformation; //导入依赖的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;
}
示例6: processOpenIdAnswer
import org.openid4java.discovery.DiscoveryInformation; //导入依赖的package包/类
@RequestMapping(value = "/", method = POST)
public void processOpenIdAnswer(HttpServletRequest request, HttpServletResponse response)
throws Exception {
String handle = request.getParameter(HANDLE_PARAM);
boolean isImmediateRequest = request.getParameterMap().containsKey(IMMEDIATE_PARAM);
String returnUrl = request.getRequestURL().toString() + ANSWER_PAGE;
// perform discovery on the user-supplied identifier
List discoveries = manager.discover(handle);
// 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
request.getSession().setAttribute(DISCOVERY_SESSION_KEY, discovered);
// obtain a AuthRequest message to be sent to the OpenID provider
AuthRequest authReq = manager.authenticate(discovered, returnUrl);
authReq.setImmediate(isImmediateRequest);
// since our service uses OpenId Version two this should to it
response.sendRedirect(authReq.getDestinationUrl(true));
}
示例7: retrieveRedirectAction
import org.openid4java.discovery.DiscoveryInformation; //导入依赖的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);
}
}
示例8: retrieveUserProfile
import org.openid4java.discovery.DiscoveryInformation; //导入依赖的package包/类
@Override
protected U retrieveUserProfile(final OpenIdCredentials credentials, final WebContext context) throws HttpAction {
final ParameterList parameterList = credentials.getParameterList();
final DiscoveryInformation discoveryInformation = credentials.getDiscoveryInformation();
logger.debug("parameterList: {}", parameterList);
logger.debug("discoveryInformation: {}", discoveryInformation);
try {
// verify the response
final VerificationResult verification = this.consumerManager.verify(computeFinalCallbackUrl(context), parameterList,
discoveryInformation);
// examine the verification result and extract the verified identifier
final Identifier verified = verification.getVerifiedId();
if (verified != null) {
final AuthSuccess authSuccess = (AuthSuccess) verification.getAuthResponse();
logger.debug("authSuccess: {}", authSuccess);
final U profile = createProfile(authSuccess);
profile.setId(verified.getIdentifier());
logger.debug("profile: {}", profile);
return profile;
}
} catch (final OpenIDException e) {
throw new TechnicalException("OpenID exception", e);
}
final String message = "No verifiedId found";
throw new TechnicalException(message);
}
示例9: OpenIdCredentials
import org.openid4java.discovery.DiscoveryInformation; //导入依赖的package包/类
public OpenIdCredentials(final DiscoveryInformation discoveryInformation, final ParameterList parameterList,
final String clientName) {
this.discoveryInformation = discoveryInformation;
this.parameterList = parameterList;
setClientName(clientName);
}
示例10: getDiscoveredInformation
import org.openid4java.discovery.DiscoveryInformation; //导入依赖的package包/类
public List getDiscoveredInformation(Set targetTypes) throws DiscoveryException
{
List result = new ArrayList();
if (hasEndpoints())
{
XrdsServiceEndpoint endpoint;
Iterator endpointsIter = _endpoints.iterator();
while (endpointsIter.hasNext()) {
endpoint = (XrdsServiceEndpoint) endpointsIter.next();
Iterator typesIter = endpoint.getTypes().iterator();
while (typesIter.hasNext()) {
String type = (String) typesIter.next();
if (!targetTypes.contains(type)) continue;
try {
result.add(new DiscoveryInformation(
new URL(endpoint.getUri()),
DiscoveryInformation.OPENID_SIGNON_TYPES.contains(type) ?
new UrlIdentifier(_normalizedUrl) : null,
DiscoveryInformation.OPENID2.equals(type) ? endpoint.getLocalId() :
DiscoveryInformation.OPENID1_SIGNON_TYPES.contains(type) ? endpoint.getDelegate() : null,
type,
endpoint.getTypes()));
} catch (MalformedURLException e) {
throw new YadisException("Invalid endpoint URL discovered: " + endpoint.getUri(), OpenIDException.YADIS_INVALID_URL);
}
}
}
}
return result;
}
示例11: testPerferredAssociation
import org.openid4java.discovery.DiscoveryInformation; //导入依赖的package包/类
public void testPerferredAssociation() throws Exception {
manager.setPrefAssocSessEnc(AssociationSessionType.DH_SHA1);
DiscoveryInformation disc = new DiscoveryInformation(new URL(server.createAbsoluteUrl("/op/endpoint")), null);
DiscoveryInformation info = manager.associate(Collections.singletonList(disc));
assertEquals(1,server.getRequestParams().size());
Map request = (Map)server.getRequestParams().get(0);
assertEquals(manager.getPrefAssocSessEnc().getAssociationType(),((String[])request.get("openid.assoc_type"))[0]);
assertEquals(manager.getPrefAssocSessEnc().getSessionType(),((String[])request.get("openid.session_type"))[0]);
}
示例12: testXrdsOpenidDelegate
import org.openid4java.discovery.DiscoveryInformation; //导入依赖的package包/类
public void testXrdsOpenidDelegate() throws Exception
{
List result;
try
{
result = _resolver.discover("http://localhost:" + _servletPort + "/?headers=simplexrds&xrds=xrdsdelegate");
assertEquals("Should have discovered one endpoint: ", result.size(), 1);
DiscoveryInformation info = (DiscoveryInformation) result.get(0);
assertNotNull("Should have discovered an openid:Delegate.", info.getDelegateIdentifier());
}
catch (DiscoveryException e)
{
fail("Discovery failed on xrdsdelegate: " + e.getMessage());
}
}
示例13: init
import org.openid4java.discovery.DiscoveryInformation; //导入依赖的package包/类
private State init(
HttpServletRequest req,
final String openidIdentifier,
final SignInMode mode,
final boolean remember,
final String returnToken) {
final List<?> list;
try {
list = manager.discover(openidIdentifier);
} catch (DiscoveryException e) {
log.error("Cannot discover OpenID " + openidIdentifier, e);
return null;
}
if (list == null || list.isEmpty()) {
return null;
}
final String contextUrl = urlProvider.get(req);
final DiscoveryInformation discovered = manager.associate(list);
final UrlEncoded retTo = new UrlEncoded(contextUrl + RETURN_URL);
retTo.put(P_MODE, mode.name());
if (returnToken != null && returnToken.length() > 0) {
retTo.put(P_TOKEN, returnToken);
}
if (remember) {
retTo.put(P_REMEMBER, "1");
}
if (discovered.hasClaimedIdentifier()) {
retTo.put(P_CLAIMED, discovered.getClaimedIdentifier().getIdentifier());
}
return new State(discovered, retTo, contextUrl);
}
示例14: prepareAuthenticationUrl
import org.openid4java.discovery.DiscoveryInformation; //导入依赖的package包/类
/**
* Prepares open ID authentication URL.
*
* @param openIdIdentifier the open ID identifier to authenticate
* @param siteUrl the site URL
* @param returnViewName the return view name
* @return the authentication URL
* @throws DiscoveryException if discovery exception occurs.
* @throws MessageException if message exception occurs.
* @throws ConsumerException if consume exception occurs.
*/
public static String prepareAuthenticationUrl(final String openIdIdentifier, final String siteUrl
, final String returnViewName)
throws DiscoveryException, MessageException, ConsumerException {
if (UI.getCurrent().getSession().getAttribute(ConsumerManager.class) == null) {
UI.getCurrent().getSession().setAttribute(ConsumerManager.class, new ConsumerManager());
}
final ConsumerManager manager = UI.getCurrent().getSession().getAttribute(ConsumerManager.class);
final String returnURL = siteUrl + returnViewName;
final List discoveries = manager.discover(openIdIdentifier);
final DiscoveryInformation discovered = manager.associate(discoveries);
UI.getCurrent().getSession().setAttribute(DiscoveryInformation.class, discovered);
final AuthRequest authReq = manager.authenticate(discovered, returnURL);
return authReq.getDestinationUrl(true);
}
示例15: getVerificationResult
import org.openid4java.discovery.DiscoveryInformation; //导入依赖的package包/类
/**
* Gets verification result based on session and request parameters. This should be called when
* processing the OpenId return request.
* @param siteUrl the site URL
* @param returnViewName the return view name
*
* @return the verification result
* @throws DiscoveryException if discovery exception occurs.
* @throws MessageException if message exception occurs.
* @throws AssociationException if association exception occurs.
*/
public static VerificationResult getVerificationResult(final String siteUrl
, final String returnViewName) throws MessageException, DiscoveryException,
AssociationException {
final ConsumerManager consumerManager = UI.getCurrent().getSession().getAttribute(ConsumerManager.class);
final DiscoveryInformation discovered = UI.getCurrent().getSession().getAttribute(
DiscoveryInformation.class);
UI.getCurrent().getSession().setAttribute(ConsumerManager.class, null);
UI.getCurrent().getSession().setAttribute(DiscoveryInformation.class, null);
final HttpServletRequest request = ((VaadinServletRequest) VaadinService.getCurrentRequest())
.getHttpServletRequest();
final StringBuffer urlBuilder = new StringBuffer(siteUrl + returnViewName);
final String queryString = request.getQueryString();
if (queryString != null) {
urlBuilder.append('?');
urlBuilder.append(queryString);
}
final String requestUrl = urlBuilder.toString();
final ParameterList openidResp = new ParameterList(request.getParameterMap());
// verify the response
return consumerManager.verify(requestUrl,
openidResp, discovered);
}