本文整理汇总了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;
}
}
示例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);
}
}
示例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;
}
示例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();
}
示例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();
}
示例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);
}
示例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
}
}
示例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;
}
示例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;
}
}
示例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;
}
示例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);
}
示例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;
}
示例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));
}
}
}
示例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;
}
}
}
示例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;
}
}