小编Rae*_*ald的帖子

X-CSRF-TOKEN 不是由 Spring Boot 生成的

我按照这里的指南:http : //spring.io/guides/gs/rest-service/来构建我的休息服务示例,现在我正在尝试启用 CSRF 保护。我读到它应该默认启用,所以如果我不包括:

http.csrf().disable()

在我的WebSecurityConfigurerAdapter配置中,CSRF 保护应该默认启用,但似乎并非如此。问题是 X-CSRF-TOKEN 没有生成,也没有以任何方式包含在我的 HTTP 响应中。我应该怎么做,让 x-csrf-token 生成并包含在响应中,当然还有 csrf 保护完全起作用?

我注意到,使用类似的 spring mvc 配置,我生成的 x-csrf-token 只包括:

< security:csrf disabled="false"/>

在我的安全配置文件中。但是,使用 Spring Boot 时,我可能会出错,并且无法生成 csrf 令牌。任何人都可以帮助我,也许给我指出一个有效的例子?我的安全配置是:

     @Override
     protected void configure(HttpSecurity http) throws Exception 
     {
        http
      // .csrf().disable()
      .authorizeRequests()
          .anyRequest()
          .authenticated()
      .and()
      .httpBasic()
      .authenticationEntryPoint(new RestAuthenticationEntryPoint())
      .and()
      .formLogin()
      .successHandler(new RestAuthenticationSuccessHandler())
      .failureHandler(new SimpleUrlAuthenticationFailureHandler())
      .and()
      .logout()
      .logoutSuccessHandler(new RestLogoutSuccessHandler());
}

@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception 
{
    auth.userDetailsService(restUserDetailService);
}
Run Code Online (Sandbox Code Playgroud)

java spring csrf spring-security spring-boot

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

如果Object数组是Object,为什么String数组不是String

Object类是Java中每个类的超类.所以每个类都应该固有Object类的属性或行为.

然后我们可以声明对象数组,如下所示:

Object c = new Object[] {1,2,"22" };
Run Code Online (Sandbox Code Playgroud)

然后来到String时为什么下面的声明是错误的:

String s = new String[]{"s","s"};
Run Code Online (Sandbox Code Playgroud)

java

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

配置maven-failsafe-plugin以查找不在src / test / java中的集成测试

我的目录结构如下:

  • src/integrationTest/java
  • src/test/java
  • src/main/java

我试图通过故障保护来进行集成测试,但是没有按照我想要的方式进行。

我已经试过了:

<plugin>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.17</version>
    <executions>
        <execution>
            <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <testSourceDirectory>src/integrationTest/java</testSourceDirectory>
        <testClassesDirectory>${project.build.directory}/it-classes</testClassesDirectory>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

和这个:

<plugin>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.17</version>
    <executions>
        <execution>
            <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <includes>
            <include>src/integrationTest/**/*.java</include>
        </includes>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

无济于事 故障安全找不到运行的测试。

我已经能够使用build-helper-maven插件添加一个test-source目录,然后使用failsafe运行测试。

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.9.1</version>
    <executions>
        <execution>
            <id>add-integration-test-source-as-test-sources</id>
            <phase>generate-test-sources</phase>
            <goals>
                <goal>add-test-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>src/integrationTest/java</source>
                </sources>
            </configuration>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

但是,现在的问题是,surefire现在也将测试作为单元测试运行。当故障保险应该能够找到测试时,似乎也不必使用其他插件。我不希望不需要使用build-helper maven插件并配置surefire来排除该路径。

我究竟做错了什么?

java maven maven-failsafe-plugin

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

如何让 Eclipse 停止要求在创建新 Java 项目时创建模块信息 java 文件?

每次我尝试创建一个新的 Java 项目时,Eclipse 都会不断询问我是否要向源文件夹添加一个 module-info java 文件。这变得非常烦人,因为没有立即明显的选项可以选择退出此检查。

面向 Java 开发人员的 IDE,Photon 版本 4.8.0

java eclipse module-info

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

Angular Karma Jasmine 测试“无法绑定到‘ngIf’,因为它不是已知属性”

我对 Angular 的 Karma Jasmine 测试@Component抱怨说

错误:“无法绑定到‘ngIf’,因为它不是‘p’的已知属性。”

