当前位置: 首页>>代码示例>>Java>>正文


Java OAuthProblemException类代码示例

本文整理汇总了Java中net.oauth.OAuthProblemException的典型用法代码示例。如果您正苦于以下问题:Java OAuthProblemException类的具体用法?Java OAuthProblemException怎么用?Java OAuthProblemException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


OAuthProblemException类属于net.oauth包,在下文中一共展示了OAuthProblemException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: validate

import net.oauth.OAuthProblemException; //导入依赖的package包/类
/**
 * Check whether the message has a valid signature.
 * @throws URISyntaxException 
 *
 * @throws OAuthProblemException
 *             the signature is invalid
 */
public void validate(OAuthMessage message)
throws IOException, OAuthException, URISyntaxException {
    message.requireParameters("oauth_signature");
    String signature = message.getSignature();
    String baseString = getBaseString(message);
    if (!isValid(signature, baseString)) {

 // *LAMS* added by LAMS
 log.debug("Error. Signature invalid. oauth_signature=" + signature + ", oauth_signature_base_string="
  + baseString + ", oauth_signature_method=" + message.getSignatureMethod());
     		
        OAuthProblemException problem = new OAuthProblemException(
                "signature_invalid");
        problem.setParameter("oauth_signature", signature);
        problem.setParameter("oauth_signature_base_string", baseString);
        problem.setParameter("oauth_signature_method", message
                .getSignatureMethod());
        throw problem;
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:OAuthSignatureMethod.java

示例2: handleException

import net.oauth.OAuthProblemException; //导入依赖的package包/类
public static void handleException(HttpServletResponse response,
        Exception e, String realm, boolean sendBody) throws IOException,
        ServletException {
    if (e instanceof OAuthProblemException) {
        OAuthProblemException problem = (OAuthProblemException) e;
        Object httpCode = problem.getParameters().get(OAuthProblemException.HTTP_STATUS_CODE);
        if (httpCode == null) {
            httpCode = PROBLEM_TO_HTTP_CODE.get(problem.getProblem());
        }
        if (httpCode == null) {
            httpCode = SC_FORBIDDEN;
        }
        response.reset();
        response.setStatus(Integer.parseInt(httpCode.toString()));
        OAuthMessage message = new OAuthMessage(null, null, problem
                .getParameters().entrySet());
        response.addHeader("WWW-Authenticate", message
                .getAuthorizationHeader(realm));
        if (sendBody) {
            sendForm(response, message.getParameters());
        }
    } else if (e instanceof IOException) {
        throw (IOException) e;
    } else if (e instanceof ServletException) {
        throw (ServletException) e;
    } else if (e instanceof RuntimeException) {
        throw (RuntimeException) e;
    } else {
        throw new ServletException(e);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:32,代码来源:OAuthServlet.java

示例3: validateCallbackURL

import net.oauth.OAuthProblemException; //导入依赖的package包/类
protected void validateCallbackURL(Client client,
                                   String oauthCallback) throws OAuthProblemException {
    // the callback must not be empty or null, and it should either match
    // the pre-registered callback URI or have the common root with the
    // the pre-registered application URI
    if (!StringUtils.isEmpty(oauthCallback) 
        && (!StringUtils.isEmpty(client.getCallbackURI())
            && oauthCallback.equals(client.getCallbackURI())
            || !StringUtils.isEmpty(client.getApplicationURI())
            && oauthCallback.startsWith(client.getApplicationURI()))) {
        return;
    }
    OAuthProblemException problemEx = new OAuthProblemException(
        OAuth.Problems.PARAMETER_REJECTED + " - " + OAuth.OAUTH_CALLBACK);
    problemEx
        .setParameter(OAuthProblemException.HTTP_STATUS_CODE,
            HttpServletResponse.SC_BAD_REQUEST);
    throw problemEx;
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:20,代码来源:OscarRequestTokenHandler.java

示例4: authorizeRequestToken

import net.oauth.OAuthProblemException; //导入依赖的package包/类
/**
 * Authorizes a request token to be exchanged for an access token.
 *
 * @param requestToken the request token used for identification.
 * @param user the user that has authorized the token.
 * @throws OAuthProblemException if the request token does not map to an
 *         accessor or if the token was already used.
 */
public OAuthAccessor authorizeRequestToken(String requestToken, ParticipantId user)
    throws OAuthProblemException {
  Preconditions.checkNotNull(user, "User must not be null");

  OAuthAccessor accessor = getRequestTokenAccessor(requestToken);

  if (accessor.getProperty(USER_PROPERTY_NAME) != null) {
    throw OAuthUtil.newOAuthProblemException(OAuth.Problems.TOKEN_USED);
  }

  accessor.setProperty(USER_PROPERTY_NAME, user);
  requestTokenAccessors.put(requestToken, accessor);

  LOG.info("Authorized request token for " + user);
  return accessor.clone();
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:25,代码来源:DataApiTokenContainer.java

示例5: generateAccessToken

import net.oauth.OAuthProblemException; //导入依赖的package包/类
/**
 * Authorize the {@link OAuthAccessor} by generating a new access token and
 * token secret.
 *
 * @param requestToken the requestToken used for identifying the accessor that
 *        needs to be authorized.
 * @return a new {@link OAuthAccessor} with the access token and token secret
 *         set.
 * @throws OAuthProblemException if the request token in the accessor is not
 *         known.
 */
public OAuthAccessor generateAccessToken(String requestToken) throws OAuthProblemException {
  OAuthAccessor accessor = getRequestTokenAccessor(requestToken);

  if (accessor.getProperty(USER_PROPERTY_NAME) == null) {
    // User has not given the consumer permission yet.
    throw OAuthUtil.newOAuthProblemException(OAuth.Problems.PERMISSION_UNKNOWN);
  }

  // Token secret does not need to unique so can be generated now.
  accessor.tokenSecret = generateToken();

  do {
    accessor.accessToken = generateToken();
  } while (accessTokenAccessors.putIfAbsent(accessor.accessToken, accessor) != null);
  requestTokenAccessors.remove(accessor.requestToken);

  LOG.info("Generated access token for " + accessor.getProperty(USER_PROPERTY_NAME));
  return accessor.clone();
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:31,代码来源:DataApiTokenContainer.java

示例6: validateAndAuthorize

import net.oauth.OAuthProblemException; //导入依赖的package包/类
private ParticipantId validateAndAuthorize(HttpServletRequest req, HttpServletResponse resp) throws IOException {
  OAuthMessage message = new HttpRequestMessage(req, req.getRequestURL().toString());

  OAuthAccessor accessor;
  try {
    message.requireParameters(OAuth.OAUTH_TOKEN);
    accessor = tokenContainer.getAccessTokenAccessor(message.getParameter(OAuth.OAUTH_TOKEN));
  } catch (OAuthProblemException e) {
    LOG.info("No valid OAuth token present", e);
    // Have to set status here manually, cannot use e.getHttpStatusCode
    // because message.requireParameters doesn't set it in the exception.
    resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, e.getMessage());
    return null;
  }
  if (!validateMessage(req, accessor)) {
    resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    return null;
  }
  return (ParticipantId) accessor.getProperty(DataApiTokenContainer.USER_PROPERTY_NAME);
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:21,代码来源:DataApiServlet.java

示例7: testDoAuthorizeTokenPostRejectsToken

import net.oauth.OAuthProblemException; //导入依赖的package包/类
public void testDoAuthorizeTokenPostRejectsToken() throws Exception {
  when(req.getPathInfo()).thenReturn(AUTHORIZE_TOKEN_PATH);
  when(req.getMethod()).thenReturn("POST");
  when(req.getParameter("cancel")).thenReturn("yes");
  Map<String, String[]> params = getDoAuthorizeTokenParams();
  when(req.getParameterMap()).thenReturn(params);
  String token = servlet.getOrGenerateXsrfToken(ALEX);
  when(req.getParameter("token")).thenReturn(token);

  when(sessionManager.getLoggedInUser(any(HttpSession.class))).thenReturn(ALEX);

  servlet.doPost(req, resp);

  verify(resp).setStatus(HttpServletResponse.SC_OK);
  try {
    tokenContainer.getRequestTokenAccessor(params.get(OAuth.OAUTH_TOKEN)[0]);
    fail("This token should not be present anymore");
  } catch (OAuthProblemException e) {
    // expected
  }
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:22,代码来源:DataApiOAuthServletTest.java

示例8: convertToOAuthAccessor

import net.oauth.OAuthProblemException; //导入依赖的package包/类
public static OAuthAccessor convertToOAuthAccessor(Accessor accessor, OAuthConsumer oAuthConsumer)
        throws OAuthProblemException {
    if (accessor == null)
        return null;
    if (!oAuthConsumer.consumerKey.equals(accessor.getConsumerId()))
        throw new OAuthProblemException(OAuth.Problems.CONSUMER_KEY_REFUSED);
    OAuthAccessor oAuthAccessor = new OAuthAccessor(oAuthConsumer);
    if (accessor.getType() == Accessor.Type.ACCESS)
        oAuthAccessor.accessToken = accessor.getToken();
    else
        oAuthAccessor.requestToken = accessor.getToken();
    oAuthAccessor.tokenSecret = accessor.getSecret();
    // Support Variable Accessor Secret http://wiki.oauth.net/w/page/12238502/AccessorSecret
    if (accessor.getAccessorSecret() != null)
        oAuthConsumer.setProperty(OAuthConsumer.ACCESSOR_SECRET, accessor.getAccessorSecret());
    return oAuthAccessor;
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:18,代码来源:Util.java

示例9: validate

import net.oauth.OAuthProblemException; //导入依赖的package包/类
/**
 * Check whether the message has a valid signature.
 * @throws URISyntaxException 
 *
 * @throws OAuthProblemException
 *             the signature is invalid
 */
public void validate(OAuthMessage message)
throws IOException, OAuthException, URISyntaxException {
    message.requireParameters("oauth_signature");
    String signature = message.getSignature();
    String baseString = getBaseString(message);
    if (!isValid(signature, baseString)) {
        OAuthProblemException problem = new OAuthProblemException(
                "signature_invalid");
        problem.setParameter("oauth_signature", signature);
        problem.setParameter("oauth_signature_base_string", baseString);
        problem.setParameter("oauth_signature_method", message
                .getSignatureMethod());
        throw problem;
    }
}
 
开发者ID:lshain-android-source,项目名称:external-oauth,代码行数:23,代码来源:OAuthSignatureMethod.java

示例10: getConsumer

import net.oauth.OAuthProblemException; //导入依赖的package包/类
public static synchronized OAuthConsumer getConsumer(
        OAuthMessage requestMessage)
        throws IOException, OAuthProblemException {
    
    OAuthConsumer consumer = null;
    // try to load from local cache if not throw exception
    String consumer_key = requestMessage.getConsumerKey();
    
    consumer = SampleOAuthProvider.ALL_CONSUMERS.get(consumer_key);
    
    if(consumer == null) {
        OAuthProblemException problem = new OAuthProblemException("token_rejected");
        throw problem;
    }
    
    return consumer;
}
 
开发者ID:lanen,项目名称:mint4j,代码行数:18,代码来源:SampleOAuthProvider.java

示例11: doPost

import net.oauth.OAuthProblemException; //导入依赖的package包/类
/**
 * Entry point for the Data API Calls.
 */
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
  OAuthMessage message = new HttpRequestMessage(req, req.getRequestURL().toString());

  OAuthAccessor accessor;
  try {
    message.requireParameters(OAuth.OAUTH_TOKEN);
    accessor = tokenContainer.getAccessTokenAccessor(message.getParameter(OAuth.OAUTH_TOKEN));
  } catch (OAuthProblemException e) {
    LOG.info("No valid OAuth token present", e);
    // Have to set status here manually, cannot use e.getHttpStatusCode
    // because message.requireParameters doesn't set it in the exception.
    resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, e.getMessage());
    return;
  }
  ParticipantId participant =
      (ParticipantId) accessor.getProperty(DataApiTokenContainer.USER_PROPERTY_NAME);
  
  processOpsRequest(req, resp, message, accessor, participant);
}
 
开发者ID:apache,项目名称:incubator-wave,代码行数:24,代码来源:DataApiServlet.java

示例12: invoke

import net.oauth.OAuthProblemException; //导入依赖的package包/类
/**
 * Send a request message to the service provider and get the response.
 * 
 * @return the response
 * @throws IOException
 *             failed to communicate with the service provider
 * @throws OAuthProblemException
 *             the HTTP response status code was not 200 (OK)
 */
public OAuthMessage invoke(OAuthMessage request, ParameterStyle style)
		throws IOException, OAuthException {
	OAuthResponseMessage response = access(request, style);
	if ((response.getHttpResponse().getStatusCode() / 100) != 2) {
		OAuthProblemException problem = response.toOAuthProblemException();
		try {
			problem.setParameter(
					OAuthProblemException.SIGNATURE_BASE_STRING,
					OAuthSignatureMethod.getBaseString(request));
		} catch (Exception ignored) {
		}
		throw problem;
	}
	return response;
}
 
开发者ID:Simbacode,项目名称:mobipayments,代码行数:25,代码来源:OAuthClient.java

示例13: testRedirect

import net.oauth.OAuthProblemException; //导入依赖的package包/类
public void testRedirect() throws Exception {
    final OAuthMessage request = new OAuthMessage("GET",
            "http://google.com/search", OAuth.newList("q", "Java"));
    final Integer expectedStatus = Integer.valueOf(301);
    final String expectedLocation = "http://www.google.com/search?q=Java";
    for (OAuthClient client : clients) {
        try {
            OAuthMessage response = client.invoke(request, ParameterStyle.BODY);
            fail(client.getHttpClient() + " response: " + response);
        } catch (OAuthProblemException e) {
            Map<String, Object> parameters = e.getParameters();
            assertEquals("status", expectedStatus, parameters.get(HttpMessage.STATUS_CODE));
            assertEquals("Location", expectedLocation, parameters.get(HttpResponseMessage.LOCATION));
        }
    }
}
 
开发者ID:groovenauts,项目名称:jmeter_oauth_plugin,代码行数:17,代码来源:OAuthClientTest.java

示例14: validateVersion

import net.oauth.OAuthProblemException; //导入依赖的package包/类
private void validateVersion(OAuthMessage message) throws net.oauth.OAuthException, IOException
{
	// Checks OAuth is version 1
	String versionString = message.getParameter(OAuth.OAUTH_VERSION);
	if( versionString != null )
	{
		double version = Double.parseDouble(versionString);
		if( version < 1.0 || 1.0 < version )
		{
			OAuthProblemException problem = new OAuthProblemException(OAuth.Problems.VERSION_REJECTED);
			problem.setParameter(OAuth.Problems.OAUTH_ACCEPTABLE_VERSIONS, 1.0 + "-" + 1.0);
			throw problem;
		}
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:16,代码来源:OAuthWebServiceImpl.java

示例15: validateTimestamp

import net.oauth.OAuthProblemException; //导入依赖的package包/类
/**
 * Throw an exception if the timestamp [sec] is out of range.
 */
private void validateTimestamp(long timestamp, long currentTimeMsec) throws OAuthProblemException
{
	long min = (currentTimeMsec - DEFAULT_MAX_TIMESTAMP_AGE + 500) / 1000L;
	long max = (currentTimeMsec + DEFAULT_MAX_TIMESTAMP_AGE + 500) / 1000L;
	if( timestamp < min || max < timestamp )
	{
		OAuthProblemException problem = new OAuthProblemException(OAuth.Problems.TIMESTAMP_REFUSED);
		problem.setParameter(OAuth.Problems.OAUTH_ACCEPTABLE_TIMESTAMPS, min + "-" + max);
		throw problem;
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:15,代码来源:OAuthWebServiceImpl.java


注:本文中的net.oauth.OAuthProblemException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。