小编dur*_*dur的帖子

如何在 SonarQube Scanner for Jenkins 中设置 sonar.projectBaseDir?

我尝试使用SonarQube Scanner插件(版本 2.5)分析 Jenkins 中多模块项目的一个模块。不幸的是,Jenkins 选择了错误的模块作为工作目录。

在这种特殊情况下,我可以更改模块的顺序,但一般来说(多个分析模块)它不起作用。所以我想解决该属性的问题sonar.projectBaseDir,请参阅高级 SonarQube 扫描仪用法

替代分析目录

如果要分析的文件不在分析开始的目录中,请使用该sonar.projectBaseDir属性将分析移动到其他目录。EG 分析从 开始jenkins/jobs/myjob/workspace,但要分析的文件位于ftpdrop/cobol/project1.

声纳项目.properties

sonar.projectBaseDir=/home/ftpdrop/cobol/project1
sonar.sources=src
sonar.cobol.copy.directories=/copy

我尝试了以下方法将sonar.projectBaseDir属性设置为正确的模块(module2而不是module1):

  1. sonar.projectBaseDirsonar-project.properties在文件中

    但这不起作用。文件中的属性sonar-project.properties将被忽略。日志显示该属性已被 JVM 选项覆盖:

    /Users/test/jenkinsslave/tools/hudson.plugins.sonar.SonarRunnerInstallation/SonarQube_Scanner_2.8/bin/sonar-scanner -X -e -Dsonar.host.url=http://sonarqube:9090 -Dproject.settings=/Users/test/jenkinsslave/workspace/Test/module2/sonar-project.properties -Dsonar.projectBaseDir=/Users/test/jenkinsslave/workspace/Test/module1
    
    Run Code Online (Sandbox Code Playgroud)

    我认为这是 SonarQube Scanner 插件中的一个错误,因为project.settings与 不兼容 sonar.projectBaseDir,请参阅高级 SonarQube Scanner 用法

    该属性project.settings可用于指定项目配置文件的路径(该选项与project.homesonar.projectBaseDir属性不兼容)。

  2. sonar.projectBaseDir作为JVM 选项

    但这不起作用。该属性被忽略。日志显示该属性被覆盖:

    /Users/test/jenkinsslave/tools/hudson.plugins.sonar.SonarRunnerInstallation/SonarQube_Scanner_2.8/bin/sonar-scanner -X -e -Dsonar.host.url=http://sonarqube:9090 -Dsonar.projectBaseDir=/Users/test/jenkinsslave/workspace/Test/module1 …
    Run Code Online (Sandbox Code Playgroud)

sonarqube sonarqube-scan

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

Java Unirest 禁用证书

您能否告诉我如何禁用使用 Unirest 作为休息客户端的证书验证。

我将 Unirest 与 Java Spring 结合使用。下面是我的源代码:

try {
    HttpResponse<String> response = Unirest.post("myurl")
      .header("content-type", "application/json")
      .header("accept", "application/json")
      .body("my json data here")
      .asJson();
} catch (Exception e) {
    logger.info("==================REST CLIENT ERROR: "+e.getMessage());
}
Run Code Online (Sandbox Code Playgroud)

结果:

==================REST客户端错误:javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX路径构建失败:sun.security.provider.certpath .SunCertPathBuilderException:无法找到请求目标的有效证书路径

java spring unirest spring-boot

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

如何使用自定义验证规则扩展 Spring Security 的 @Preauthorize?

Spring Security 提供了一些方便的方法控制注解:

@PreAuthorize("hasRole('ADMIN')")
@PreAuthorize("hasAuthority('ROLE_ADMIN')")
@PreAuthorize("hasPermission('ADD')")
Run Code Online (Sandbox Code Playgroud)

我想用一些自定义方法来扩展它,比如

 @PreAuthorize("hasCompany('XX')") 
Run Code Online (Sandbox Code Playgroud)

其验证数据应来自 JWT 令牌。

任何人都可以帮忙吗?

spring-security jwt

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

如何在浏览器中自动添加(例外)SSL 证书

首先,如果这个问题无效,我很抱歉,我正在处理一种情况,我在本地创建了 SSL 证书并由本地 CA 签名。

我的前端应用程序是有角度的,而我的后端应用程序是在 Spring boot 中,当我尝试从 UI 连接登录时,我需要手动添加此证书,因为我通过单击该按钮给出了一个链接按钮,我将加载后端 api在浏览器中

在此输入图像描述

之后将打开一个弹出窗口并加载后端 api,

在此输入图像描述

然后我需要手动单击“高级”,然后继续不安全。完成所有这些步骤后,证书将添加到浏览器中。

任何人都可以建议如何自动添加它,而无需所有这些手动工作。

java ssl spring-boot angular

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

Why Resource Server has to know client_id in Spring OAuth2?

I'm implementing OAuth2 authorization using Spring Boot. I have already Authorization Server and Resource Server, now I want to access resources from Resource Server using client_credentials grant type.

