小编dur*_*dur的帖子

springSecurityFilterChain不能为null

我正在使用Spring Boot 1.4.0.M2,我编写了以下测试用例,以确保具有弹簧安全性的控制器正常运行.

@RunWith(SpringRunner.class)
@WebMvcTest(HelloController.class)
public class HelloControllerTest {

    @Autowired
    private WebApplicationContext wac;

    private MockMvc mockMvc;

    @Before
    public void setUp() {
        mockMvc = MockMvcBuilders
                .webAppContextSetup(wac)
                .alwaysDo(print())
                .apply(springSecurity())
                .build();
    }

    @Test
    public void getHelloShouldReturnWithCacheControlSet() throws Exception {
        this.mockMvc.perform(get("/hello")
                .accept(MediaType.TEXT_PLAIN))
                .andExpect(status().isOk())
                .andExpect(content().string("Hello World!"))
                .andExpect(header().stringValues("Cache-Control", "max-age=5"));
    }
}
Run Code Online (Sandbox Code Playgroud)

当我运行测试时,抛出以下异常:

java.lang.IllegalStateException: springSecurityFilterChain cannot be null. Ensure a Bean with the name springSecurityFilterChain implementing Filter is present or inject the Filter to be used.
Run Code Online (Sandbox Code Playgroud)

所有其他代码可以在这里找到:https://github.com/renewinkler84/http-cache-demo

为什么抛出这个异常?还有什么我需要配置?

spring spring-security spring-boot

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

jQuery.Deferred 异常:无法读取属性

var arr = [{
    value: 'a'
}];
var getTest = function() {
    jQuery.each(arr, function(i, val) {

        if (val.value == "a") {
            return val;
        }
    });
}

alert(getTest().value);
Run Code Online (Sandbox Code Playgroud)

jquery-3.1.0.js:3793 Uncaught TypeError: 无法读取未定义的属性“值”

jquery

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

数据绑定android中的修剪方法

是有可能trim()的方法是在两个方面数据绑定,从XML获取信息时的工作.如果有,怎么样?

android:text='@={contact.contactDetails.name}'
Run Code Online (Sandbox Code Playgroud)

android 2-way-object-databinding android-databinding

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

开始发布时出错:工作树中有未跟踪的文件

我正在使用Maven JGit-Flow插件来自动化一些发布过程。不幸的是,当我尝试使用mvn jgitflow:release-start以下命令启动新版本时遇到了这个问题:

[ERROR] Failed to execute goal external.atlassian.jgitflow:jgitflow-maven-plugin:1.0-m5.1:release-start (default-cli) on project <myProjectName>: Error starting release: Error starting release: Working tree has untracked files 
Run Code Online (Sandbox Code Playgroud)

但是我在这里(在主服务器上)也看不到和未跟踪的文件:

git status
On branch develop
Your branch is up-to-date with 'origin/develop'.
nothing to commit, working directory clean
Run Code Online (Sandbox Code Playgroud)

知道Maven JGit-Flow插件如何查找未跟踪的文件吗?

maven jgitflow-maven-plugin

5
推荐指数
2
解决办法
5088
查看次数

为什么 Linux 下的 PDF 文本会被截断?

我尝试在 Jasper Reports 中格式化日期,它适用于 Windows,但不适用于 Linux。对于 Linux,生成的文本会被截断。

代码:

JRXML:

<parameter name="timestamp" class="java.util.Date"/>
[...]
<textField>
    <reportElement x="0" y="0" width="50" height="16" uuid="0007846a-26f1-457a-a198-67a2f7c8417c">
        <property name="local_mesure_unitwidth" value="pixel"/>
        <property name="com.jaspersoft.studio.unit.width" value="px"/>
        <property name="local_mesure_unitx" value="pixel"/>
        <property name="com.jaspersoft.studio.unit.x" value="px"/>
        <property name="local_mesure_unity" value="pixel"/>
        <property name="com.jaspersoft.studio.unit.y" value="px"/>
        <property name="local_mesure_unitheight" value="pixel"/>
        <property name="com.jaspersoft.studio.unit.height" value="px"/>
    </reportElement>
    <box padding="2"/>
    <textElement textAlignment="Left" verticalAlignment="Top">
        <font size="8" pdfFontName="Helvetica" pdfEncoding="Cp1250" isPdfEmbedded="true"/>
    </textElement>
    <textFieldExpression><![CDATA[DATEFORMAT($P{timestamp},"dd.MM HH:mm")]]></textFieldExpression>
</textField>
Run Code Online (Sandbox Code Playgroud)

Maven 依赖项:

<dependency>
    <groupId>net.sf.jasperreports</groupId>
    <artifactId>jasperreports</artifactId>
    <version>5.6.0</version>
</dependency>
<dependency>
    <groupId>net.sf.jasperreports</groupId>
    <artifactId>jasperreports-functions</artifactId>
    <version>5.6.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

爪哇:

