Search in sources :

Example 1 with OAuthAccessor

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;
}
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 OAuthAccessor

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

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);
    }
}
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 4 with OAuthAccessor

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);
    }
}
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 5 with OAuthAccessor

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());
}
Also used : OAuthAccessor(net.oauth.OAuthAccessor) OAuthMessage(net.oauth.OAuthMessage) URI(java.net.URI)

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