I'm little confused about it, because in Resource Server I have to add client_id and client_secret. But why Resource Server really need it?

As I understand this concept client should get from Authorization Server using client credentials his access token. And then send this access token to Resource Server without any …

spring-security oauth-2.0

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

GCP 对存储桶的只写访问 (GCS)

我们正在尝试为不同的源系统创建不同的存储桶,并只允许它们访问特定存储桶上的转储数据。他们不应该具有读取权限,即他们不应该能够看到桶内的帽子。是否可行,如果可行,如何实现?

bucket google-cloud-platform

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

仅在特定 URL 上调用自定义 Spring Security 过滤器

我有一个 Spring Boot 应用程序,我试图在其中创建一个自定义安全过滤器,如下所示:

public class CustomSecurityFilter extends GenericFilterBean {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        //it should be invoked only for "/needCustomSecurityOnThisURL"
        chain.doFilter(request, response);
    }
}
Run Code Online (Sandbox Code Playgroud)

现在,我只想在特定的 URL 上调用它,但我无法弄清楚这一点。我正在使用以下代码调用它:

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http
            .authorizeRequests()
                .anyRequest().authenticated()
                .and()
            .csrf().disable() // Disable CSRF Token
            .httpBasic();

        // Disable Session Management
        http
            .sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS);

        //want to add the Custom Security Filter n it should …
Run Code Online (Sandbox Code Playgroud)

java spring restful-authentication spring-security spring-filter

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

如何使用 Terraform 挂载 ebs_block_device?

谁能建议我如何自动挂载使用 Terraform 创建的 EBS 卷并使其可用/custom

\n
resource "aws_instance" "ec201" {\n...\n  ebs_block_device {\n    device_name = "/dev/sdd"\n    volume_type = "gp2"\n    volume_size = 10\n    delete_on_termination = true\n    encrypted = true\n  }\n...\n
Run Code Online (Sandbox Code Playgroud)\n

可以自动挂载吗?

\n

我已阅读这些页面:

\n\n

当我做一个:

\n
> lsblk\nNAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT\n...\nnvme1n1     259:0    0   10G  0 disk \nnvme0n1     259:1    0  250G  0 disk \n\xe2\x94\x94\xe2\x94\x80nvme0n1p1 259:2    0  250G  0 part /\n
Run Code Online (Sandbox Code Playgroud)\n

我有一个 10GB 分区未挂载。是否可以使用 terraform …

amazon-ec2 amazon-web-services terraform terraform-provider-aws

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

如何将已弃用的 WebSecurityConfigurerAdapter 迁移到 SecurityFilterChain?

正如他们在这里描述我们的那样,该遗嘱WebSecurityConfigurerAdapter很快就被弃用了。

由于我想实现 JWT 模式,我尝试重构WebSecurityConfigurerAdapterwith的实现。SecurityFilterChain我面临的主要考虑因素是配置返回无效。

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder);
}

@Override
protected void configure(HttpSecurity http) throws Exception {
    CustomAuthenticationFilter customAuthenticationFilter = new CustomAuthenticationFilter(authenticationManagerBean(), accessTokenExpiredInDays, refreshTokenExpiredInDays, jwtSecret);
    customAuthenticationFilter.setFilterProcessesUrl("/api/login");
    http
        .csrf().disable();
    http
        .sessionManagement()
            .sessionCreationPolicy(SessionCreationPolicy.STATELESS);
    http
        .authorizeRequests()
            .antMatchers("/error").permitAll();
    http
        .authorizeRequests()
            .antMatchers("/api/login/**", "/api/token/refresh/**").permitAll();
    http
        .authorizeRequests()
            .anyRequest().authenticated();
    http
        .addFilter(customAuthenticationFilter);
    http
        .addFilterBefore(new CustomAuthorizationFilter(jwtSecret), UsernamePasswordAuthenticationFilter.class);
}

@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception{
    return super.authenticationManagerBean();
}
Run Code Online (Sandbox Code Playgroud)

java spring spring-security

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

MeterRegistry 计数器测试用例失败

我已经通过注入和增加计数在我的服务中实现了 Micrometer Prometheus 计数器,MeterRegistry如下所示,并且我还编写了一个测试用例,但是当我运行测试用例时,我得到:

“java.lang.NullPointerException:无法调用“io.micrometer.core.instrument.MeterRegistry.counter(String, String[])”,因为“this.meterRegistry”为空”。

服务文件:

@Autowired
private MeterRegistry meterRegistry;
    
public void counterIncrement() { 
    meterRegistry.counter("test_count").increment();
}
Run Code Online (Sandbox Code Playgroud)

测试用例文件:

@MockBean
private MeterRegistry registry;
     
@Test
void testCounter() {
    //  invoking counterIncrement();
}
Run Code Online (Sandbox Code Playgroud)

junit spring-boot micrometer spring-micrometer

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