use of net.oauth.OAuthAccessor in project bigbluebutton by bigbluebutton.
the class IMSJSONRequest 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 bigbluebutton by bigbluebutton.
the class BasicLTIUtil method signProperties.
/**
* Add the necessary fields and sign.
*
* @param postProp
* @param url
* @param method
* @param oauth_consumer_key
* @param oauth_consumer_secret
* @param tool_consumer_instance_guid
* See: {@link BasicLTIConstants#TOOL_CONSUMER_INSTANCE_GUID}
* @param tool_consumer_instance_description
* See: {@link BasicLTIConstants#TOOL_CONSUMER_INSTANCE_DESCRIPTION}
* @param tool_consumer_instance_url
* See: {@link BasicLTIConstants#TOOL_CONSUMER_INSTANCE_URL}
* @param tool_consumer_instance_name
* See: {@link BasicLTIConstants#TOOL_CONSUMER_INSTANCE_NAME}
* @param tool_consumer_instance_contact_email
* See:
* {@link BasicLTIConstants#TOOL_CONSUMER_INSTANCE_CONTACT_EMAIL}
* @return
*/
public static Map<String, String> signProperties(Map<String, String> postProp, String url, String method, String oauth_consumer_key, String oauth_consumer_secret, String tool_consumer_instance_guid, String tool_consumer_instance_description, String tool_consumer_instance_url, String tool_consumer_instance_name, String tool_consumer_instance_contact_email) {
postProp = BasicLTIUtil.cleanupProperties(postProp);
postProp.put(LTI_VERSION, "LTI-1p0");
postProp.put(LTI_MESSAGE_TYPE, "basic-lti-launch-request");
// Allow caller to internationalize this for us...
if (postProp.get(BASICLTI_SUBMIT) == null) {
postProp.put(BASICLTI_SUBMIT, "Launch Endpoint with BasicLTI Data");
}
if (tool_consumer_instance_guid != null)
postProp.put(TOOL_CONSUMER_INSTANCE_GUID, tool_consumer_instance_guid);
if (tool_consumer_instance_description != null)
postProp.put(TOOL_CONSUMER_INSTANCE_DESCRIPTION, tool_consumer_instance_description);
if (tool_consumer_instance_url != null)
postProp.put(TOOL_CONSUMER_INSTANCE_URL, tool_consumer_instance_url);
if (tool_consumer_instance_name != null)
postProp.put(TOOL_CONSUMER_INSTANCE_NAME, tool_consumer_instance_name);
if (tool_consumer_instance_contact_email != null)
postProp.put(TOOL_CONSUMER_INSTANCE_CONTACT_EMAIL, tool_consumer_instance_contact_email);
if (postProp.get("oauth_callback") == null)
postProp.put("oauth_callback", "about:blank");
if (oauth_consumer_key == null || oauth_consumer_secret == null) {
dPrint("No signature generated in signProperties");
return postProp;
}
OAuthMessage oam = new OAuthMessage(method, url, postProp.entrySet());
OAuthConsumer cons = new OAuthConsumer("about:blank", oauth_consumer_key, oauth_consumer_secret, null);
OAuthAccessor acc = new OAuthAccessor(cons);
try {
oam.addRequiredParameters(acc);
// System.out.println("Base Message String\n"+OAuthSignatureMethod.getBaseString(oam)+"\n");
List<Map.Entry<String, String>> params = oam.getParameters();
Map<String, String> nextProp = new HashMap<String, String>();
// Convert to Map<String, String>
for (final Map.Entry<String, String> entry : params) {
nextProp.put(entry.getKey(), entry.getValue());
}
return nextProp;
} catch (net.oauth.OAuthException e) {
M_log.warning("BasicLTIUtil.signProperties OAuth Exception " + e.getMessage());
throw new Error(e);
} catch (java.io.IOException e) {
M_log.warning("BasicLTIUtil.signProperties IO Exception " + e.getMessage());
throw new Error(e);
} catch (java.net.URISyntaxException e) {
M_log.warning("BasicLTIUtil.signProperties URI Syntax Exception " + e.getMessage());
throw new Error(e);
}
}
use of net.oauth.OAuthAccessor 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.OAuthAccessor in project zm-mailbox by Zimbra.
the class OAuthRequestTokenServlet method processRequest.
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
try {
OAuthMessage oAuthMessage = OAuthServlet.getMessage(request, null);
OAuthConsumer consumer = OAuthServiceProvider.getConsumer(oAuthMessage);
//TODO: This property is applicable for mobile client.
//For other types of consumers there will be more fields(e.g. Browser)
String device = request.getParameter("device");
consumer.setProperty("device", device);
OAuthAccessor accessor = new OAuthAccessor(consumer);
OAuthServiceProvider.VALIDATOR.validateReqTokenMessage(oAuthMessage, accessor);
// generate request_token and secret
OAuthServiceProvider.generateRequestToken(accessor);
response.setContentType("text/plain");
OutputStream out = response.getOutputStream();
OAuth.formEncode(OAuth.newList("oauth_token", accessor.requestToken, "oauth_token_secret", accessor.tokenSecret, OAuth.OAUTH_CALLBACK_CONFIRMED, "true"), out);
out.close();
} catch (Exception e) {
LOG.debug("RequestTokenHandler exception", e);
OAuthServiceProvider.handleException(e, request, response, true);
}
}
use of net.oauth.OAuthAccessor in project uPortal by Jasig.
the class ZeroLeggedOAuthInterceptor method getOAuthAuthString.
/**
* Get the oauth Authorization string.
*
* @param req the request
* @return the Authorization string
*/
private String getOAuthAuthString(HttpRequest req) throws OAuthException, IOException, URISyntaxException {
RealmOAuthConsumer consumer = getConsumer();
OAuthAccessor accessor = new OAuthAccessor(consumer);
String method = req.getMethod().name();
URI uri = req.getURI();
OAuthMessage msg = accessor.newRequestMessage(method, uri.toString(), null);
return msg.getAuthorizationHeader(consumer.getRealm());
}
Aggregations