【问题标题】:How would microfrontend work using Apache Wicket?微前端如何使用 Apache Wicket 工作?
【发布时间】:2020-04-01 20:52:07
【问题描述】:

我想使用 Apache Wicket 实现微前端架构,但我无法让它工作。

add(new WebMarkupContainer("testFrame") {

        @Override
        protected void onComponentTag(ComponentTag tag) {
            checkComponentTag(tag, "iframe");

            super.onComponentTag(tag);
            //Won't work like this if you want to send credentials.
            //tag.put("src", "http://localhost:8089/httpBasicAuthenticated/url/page/");

        }

        @Override
        public void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag) {
            Response response = getRequestCycle().getResponse();

            final CredentialsProvider provider = new BasicCredentialsProvider();

            String username = "user";
            String password = "password";

            final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);

            provider.setCredentials(AuthScope.ANY, credentials);

            final HttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();
            HttpResponse httpResponse = null;

            String body = "";
            try {
                httpResponse = client.execute(new 
                   HttpGet("http://localhost:8089/httpBasicAuthenticated/url/page/"));
                body = IOUtils.toString(httpResponse.getEntity().getContent(), "UTF-8");
            } catch (final IOException e) {

                e.printStackTrace();
            }
            response.write(body);

        }

    });

Result from inspecting the element

我正在尝试使用 iframe,但它没有在 iframe 内呈现页面。有什么不对?如何通过 iframe 根据页面请求发送凭据?

编辑: 在此代码中,我尝试自动发送凭据,以便不显示身份验证提示。

【问题讨论】:

    标签: security iframe wicket basic-authentication micro-frontend


    【解决方案1】:

    使用基本身份验证,您需要呈现<iframe src="..."></iframe>,浏览器会显示一个对话框让您输入凭据。

    如果您在服务器上构建主体(即在 Wicket 代码中),那么您不需要 iframe,而是需要 div

    【讨论】:

    • 我想自动发送凭据而不需要身份验证提示。我刚刚编辑了我的描述。我可以用Include 做到这一点,但这意味着我需要带来页面的网络资源,例如css、js 文件并将其添加到 head 部分,但如果 url 的 <link>s 和 <script> 有相对 url 怎么办。我认为这很麻烦,有什么建议吗?我很高兴听到更多消息。
    猜你喜欢
    • 1970-01-01
    • 2018-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-20
    • 1970-01-01
    • 2019-08-24
    • 1970-01-01
    相关资源
    最近更新 更多