Search in sources :

Example 1 with OAuthProblemException

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);
    }
}
Also used : OAuthProblemException(net.oauth.OAuthProblemException) ServletException(javax.servlet.ServletException) OAuthMessage(net.oauth.OAuthMessage) IOException(java.io.IOException)

Example 2 with OAuthProblemException

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;
    }
}
Also used : OAuthProblemException(net.oauth.OAuthProblemException)

Example 3 with OAuthProblemException

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;
}
Also used : OAuthProblemException(net.oauth.OAuthProblemException) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 4 with OAuthProblemException

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);
    }
}
Also used : OAuthAccessor(net.oauth.OAuthAccessor) OAuthProblemException(net.oauth.OAuthProblemException) Account(com.zimbra.cs.account.Account) OAuthMessage(net.oauth.OAuthMessage) OutputStream(java.io.OutputStream) ZimbraAuthToken(com.zimbra.cs.account.ZimbraAuthToken) AuthToken(com.zimbra.cs.account.AuthToken) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) OAuthProblemException(net.oauth.OAuthProblemException)

Example 5 with OAuthProblemException

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;
    }
}
Also used : OAuthProblemException(net.oauth.OAuthProblemException)

Aggregations

OAuthProblemException (net.oauth.OAuthProblemException)13 IOException (java.io.IOException)4 OAuthAccessor (net.oauth.OAuthAccessor)3 OAuthMessage (net.oauth.OAuthMessage)3 ServiceException (com.zimbra.common.service.ServiceException)2 Account (com.zimbra.cs.account.Account)2 ServletException (javax.servlet.ServletException)2 AuthToken (com.zimbra.cs.account.AuthToken)1 AuthTokenException (com.zimbra.cs.account.AuthTokenException)1 ZimbraAuthToken (com.zimbra.cs.account.ZimbraAuthToken)1 OAuthAccessorSerializer (com.zimbra.cs.account.oauth.OAuthAccessorSerializer)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 OAuth (net.oauth.OAuth)1 OAuthConsumer (net.oauth.OAuthConsumer)1 OAuthException (net.oauth.OAuthException)1