private byte[] createPdf() {

    try { …
Run Code Online (Sandbox Code Playgroud)

java fonts pdf-generation jasper-reports export-to-pdf

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

在 JAX-RS 项目中使用 Spring RestTemplate

我的项目由 5 个模块组成。其中只有一个使用 JAX-RS,其他使用 Spring。我当前的任务是开发服务,即向某些 API 发送 HTTP 请求。我想使用 SpringRestTemplate来完成这个任务,但问题是 JAX-RS 的项目没有RestTemplate类和其他需要的依赖项。我想用:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>4.2.5.RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

在 JAX-RS 模块中,以避免RestTemplate为某些 JAX-RS 客户端和为某些 JAX-RS 客户端重复代码。这是个好主意吗?会在RestTemplate没有spring-core依赖的情况下正常工作吗?

rest spring jax-rs

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

如何避免使用 Spring Security 重定向到某些 URL 的登录表单?

这是我的 webapp 的 Spring Security 配置

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
        .authorizeRequests()
            .antMatchers("/", LOGIN, "/webjars/**").permitAll()
            .antMatchers(CONFIGURATION).hasAuthority(Authorities.AUTHORITY_SOLMAN72_EXPORT_ENABLED.getKey())
            .antMatchers("/api/**").hasAuthority(Authorities.AUTHORITY_SOLMAN72_EXPORT_ENABLED.getKey())
            .and()
        .formLogin()
            .loginPage(LOGIN)
            .and()
        .addFilterBefore(oAuth2ClientAuthenticationProcessingFilter, BasicAuthenticationFilter.class);
}
Run Code Online (Sandbox Code Playgroud)

目前,服务器正在将LOGIN每个没有正确凭据的请求重定向到该页面。

我只想将LOGIN未经授权的请求重定向到页面CONFIGURATION,而未经授权的请求/api/**应以 403 回答。

实现这一目标的好方法是什么?

spring spring-security spring-boot

5
推荐指数
3
解决办法
3200
查看次数

仅使用 openssl 创建了 java truststore.p12

我在安装过程中生成自签名证书,并且不想安装 JDK 来获取 keytool(这无疑会使 问题变得更容易)。

根据之前的讨论,PKCS12 信任库包必须具有必需的属性“2.16.840.1.113894.746875.1.1”,以便 JRE 将其用作可接受的信任库。

本文介绍向证书请求添加 OID。该方法看起来很有希望,但我不断收到以下错误

Error Loading request extension section req_ext
...:X509 V3 routines:do_ext_nconf:unknown extension:../crypto/x509v3/v3_conf.c:82:
...:X509 V3 routines:X509V3_EXT_nconf:error in extension:../crypto/x509v3/v3_conf.c:47:name=java_trusted_ca, value=yes
.
.
where relevant parts of openssl.conf are:
oid_section = OIDs
[ OIDs ]
java_trusted_ca = 2.16.840.1.113894.746875.1.1
[ req ]
req_extensions = req_ext
[ req_ext ]
java_trusted_ca=yes
Run Code Online (Sandbox Code Playgroud)

我需要帮助设置属性,以便属性包含:

MAC Iteration 1024
MAC verified OK
PKCS7 Encrypted data: pbeWithSHA1And40BitRC2-CBC, Iteration 1024
Certificate bag
Bag Attributes
    friendlyName: microsoft it ssl sha2 …
Run Code Online (Sandbox Code Playgroud)

java openssl java-security

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

Spring Security 5 OAuth2客户端密码授予类型

我有2个应用程序:

  1. Spring应用程序1是客户端和资源服务器。
  2. Spring应用程序2是授权服务器。

用户将能够登录应用程序 1 并访问其资源。我想实现以下流程:

用户在登录表单中输入其凭据 -> 应用程序 1 将使用用户凭据及其clientId密码授予类型从应用程序 2 获取令牌 -> 使用令牌访问应用程序 1 的资源。

问题是Spring Security 5是否支持客户端的密码授予类型?我在 Spring Security 5 实现中找到了所有其余授权类型,但没有找到密码。

spring spring-security oauth-2.0 spring-boot spring-security-oauth2

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

Spring Security 与 Spring Boot 3 - 从安全上下文持有者获取 JWT 令牌

迁移到 Spring Boot 3 后,

extends ResourceServerConfigurerAdapter is deprecrated.
Run Code Online (Sandbox Code Playgroud)

因此,无法使用覆盖的方法

   @Override
public void configure(ResourceServerSecurityConfigurer config) {
    config.tokenServices(tokenServices());
}
Run Code Online (Sandbox Code Playgroud)

我可以将其替换为

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
    http.csrf().disable();
    http.authorizeHttpRequests(auth->auth.
            requestMatchers(whitelistedEndPoints()).permitAll()
            .anyRequest()
            .anonymous())
            .httpBasic().disable();
    return http.build();
}
Run Code Online (Sandbox Code Playgroud)

我有一个现有代码可以从 OAuth 获取 jwt 令牌,如下所示

 public String getJwtTokenFromAuth() {
    OAuth2Authentication auth =(OAuth2Authentication) SecurityContextHolder.getContext().getAuthentication();
  
    OAuth2AuthenticationDetails oauth2AuthenticationDetails = (OAuth2AuthenticationDetails) auth.getDetails();
    return oauth2AuthenticationDetails.getTokenValue();
}
Run Code Online (Sandbox Code Playgroud)

然而,

OAuth2Authentication 和 OAuth2AuthenticationDetails 不可用

我如何用 Spring Boot 3 的新 Spring Security 模块替换此代码/功能。下面是 pom 依赖项,请建议我是否需要添加/删除任何依赖项?

  <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-oauth2-resource-server</artifactId>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

spring-security spring-boot

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