标签: undertow

Wildfly上的Spring Security:执行过滤器链时出错

我正在尝试将Spring Security SAML ExtensionSpring Boot集成.

关于这件事,我确实开发了一个完整的示例应用程序.它的源代码可以在GitHub上找到:

通过将其作为Spring Boot应用程序运行(针对SDK内置的Application Server运行),WebApp可以正常工作.

不幸的是,相同的AuthN进程在Undertow/WildFly根本不起作用.

根据日志,IdP实际上执行AuthN过程:我的自定义UserDetails实现的指令被正确执行.尽管有执行流程,但Spring并未设置并保留当前用户的权限.

@Component
public class SAMLUserDetailsServiceImpl implements SAMLUserDetailsService {

    // Logger
    private static final Logger LOG = LoggerFactory.getLogger(SAMLUserDetailsServiceImpl.class);

    @Override
    public Object loadUserBySAML(SAMLCredential credential)
            throws UsernameNotFoundException, SSOUserAccountNotExistsException {
        String userID = credential.getNameID().getValue();
        if (userID.compareTo("jdoe@samplemail.com") != 0) {     // We're simulating the data access.
            LOG.warn("SSO User Account not found into the system");
            throw new SSOUserAccountNotExistsException("SSO User Account not found into …
Run Code Online (Sandbox Code Playgroud)

spring spring-security wildfly undertow spring-saml

193
推荐指数
1
解决办法
7368
查看次数

如何配置Wildfly以提供静态内容(如图像)?

我有一个在Wildfly 8.0.0 Final上运行的JavaEE应用程序.

应用程序使用大量图像,我不想将它们存储在数据库中,因此它们被写入硬盘.

例如,如何配置Wildfly/Undertow以便在某个URL上提供这些文件(/ var/images)http://localhost:8080/myapplication/imagesFromDisk

static-content wildfly undertow

36
推荐指数
1
解决办法
3万
查看次数

Vert.x事件循环 - 这是如何异步的?

我正在使用Vert.x和基于事件循环的服务器相当新,而不是线程/连接模型.

public void start(Future<Void> fut) {
    vertx
        .createHttpServer()
        .requestHandler(r -> {
            LocalDateTime start = LocalDateTime.now();
            System.out.println("Request received - "+start.format(DateTimeFormatter.ISO_DATE_TIME));
            final MyModel model = new MyModel();
            try {

                for(int i=0;i<10000000;i++){
                    //some simple operation
                }

                model.data = start.format(DateTimeFormatter.ISO_DATE_TIME) +" - "+LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME);

            } catch (Exception e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

          r.response().end(
                  new Gson().toJson(model)
                 );
        })
        .listen(4568, result -> {
          if (result.succeeded()) {
            fut.complete();
          } else {
            fut.fail(result.cause());
          }
        });
    System.out.println("Server started ..");
  }
Run Code Online (Sandbox Code Playgroud)
  • 我只是想模拟一个长时间运行的请求处理程序来理解这个模型是如何工作的.
  • 我观察到的是所谓的事件循环被阻止,直到我的第一个请求完成.无论花费多少时间,后续请求都不会被执行,直到前一个请求完成.
  • 显然我在这里错过了一块,这就是我在这里的问题.

根据目前的答案编辑:

  1. 是不是接受所有被认为是异步的请求?如果只有当前一个连接被清除时才能接受新连接,它是如何异步的?
    • 假设典型请求需要100毫秒到1秒之间的任何时间(基于请求的种类和性质).所以这意味着,事件循环在前一个请求完成之前不能接受新连接(即使它在一秒钟内结束).如果我作为程序员必须仔细考虑所有这些并将这些请求处理程序推送到工作线程,那么它与线程/连接模型有何不同? …

java nio vert.x undertow

17
推荐指数
3
解决办法
7614
查看次数

如何正确读取处理程序中的POST请求正文?

我现在使用的代码:

    Pooled<ByteBuffer> pooledByteBuffer = exchange.getConnection().getBufferPool().allocate();
    ByteBuffer byteBuffer = pooledByteBuffer.getResource();

    int limit = byteBuffer.limit();

    byteBuffer.clear();

    exchange.getRequestChannel().read(byteBuffer);
    int pos = byteBuffer.position();
    byteBuffer.rewind();
    byte[] bytes = new byte[pos];
    byteBuffer.get(bytes);

    String requestBody = new String(bytes, Charset.forName("UTF-8") );

    byteBuffer.clear();
    pooledByteBuffer.free();
Run Code Online (Sandbox Code Playgroud)

它似乎工作正常但我不确定是否需要clear()ByteBuffer才能将其返回池中.我甚至不确定使用exchange.getConnection().getBufferPool().allocate();.文档中没有太多关于它的内容.

java undertow

11
推荐指数
2
解决办法
6574
查看次数

如何使用自定义记录器在spring boot中记录访问日志

目前在spring boot 1.3中,我们只能将访问日志记录到文件系统中的文件中.有没有办法实际使用自定义记录器(如log4j2)来记录访问日志?

我目前正在使用带有spring boot的下载,但是在检查了spring boot源代码之后,使用DefaultAccessLogReceiver初始化了underow logger,它正在写入文件.我想尽可能使用AccessLogHandler,并避免编写记录访问权限的Web过滤器.

这有什么简单的方法吗?(写拉取请求除外)

java spring log4j2 spring-boot undertow

11
推荐指数
1
解决办法
2685
查看次数

如何做非阻塞IO?

我正在使用Undertow创建一个简单的应用程序.

public class App {
    public static void main(String[] args) {
        Undertow server = Undertow.builder().addListener(8080, "localhost")
                .setHandler(new HttpHandler() {

                    public void handleRequest(HttpServerExchange exchange) throws Exception {
                        Thread.sleep(5000);
                        exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
                        exchange.getResponseSender().send("Hello World");
                    }

                }).build();
        server.start();
    }
}
Run Code Online (Sandbox Code Playgroud)

我打开浏览器选项卡,localhost:8080然后打开第二个选项卡localhost:8080

这次第一个标签将等待5秒,第二个标签将等待10秒

为什么会这样?

java undertow

10
推荐指数
3
解决办法
8078
查看次数

如何在WildFly的战争之外提供静态资源

我可能错了,但根据我的理解,WildFly必须具备以下功能:

必须可以将我的JSF视图(即xhtml文件)链接到WildFly服务器上已有的资源(pdf,图像,其他xhtml文件).

我可以在php和apache服务器上做同样的事情.

我需要在哪里放置这些资源,如何从我的视图中访问它们?E. g.将视图中的链接放到pdf文件中,该文件在新选项卡中打开pdf文件.

非常感谢您的提示和提示!!

编辑

standalone.xml

<server name="default-server">
    <http-listener name="default" socket-binding="http" max-post-size="974247881"/>
    <host name="default-host" alias="localhost">
        <location name="/" handler="welcome-content"/>
        <location name="/content" handler="ContentDir"/>
        <filter-ref name="server-header"/>
        <filter-ref name="x-powered-by-header"/>
    </host>
</server>
<servlet-container name="default">
    <jsp-config/>
    <websockets/>
</servlet-container>
<handlers>
    <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
    <file name="ContentDir" path="${jboss.home.dir}/standalone/data/unzipped" directory-listing="true"/> 
</handlers>
Run Code Online (Sandbox Code Playgroud)

链接在JSF视图中

<h:outputLink value="http://localhost:8181/content">KLICK</h:outputLink>
Run Code Online (Sandbox Code Playgroud)

当我点击这个时,我得到目录列表,如你所说.

但是我怎样才能使它显示index.xhtmlcontent指向的目录中?这就是我想要的.

content指向${jboss.home.dir}/standalone/data/unzipped和解压缩有一个index.xhtml以及另一个包含更多.xhtml文件的文件夹.

在文件夹中的文件index.xhtml有相对链接.xhmtl:

<ul>
    <li><a href="t/rt.html">hg</a></li>
    <li><a href="t/tert.html">jghj</a></li>
    <li><a href="t/gf.html">jghj</a></li>
    <li><a href="t/hg.html">jghj</a></li>
    <li><a href="t/hgfh.html">jghj</a></li>
    <li><a href="t/hfgh.html">jhgj</a></li>
    <li><a href="t/hfgh.html">jhgj</a></li> …
Run Code Online (Sandbox Code Playgroud)

wildfly undertow wildfly-8

9
推荐指数
1
解决办法
7942
查看次数

如何从HttpServerExchange获取请求正文?

我创建了一个Undertow服务器和一个处理程序来记录请求.我在检索请求体时遇到问题HttpServerExchange.

LoggingHandler课堂上,我的身体没有问题.但在TestEndpoint身体空洞.

如果我删除了检索请求体的行,LoggingHandler则会填充正文TestEndpoint.

有谁知道这样做的方法?

我的服务器类:

package com.undertow.server;

import com.undertow.server.endpoints.TestEndpoint;

import org.jboss.resteasy.plugins.server.undertow.UndertowJaxrsServer;
import org.jboss.resteasy.spi.ResteasyDeployment;

import io.undertow.Undertow;
import io.undertow.Undertow.Builder;
import io.undertow.server.HandlerWrapper;
import io.undertow.server.HttpHandler;
import io.undertow.server.handlers.BlockingHandler;
import io.undertow.servlet.api.DeploymentInfo;

public class UndertowServer {

    private UndertowJaxrsServer server;

    public UndertowServer() {
        this.server = new UndertowJaxrsServer();
    }

    public void start() {
        Builder builder = Undertow.builder().addHttpListener(8000, "0.0.0.0");
        this.server.start(builder);
        this.configureEndpoints();
    }

    private void configureEndpoints() {
        ResteasyDeployment deployment = new ResteasyDeployment();
        deployment.getActualResourceClasses().add(TestEndpoint.class);

        DeploymentInfo deploymentInfo = this.server.undertowDeployment(deployment) //
                .setClassLoader(ClassLoader.getSystemClassLoader()).setContextPath("/gateway/") //
                .setDeploymentName("gateway.war"); …
Run Code Online (Sandbox Code Playgroud)

java rest httphandler resteasy undertow

9
推荐指数
1
解决办法
1543
查看次数

如何在嵌入式底板中做websockets?

根据这个:http://undertow.io/它支持websockets.但是,没有关于如何这样做的文档.我只想要一个处理Web套接字示例的简单嵌入式底层.

我不想抓住整个jboss应用服务器.

java jboss websocket wildfly undertow

8
推荐指数
2
解决办法
8256
查看次数

如果Web服务器是非阻塞的,这是否意味着它与node.js一样处理IO?

我很快就会使用名为Undertow的服务器.该网站说:

Undertow是一个用java编写的灵活的高性能Web服务器,提供基于NIO的阻塞和非阻塞API

如果Undertow允许非阻塞,那是否与node.js相同?我不是指语言或类似的东西.我有一个单独的项目,我认为node.js是一个不错的选择,但如果我可以将单个产品用于多个项目,那将会很有帮助.

编辑:我发现了这个问题. Java NIO非阻塞模式vs node.js异步操作我开始认为我有些困惑.

java nonblocking node.js undertow

8
推荐指数
1
解决办法
953
查看次数