Search in sources :

Example 1 with OAuthConsumer

use of net.oauth.OAuthConsumer 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;
}
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)

Example 2 with OAuthConsumer

use of net.oauth.OAuthConsumer 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);
    }
}
Also used : OAuthMessage(net.oauth.OAuthMessage) HashMap(java.util.HashMap) OAuthConsumer(net.oauth.OAuthConsumer) OAuthAccessor(net.oauth.OAuthAccessor) Entry(java.util.Map.Entry) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 3 with OAuthConsumer

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

Example 4 with OAuthConsumer

use of net.oauth.OAuthConsumer 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 5 with OAuthConsumer

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

the class OAuthServiceProvider method getConsumer.

public static synchronized OAuthConsumer getConsumer(String consumer_key) throws IOException, OAuthProblemException {
    String[] registeredConsumers;
    try {
        // TODO - need to lookup the domain first
        registeredConsumers = Provisioning.getInstance().getConfig().getMultiAttr(Provisioning.A_zimbraOAuthConsumerCredentials);
    } catch (ServiceException e) {
        throw new OAuthProblemException("token_rejected");
    }
    OAuthConsumer oAuthConsumer = null;
    for (String consumer : registeredConsumers) {
        String[] s = consumer.split(":");
        if (s.length >= 2 && s[0].equals(consumer_key)) {
            oAuthConsumer = new OAuthConsumer(null, consumer_key, s[1], null);
            oAuthConsumer.setProperty("key", consumer_key);
            oAuthConsumer.setProperty("app_name", s.length > 2 ? s[2] : "");
            break;
        }
    }
    if (oAuthConsumer == null) {
        throw new OAuthProblemException("token_rejected");
    }
    return oAuthConsumer;
}
Also used : OAuthProblemException(net.oauth.OAuthProblemException) ServiceException(com.zimbra.common.service.ServiceException) OAuthConsumer(net.oauth.OAuthConsumer)

Aggregations

OAuthConsumer (net.oauth.OAuthConsumer)6 OAuthAccessor (net.oauth.OAuthAccessor)5 OAuthMessage (net.oauth.OAuthMessage)4 ServiceException (com.zimbra.common.service.ServiceException)2 IllegalArgumentException (java.lang.IllegalArgumentException)2 OAuthValidator (net.oauth.OAuthValidator)2 SimpleOAuthValidator (net.oauth.SimpleOAuthValidator)2 Account (com.zimbra.cs.account.Account)1 AuthToken (com.zimbra.cs.account.AuthToken)1 ZimbraAuthToken (com.zimbra.cs.account.ZimbraAuthToken)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 TreeMap (java.util.TreeMap)1 ServletException (javax.servlet.ServletException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 OAuthProblemException (net.oauth.OAuthProblemException)1