简体   繁体   English

Java Dropbox HttpServletRequest(java.lang.UnsupportedOperationException:尚不支持。)

[英]Java Dropbox HttpServletRequest ( java.lang.UnsupportedOperationException: Not supported yet.)

in my java SWING app, the user can transfer files to his DropBox space, I have successfully implemented the library and I'm trying to get the user's access token without having to copy and paste it into my app.在我的 java SWING 应用程序中,用户可以将文件传输到他的 DropBox 空间,我已经成功实现了该库,我正在尝试获取用户的访问令牌,而无需将其复制并粘贴到我的应用程序中。 According to the documentation , I have to use HttpServletRequest to get what I want, but I get an exception, as written in the title.根据文档,我必须使用 HttpServletRequest 来获取我想要的东西,但是我得到了一个异常,如标题中所写。

public class LoginServlet implements HttpServletRequest {

protected void doGet(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {

    // read form fields
    String token = request.getParameter("data-token");
 
 
    // get response writer
    PrintWriter writer = response.getWriter();

    // build HTML code
    String htmlRespone = "<html>";
    htmlRespone += "<h2>token: " + token + "<br/>";
    htmlRespone += "</html>";

    // return response
    writer.println(htmlRespone);

    response.sendRedirect(Main.redirectUri);
    

}
 @Override
public HttpSession getSession(boolean bln) {      
    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public HttpSession getSession() {
    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

and in Main class并在主班

 LoginServlet request = new LoginServlet();
       
        // Fetch the session to verify our CSRF token
        HttpSession session = request.getSession(true);
        String sessionKey = "dropbox-auth-csrf-token";
        DbxSessionStore csrfTokenStore = new DbxStandardSessionStore(session, sessionKey);

        DbxRequestConfig config = new DbxRequestConfig("User"); //Client name can be whatever you like
        DbxAppInfo appInfo = new DbxAppInfo(App key, App secret);
        DbxWebAuth webAuth = new DbxWebAuth(config, appInfo);
        DbxWebAuth.Request authRequest = DbxWebAuth.newRequestBuilder()
                .withRedirectUri(redirectUri, csrfTokenStore)
                .build();

        String url = webAuth.authorize(authRequest);

        Desktop.getDesktop().browse(new URL(url).toURI());

        DbxAuthFinish authFinish;
        try {
            authFinish = webAuth.finishFromRedirect(redirectUri, csrfTokenStore, request.getParameterMap());
        } catch (DbxWebAuth.BadRequestException ex) {
            //log("On /dropbox-auth-finish: Bad request: " + ex.getMessage());
            //response.sendError(400);
            return;
        } catch (DbxWebAuth.BadStateException ex) {
            // Send them back to the start of the auth flow.
            //response.sendRedirect(redirectUri);
            return;
        } catch (DbxWebAuth.CsrfException ex) {
            //log("On /dropbox-auth-finish: CSRF mismatch: " + ex.getMessage());
            //response.sendError(403, "Forbidden.");
            return;
        } catch (DbxWebAuth.NotApprovedException ex) {
            // When Dropbox asked "Do you want to allow this app to access your
            // Dropbox account?", the user clicked "No".

            return;
        } catch (DbxWebAuth.ProviderException ex) {
            //log("On /dropbox-auth-finish: Auth failed: " + ex.getMessage());
            //response.sendError(503, "Error communicating with Dropbox.");
            return;
        } catch (DbxException ex) {
            //log("On /dropbox-auth-finish: Error getting token: " + ex.getMessage());
            //response.sendError(503, "Error communicating with Dropbox.");
            return;
        }
        String accessToken = authFinish.getAccessToken();

        // Save the access token somewhere (probably in your database) so you
        // don't need to send the user through the authorization process again.
        // Now use the access token to make Dropbox API calls.
        DbxClientV2 client = new DbxClientV2(config, accessToken);
        //...

full stack全栈

    java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
    at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:873)
Caused by: java.lang.UnsupportedOperationException: Not supported yet.
    at cloud.LoginServlet.getSession(LoginServlet.java:404)
    at cloud_new.Main.main(Main.java:103)

the row at cloud_new.Main.main(Main.java:103) is this HttpSession session = request.getSession(true); at cloud_new.Main.main(Main.java:103)的行是这个HttpSession session = request.getSession(true);

Note笔记

This is not a solution for the main java question relate to some http error.这不是与某些 http 错误相关的主要 java 问题的解决方案。

This is a proposed approach based or inspired in how heroku auth and google container registry auth works.这是一种基于 heroku 身份验证和谷歌容器注册表身份验证工作方式的建议方法。

Also dropbox and other platforms does not offer a kind of special admin api_key to consume the final user resources. Dropbox 和其他平台也没有提供一种特殊的 admin api_key 来消耗最终用户资源。 Due to that a web login in a real browser is required and this cannot be easily replaced or emulated with web_views or internal browsers in android or ios.由于需要在真实浏览器中进行网络登录,并且这不能轻易替换或模拟为 web_views 或 android 或 ios 中的内部浏览器。 Source 来源

Basic idea基本理念

Develop a web application which exposes two functionalities: receive the redirect from dropbox authorization platform and a rest endpoint to query if user is authenticated.开发一个 Web 应用程序,它公开两个功能:接收来自 Dropbox 授权平台的重定向和一个用于查询用户是否通过身份验证的休息端点。

Assumptions假设

  • web called my-oauth2-helper.com名为 my-oauth2-helper.com 的网络

Flow流动

  • user starts the desktop application.用户启动桌面应用程序。
  • desktop application queries to my-oauth2-helper.com/validate/auth sending user email.my-oauth2-helper.com/validate/auth发送用户电子邮件的桌面应用程序查询。
  • my-oauth2-helper.com/validate/auth returns a field which indicate that user does not have a valid authentication and other field with the dropbox login url. my-oauth2-helper.com/validate/auth返回一个字段,该字段指示用户没有有效的身份验证和其他带有保管箱登录 URL 的字段。
  • dropbox login url which has the classic oauth2 fields previously configured in dropbox developer console: client_id, redirect_uri , etc. dropbox 登录 url,其中包含先前在 dropbox 开发人员控制台中配置的经典 oauth2 字段:client_id、 redirect_uri等。
  • desktop application uses this login url to open a browser tab.桌面应用程序使用此登录 URL 打开浏览器选项卡。
  • User is prompted with a valid dropbox web login, enter its credentials and accept the consent page.系统会提示用户输入有效的 Dropbox Web 登录信息,输入其凭据并接受同意页面。
  • Dropbox following the oauth2 protocol, redirects the user to a my-oauth2-helper.com/redirect which is the classic field called redirect_uri Dropbox 遵循 oauth2 协议,将用户重定向到my-oauth2-helper.com/redirect ,这是一个名为redirect_uri的经典字段
  • my-oauth2-helper.com/redirect receive the auth_code and exchange it for a valid access_token for this user and store it in a kind of database. my-oauth2-helper.com/redirect接收 auth_code 并将其交换为该用户的有效access_token并将其存储在一种数据库中。 After that could shows a message like: "Now, you can close this page and returns to the desktop application"之后可能会显示如下消息:“现在,您可以关闭此页面并返回到桌面应用程序”
  • Since user was prompted with dropbox web login, the desktop application started to queries at regular intervals if user has a valid authentication to the endpoint my-oauth2-helper.com/token sending the email as request parameter由于用户被提示使用 dropbox web 登录,桌面应用程序开始定期查询用户是否对端点my-oauth2-helper.com/token了有效的身份验证,将电子邮件作为请求参数发送
  • After valid access_token generation , the my-oauth2-helper.com/token endpoint returns a valid access_token for this user.生成有效的access_token后, my-oauth2-helper.com/token端点会为此用户返回有效的 access_token。
  • This access_token is ready to use in order to consume any dropbox api feature, which user accepted in consent page.access_token已准备好使用,以使用用户在同意页面中接受的任何 Dropbox api 功能。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “ java.lang.UnsupportedOperationException:尚不支持。” - “java.lang.UnsupportedOperationException: Not supported yet.” “java.lang.UnsupportedOperationException:尚不支持。” - “java.lang.UnsupportedOperationException: Not supported yet.” java.lang.UnsupportedOperationException:尚不支持 - java.lang.UnsupportedOperationException: Not supported yet 由于“线程“AWT-EventQueue-0”中的异常java.lang.UnsupportedOperationException:尚不支持,我的程序无法读取密钥。 - my program cant read the keys because of "Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedOperationException: Not supported yet." Duke Fast Deduplication:java.lang.UnsupportedOperationException:尚不支持操作? - Duke Fast Deduplication: java.lang.UnsupportedOperationException: Operation not yet supported? 由java.lang.UnsupportedOperationException引起:AdapterView不支持addView(View,layoutParams) - Caused by java.lang.UnsupportedOperationException: addView(View,layoutParams) is not supported in the AdapterView java.lang.UnsupportedOperationException 与 ArrayList() - java.lang.UnsupportedOperationException with ArrayList() DBFit java.lang.UnsupportedOperationException: 不支持类型 İNT - DBFit java.lang.UnsupportedOperationException: Type İNT is not supported java.lang.UnsupportedOperationException:option不是受支持的字段类型 - java.lang.UnsupportedOperationException: option is not a supported field type Tomcat连接池-java.lang.UnsupportedOperationException:BasicDataSource不支持 - Tomcat Connection Pooling - java.lang.UnsupportedOperationException: Not supported by BasicDataSource
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM