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;
}
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;
}
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);
}
}
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);
}
}
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;
}
Aggregations