Search in sources :

Example 6 with OAuthAccessor

use of net.oauth.OAuthAccessor in project bigbluebutton by bigbluebutton.

the class IMSPOXRequest method validateRequest.

// Assumes data is all loaded
public void validateRequest(String oauth_consumer_key, String oauth_secret, HttpServletRequest request) {
    valid = false;
    OAuthMessage oam = OAuthServlet.getMessage(request, null);
    OAuthValidator oav = new SimpleOAuthValidator();
    OAuthConsumer cons = new OAuthConsumer("about:blank#OAuth+CallBack+NotUsed", oauth_consumer_key, oauth_secret, null);
    OAuthAccessor acc = new OAuthAccessor(cons);
    try {
        base_string = OAuthSignatureMethod.getBaseString(oam);
    } catch (Exception e) {
        base_string = null;
    }
    try {
        oav.validateMessage(oam, acc);
    } catch (Exception e) {
        errorMessage = "Launch fails OAuth validation: " + e.getMessage();
        return;
    }
    valid = true;
}
Also used : SimpleOAuthValidator(net.oauth.SimpleOAuthValidator) OAuthAccessor(net.oauth.OAuthAccessor) SimpleOAuthValidator(net.oauth.SimpleOAuthValidator) OAuthValidator(net.oauth.OAuthValidator) OAuthMessage(net.oauth.OAuthMessage) OAuthConsumer(net.oauth.OAuthConsumer) IllegalArgumentException(java.lang.IllegalArgumentException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 7 with OAuthAccessor

use of net.oauth.OAuthAccessor in project zm-mailbox by Zimbra.

the class OAuthServiceProvider method getAccessor.

/**
     * Get the access token and token secret for the given oauth_token.
     */
public static synchronized OAuthAccessor getAccessor(OAuthMessage requestMessage) throws IOException, OAuthProblemException, ServiceException {
    // try to load from memcache if not throw exception
    String consumer_token = requestMessage.getToken();
    OAuthAccessor accessor = null;
    accessor = OAuthTokenCache.get(consumer_token, OAuthTokenCache.REQUEST_TOKEN_TYPE);
    if (accessor == null) {
        accessor = OAuthTokenCache.get(consumer_token, OAuthTokenCache.ACCESS_TOKEN_TYPE);
    }
    if (accessor == null) {
        OAuthProblemException problem = new OAuthProblemException("token_expired");
        throw problem;
    }
    return accessor;
}
Also used : OAuthAccessor(net.oauth.OAuthAccessor) OAuthProblemException(net.oauth.OAuthProblemException)

Example 8 with OAuthAccessor

use of net.oauth.OAuthAccessor in project zm-mailbox by Zimbra.

the class OAuthAuthorizationServlet method doPost.

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    LOG.debug("Authorization Handler doPost requested!");
    try {
        OAuthMessage requestMessage = OAuthServlet.getMessage(request, null);
        OAuthAccessor accessor = OAuthServiceProvider.getAccessor(requestMessage);
        //status can be yes/no(accept/declined)
        String status = (String) request.getAttribute("STATUS");
        if (null != status && status.equals("no")) {
            LOG.debug("Access to zimbra message is denied.");
            OAuthTokenCache.remove(accessor.requestToken, OAuthTokenCache.REQUEST_TOKEN_TYPE);
            sendUnauthorizedResponse(response, accessor);
            return;
        }
        String username = request.getParameter("username");
        String zmtoken = (String) request.getAttribute("ZM_AUTH_TOKEN");
        LOG.debug("[AuthorizationHandlerInput] username = %s, oauth_token = %s, ZM_AUTH_TOKEN = %s", username, request.getParameter("oauth_token"), zmtoken);
        if (zmtoken == null) {
            sendToAuthorizePage(request, response, accessor);
        } else {
            OAuthServiceProvider.markAsAuthorized(accessor, request.getParameter("username"), zmtoken);
            OAuthServiceProvider.generateVerifier(accessor);
            returnToConsumer(request, response, accessor);
        }
    } catch (Exception e) {
        LOG.debug("AuthorizationHandler exception", e);
        OAuthServiceProvider.handleException(e, request, response, true);
    }
}
Also used : OAuthAccessor(net.oauth.OAuthAccessor) OAuthMessage(net.oauth.OAuthMessage) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 9 with OAuthAccessor

use of net.oauth.OAuthAccessor in project zm-mailbox by Zimbra.

the class OAuthAuthorizationServlet method doGet.

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    LOG.debug("Authorization Handler doGet requested!");
    try {
        OAuthMessage oAuthMessage = OAuthServlet.getMessage(request, null);
        OAuthAccessor accessor = OAuthServiceProvider.getAccessor(oAuthMessage);
        if (Boolean.TRUE.equals(accessor.getProperty("authorized"))) {
            // already authorized send the user back
            returnToConsumer(request, response, accessor);
        } else {
            sendToAuthorizePage(request, response, accessor);
        }
    } catch (Exception e) {
        OAuthServiceProvider.handleException(e, request, response, true);
    }
}
Also used : OAuthAccessor(net.oauth.OAuthAccessor) OAuthMessage(net.oauth.OAuthMessage) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 10 with OAuthAccessor

use of net.oauth.OAuthAccessor in project zm-mailbox by Zimbra.

the class OAuthTokenCache method get.

public static OAuthAccessor get(String consumer_token, String token_type) throws ServiceException {
    String key_prefix = null;
    if (token_type == OAuthTokenCache.ACCESS_TOKEN_TYPE) {
        key_prefix = OAuthTokenCacheKey.ACCESS_TOKEN_PREFIX;
    } else if (token_type == OAuthTokenCache.REQUEST_TOKEN_TYPE) {
        key_prefix = OAuthTokenCacheKey.REQUEST_TOKEN_PREFIX;
    }
    OAuthTokenCacheKey key = new OAuthTokenCacheKey(consumer_token, key_prefix);
    LOG.debug("get type: " + token_type + " token from memcache with key: " + key.getKeyPrefix() + key.getKeyValue() + ".");
    OAuthAccessor cache = sTheInstance.get(key);
    if (cache != null) {
        if (token_type == OAuthTokenCache.ACCESS_TOKEN_TYPE) {
            cache.accessToken = consumer_token;
            cache.requestToken = null;
        } else {
            cache.requestToken = consumer_token;
            cache.accessToken = null;
        }
    }
    return cache;
}
Also used : OAuthAccessor(net.oauth.OAuthAccessor)

Aggregations

OAuthAccessor (net.oauth.OAuthAccessor)13 OAuthMessage (net.oauth.OAuthMessage)9 IOException (java.io.IOException)5 OAuthConsumer (net.oauth.OAuthConsumer)5 ServletException (javax.servlet.ServletException)4 ServiceException (com.zimbra.common.service.ServiceException)3 Account (com.zimbra.cs.account.Account)3 OAuthProblemException (net.oauth.OAuthProblemException)3 AuthToken (com.zimbra.cs.account.AuthToken)2 ZimbraAuthToken (com.zimbra.cs.account.ZimbraAuthToken)2 OAuthAccessorSerializer (com.zimbra.cs.account.oauth.OAuthAccessorSerializer)2 OutputStream (java.io.OutputStream)2 IllegalArgumentException (java.lang.IllegalArgumentException)2 OAuthValidator (net.oauth.OAuthValidator)2 SimpleOAuthValidator (net.oauth.SimpleOAuthValidator)2 AuthTokenException (com.zimbra.cs.account.AuthTokenException)1 OAuthConsumer (com.zimbra.soap.account.message.OAuthConsumer)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1