use of net.oauth.OAuthProblemException in project bigbluebutton by bigbluebutton.
the class OAuthServlet method handleException.
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(HttpMessage.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);
}
}
use of net.oauth.OAuthProblemException in project bigbluebutton by bigbluebutton.
the class OAuthSignatureMethod method validate.
/**
* 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;
}
}
use of net.oauth.OAuthProblemException in project bigbluebutton by bigbluebutton.
the class OAuthResponseMessage method toOAuthProblemException.
/**
* Encapsulate this message as an exception. Read and close the body of this
* message.
*/
public OAuthProblemException toOAuthProblemException() throws IOException {
OAuthProblemException problem = new OAuthProblemException();
try {
// decode the response body
getParameters();
} catch (IOException ignored) {
}
problem.getParameters().putAll(getDump());
try {
InputStream b = getBodyAsStream();
if (b != null) {
// release resources
b.close();
}
} catch (IOException ignored) {
}
return problem;
}
use of net.oauth.OAuthProblemException in project zm-mailbox by Zimbra.
the class OAuthAccessTokenServlet method processRequest.
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
try {
String origUrl = request.getHeader("X-Zimbra-Orig-Url");
OAuthMessage oAuthMessage = StringUtil.isNullOrEmpty(origUrl) ? OAuthServlet.getMessage(request, null) : OAuthServlet.getMessage(request, origUrl);
OAuthAccessor accessor = OAuthServiceProvider.getAccessor(oAuthMessage);
OAuthServiceProvider.VALIDATOR.validateAccTokenMessage(oAuthMessage, accessor);
// make sure token is authorized
if (!Boolean.TRUE.equals(accessor.getProperty("authorized"))) {
OAuthProblemException problem = new OAuthProblemException("permission_denied");
LOG.debug("permission_denied");
throw problem;
}
AuthToken userAuthToken = ZimbraAuthToken.getAuthToken((String) accessor.getProperty("ZM_AUTH_TOKEN"));
String accountId = userAuthToken.getAccountId();
Account account = Provisioning.getInstance().getAccountById(accountId);
// generate access token and secret
OAuthServiceProvider.generateAccessToken(accessor);
account.addForeignPrincipal("oAuthAccessToken:" + accessor.accessToken);
account.addOAuthAccessor(accessor.accessToken + "::" + new OAuthAccessorSerializer().serialize(accessor));
response.setContentType("text/plain");
OutputStream out = response.getOutputStream();
OAuth.formEncode(OAuth.newList("oauth_token", accessor.accessToken, "oauth_token_secret", accessor.tokenSecret), out);
out.close();
} catch (Exception e) {
LOG.debug("AccessTokenHandler exception", e);
OAuthServiceProvider.handleException(e, request, response, true);
}
}
use of net.oauth.OAuthProblemException in project zm-mailbox by Zimbra.
the class OAuthRevAValidator method validateCallback.
// Support oauth_callback here for RevA
protected void validateCallback(OAuthMessage message, OAuthAccessor accessor) throws OAuthException, IOException {
String callback = message.getParameter(OAuth.OAUTH_CALLBACK);
if (callback != null && callback != "") {
LOG.debug("callback is ready.");
//if(callback=="oob"){
//oob is not implemented yet
//}else{
accessor.setProperty(OAuth.OAUTH_CALLBACK, callback);
//}
} else {
LOG.debug("no callbacks set!");
OAuthProblemException problem = new OAuthProblemException("no_callback");
throw problem;
}
}
Aggregations