当应用程序本身出现此类错误时,修复方法是确保将其添加BrowserModule到应用程序模块 ( )imports: []中。我确实有这个导入(所以这个问题不是关于“无法绑定到 'ngXXX' 因为它不是 'YYY' 的已知属性”的规范问题的重复)。@NgModule()app.module.ts

这是我的测试设置代码:

    let component: MyComponent;
    let fixture: ComponentFixture<MyComponent>;

    beforeEach(async () => {
        TestBed.configureTestingModule({
            imports: [
                BrowserModule
            ],
            providers: [
                MyComponent,
                { provide: MyService, useClass: MockMyService }
            ]
        }).compileComponents();
        TestBed.inject(MyService);
        component = TestBed.inject(MyComponent);
        fixture = TestBed.createComponent(MyComponent);
        fixture.detectChanges();
    });
Run Code Online (Sandbox Code Playgroud)

我的 HTML 模板显示*ngIf,不是ngIf或拼写错误,这是该错误消息的另一个常见原因:

<div class="self">
    <p *ngIf="isLoggedIn() else selfLogin">Logged in …
Run Code Online (Sandbox Code Playgroud)

jasmine karma-jasmine angular

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

是否有用于记录/监控系统测试的好工具?

我正在寻找一种工具来设计,记录和监控产品的系统测试.

我需要的基础知识是:1)一种工具,可以代表测试之间的某种继承(即,一个测试设置另一个或某些).

2)一个工具,允许我单独监控每个版本的特定测试运行(即,对于产品的1.1版,我们从所有记录的测试中运行这些特定测试).

3)一种工具,它允许某种自由形式的"标记"测试(即,我可以将相同的测试分成几组:回归测试,功能测试,ui测试......一次测试可以一次全部三次).

4)可选 - 该工具将允许我运行"自动测试"脚本(使用内部开发的自动化系统自动化,因此它必须允许多种方式与之配合).

我发现可能有用的一个工具是:http://trac-hacks.org/wiki/TestCaseManagementPlugin

它具有使用Trac的额外好处,我们开始使用它来进行错误跟踪/任务跟踪.如果有人可以推荐(或给出一个不使用它的充分理由),也会非常感激.

谢谢

testing trac system-testing

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

Apache Derby - 检查数据库已经创建?

使用Apache Derby with Java(J2ME,但我认为这没有什么区别)有没有办法检查数据库是否已经存在并包含一个表?

java database derby

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

运行多线程时双重释放或损坏

我在我的C++程序中遇到了一个运行时错误"double free or corruption",它调用了一个可靠的库ANN并使用OpenMP来平行for循环.

*** glibc detected *** /home/tim/test/debug/test: double free or corruption (!prev): 0x0000000002527260 ***     
Run Code Online (Sandbox Code Playgroud)

这是否意味着地址0x0000000002527260的内存被释放多次?

错误发生在"_search_struct-> annkSearch(queryPt,k_max,nnIdx,dists,_eps);" 内部函数classify_various_k(),它在函数tune_complexity()内部的OpenMP for循环中.

请注意,当OpenMP有多个线程时会发生错误,并且在单线程情况下不会发生.不知道为什么.

以下是我的代码.如果它不足以进行诊断,请告诉我.谢谢你的帮助!

  void KNNClassifier::train(int nb_examples, int dim, double **features, int * labels) {                         
      _nPts = nb_examples;  

      _labels = labels;  
      _dataPts = features;  

      setting_ANN(_dist_type,1);   

    delete _search_struct;  
    if(strcmp(_search_neighbors, "brutal") == 0) {                                                                 
      _search_struct = new ANNbruteForce(_dataPts, _nPts, dim);  
    }else if(strcmp(_search_neighbors, "kdtree") == 0) {  
      _search_struct = new ANNkd_tree(_dataPts, _nPts, dim);  
      }  

  }  


      void KNNClassifier::classify_various_k(int dim, double *feature, int label, int *ks, …
Run Code Online (Sandbox Code Playgroud)

c++ multithreading

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

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

在Java EE 6中生成激活URL

我正在使用Java EE 6 Web Profile开发Web应用程序.我想通过电子邮件向新用户发送其帐户的激活链接.我该如何实现呢?我正在使用JSF2.这样做有什么规范或推荐方法吗?

java activation jsf-2

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