小编jim*_*arn的帖子

如何在基于 Spring 的反应式应用程序中从身份验证中排除路径?

在非反应式 spring 应用程序中,我通常会创建一个配置类,扩展WebSecurityConfigurerAdapter和配置WebSecurity如下:

@Override
public void configure(WebSecurity web) throws Exception {
    web.ignoring().antMatchers("/pathToIgnore");
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能在反应式应用程序中做同样的事情?

security spring reactor

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

登录Spring Controller建议期间如何使MDC可用?

我有一个spring-boot Web应用程序,该应用程序利用logback的MDC上下文来用自定义数据丰富日志。我具有以下实现方式,该实现方式可以使用一些与“ customKey”关联的自定义数据,并且在将%X {customKey}添加到logback配置中的日志记录模式后,它会被正确记录:

public class MDCFilter extends OncePerRequestFilter implements Ordered {

@Override
protected void doFilterInternal(HttpServletRequest httpServletRequest,
        HttpServletResponse httpServletResponse,
        FilterChain filterChain) throws ServletException, IOException {
        try {

            MDC.put("customKey", "someValue");          

            filterChain.doFilter(httpServletRequest, httpServletResponse);
        } catch(Throwable t) {
            LOG.error("Uncaught exception occurred", t);
            throw t;
        } finally {
            MDC.remove("customKey");
        }
    }

    public int getOrder() {
        return Ordered.HIGHEST_PRECEDENCE - 4;
    }
}
Run Code Online (Sandbox Code Playgroud)

只要没有抛出未捕获的异常,此方法就可以正常工作。为了解决这些问题,我准备了控制器建议。遗憾的是,MDC在登录控制器建议期间不再可用,因为它已被清理。如果我正确理解,spring将通过使用HandlerExceptionResolverComposite来确定负责的ExceptionHandler,该实现以最低的优先级进行注册,因此,它是在MDC已清理之后的最后一个。

我现在的困惑是:我应该如何注册我的过滤器,以便在登录控制器建议期间仍可以使用MDC?

我认为一个选择是从过滤器的finally块中删除MDC.remove(...)调用,而是实现一个ServletRequestListener,它在requestDestroyed-方法中清除MDC。但是由于该过滤器用于多个Web模块,所以我需要确保在每个现有的预期模块以及MDCFilter中也声明了ServletRequestListener,这对我来说似乎很容易出错。此外,如果负责将数据添加到MDC的过滤器还负责删除它,我希望使用它。

logback mdc spring-boot

6
推荐指数
1
解决办法
574
查看次数

IntelliJ Idea:依赖关系查看器中的红线

我开始尝试intellij提供的不同图表视图,并偶然发现了依赖关系视图.在我的一个项目中,我遇到过除了指示依赖关系的蓝色箭头之外,还有一些使用红线显示的依赖关系.IntelliJ试图在这里告诉我什么.它是否暗示可能或可能是明确的问题?

Intellij依赖视图

diagram intellij-idea

5
推荐指数
1
解决办法
2484
查看次数

android资源限定符-b代表什么?

在其中一个基本的android教程中,我遇到了资源/配置标识符"-b +",没有解释.来源可以在这里找到:https://developer.android.com/training/basics/supporting-devices/languages.html

在那里声明,为了支持不同的语言环境,在命名资源文件夹时可以使用以下格式:

<resource type>-b+<language code>[+<country code>]
Run Code Online (Sandbox Code Playgroud)

美国语言环境的一个具体示例包括语言代码和国家/地区代码:

<project_root>/res/values-b+en+US/
Run Code Online (Sandbox Code Playgroud)

我的问题是-b代表什么,以及它如何与省略"-b +"约定的不同格式有关,并且在顶部使用字母"r"来识别语言代码和区域?

<project_root>/res/values-en-rUS
Run Code Online (Sandbox Code Playgroud)

可以在这里找到:https://developer.android.com/guide/topics/resources/providing-resources.html#table2

此致,本

android localization

5
推荐指数
0
解决办法
173
查看次数

如何过滤通量中具有最高值的所有元素

在事先不知道最高值的情况下,如何筛选发布者以获取具有最高值的元素?

这是一个小测试来说明我想要实现的目标:

@Test
fun filterForHighestValuesTest() {
    val numbers = Flux.just(1, 5, 7, 2, 8, 3, 8, 4, 3)
        // what operators to apply to numbers to make the test pass?

    StepVerifier.create(numbers)
        .expectNext(8)
        .expectNext(8)
        .verifyComplete()
}
Run Code Online (Sandbox Code Playgroud)

我从reduce 运算符开始:

@Test
fun filterForHighestValuesTestWithReduce() {

    val numbers = Flux.just(1, 5, 7, 2, 8, 3, 8, 4, 3)
        .reduce { a: Int, b: Int -> if( a > b) a else b }

    StepVerifier.create(numbers)
        .expectNext(8)
        .verifyComplete()
}
Run Code Online (Sandbox Code Playgroud)

当然,该测试通过了,但只会发出一个Mono,而我想获得Flux包含具有最高值的所有元素,例如这个简单示例中的 8 和 8 …

spring project-reactor

5
推荐指数
1
解决办法
7478
查看次数

从 Mono 的列表中创建 Flux 的正确方法

假设我有一个使用 CustomObjects 列表的 API 操作。对于这些对象中的每一个,它都会调用一个创建 Mono 的服务方法。如何以惯用的非阻塞方式从这些 Mono 对象创建 Flux?

我现在想到的是这个。我更改了方法名称以更好地反映其预期目的。

fun myApiMethod(@RequestBody customObjs: List<CustomObject>): Flux<CustomObject> {

    return Flux.create { sink ->
        customObjs.forEach {

            service.persistAndReturnMonoOfCustomObject(it).map {
                sink.next(it)
            }
        }
        sink.complete()
    }
}
Run Code Online (Sandbox Code Playgroud)

此外,我是否需要订阅流量才能真正返回一些东西?

mono spring flux kotlin project-reactor

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

为 client_credentials 流程配置 Spring OAuth2 客户端

我们为 oauth2 客户端提供了以下客户端配置,该配置与 Spring Boot 1.4.0 配合得很好:

@Configuration
@ConfigurationProperties(prefix = "pmc.oauth.client")
public class OAuthClientConfig {

@NotNull
private String scope;

@NotNull
private String clientSecret;

@NotNull
private String clientId;

@NotNull
private String accessTokenUri;

private int clientReadTimeout = 60000;
private int clientConnectTimeout = 60000;

@Bean
public OAuth2ProtectedResourceDetails oAuth2ProtectedResourceDetails() {
    ClientCredentialsResourceDetails resourceDetails = new ClientCredentialsResourceDetails();
    resourceDetails.setAccessTokenUri(accessTokenUri);
    resourceDetails.setClientId(clientId);
    resourceDetails.setClientSecret(clientSecret);
    resourceDetails.setScope(Collections.singletonList(scope));
    return resourceDetails;
}

@Bean
public OAuth2ClientContext oauth2ClientContext() {
    DefaultOAuth2ClientContext defaultOAuth2ClientContext = new DefaultOAuth2ClientContext();
    return defaultOAuth2ClientContext;
}

@Bean
public OAuth2RestTemplate oAuth2RestTemplate(OAuth2ProtectedResourceDetails oAuth2ProtectedResourceDetails, OAuth2ClientContext oauth2ClientContext) {
    OAuth2RestTemplate …
Run Code Online (Sandbox Code Playgroud)

spring-boot spring-security-oauth2

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