小编Sha*_*att的帖子

使用Spring Security和CAS进行单点注销

使用纯Spring Java Config我很难让Spring和CAS执行单点注销.我有单点登录使用下面的配置.我使用一个简单的JSP页面对url https://nginx.shane.com/app/logout执行表单POST,并在POST'd数据中包含CSRF值.这一切似乎都没有错误,但是当我进入安全页面时,它只是让我回来而无需登录.有任何想法吗?

@Configuration
@EnableWebSecurity
public class SecurityWebAppConfig extends WebSecurityConfigurerAdapter {

@Bean
protected ServiceProperties serviceProperties() {
    ServiceProperties serviceProperties = new ServiceProperties();
    serviceProperties.setService("https://nginx.shane.com/app/j_spring_cas_security_check");
    serviceProperties.setSendRenew(false);
    return serviceProperties;
}

@Bean
public CasAuthenticationProvider casAuthenticationProvider() {
    CasAuthenticationProvider casAuthenticationProvider = new CasAuthenticationProvider();
    casAuthenticationProvider.setAuthenticationUserDetailsService(authenticationUserDetailsService());
    casAuthenticationProvider.setServiceProperties(serviceProperties());
    casAuthenticationProvider.setTicketValidator(cas20ServiceTicketValidator());
    casAuthenticationProvider.setKey("an_id_for_this_auth_provider_only");
    return casAuthenticationProvider;
}

@Bean
public AuthenticationUserDetailsService<CasAssertionAuthenticationToken> authenticationUserDetailsService() {
    return new TestCasAuthenticationUserDetailsService();
}

@Bean
public Cas20ServiceTicketValidator cas20ServiceTicketValidator() {
    return new Cas20ServiceTicketValidator("https://nginx.shane.com/cas");
}

@Bean
public CasAuthenticationFilter casAuthenticationFilter() throws Exception {
    CasAuthenticationFilter casAuthenticationFilter = new CasAuthenticationFilter();
    casAuthenticationFilter.setAuthenticationManager(authenticationManager());
    return casAuthenticationFilter;
}

@Bean …
Run Code Online (Sandbox Code Playgroud)

security spring cas spring-security spring-java-config

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

Spring URI PathVariable,文件扩展名无效

我在解决为什么在调用我的控制器方法之前剥离以下请求中的文件扩展名(.jpg)时遇到了问题:

GET http://blah.com/assets/picture.jpg
Run Code Online (Sandbox Code Playgroud)

我已将内容协商设置为不支持路径扩展:

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = { "com.blah" })
public class PlatformWebAppConfig extends WebMvcConfigurerAdapter {    

    public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {    
        configurer.favorPathExtension(false);
        configurer.favorParameter(false);
        configurer.useJaf(false);
        configurer.defaultContentType(MediaType.APPLICATION_JSON);
    }
}
Run Code Online (Sandbox Code Playgroud)

我的控制器是这样的:

@Controller
public class FileUploadRestApi {
    @RequestMapping(
        value = "/assets/{filename}",
        method = RequestMethod.GET)
    public void downloadFile(HttpServletResponse response,
        @PathVariable("filename") String filename,
        Principal principal) {
            // ERROR: 'filename' has extension stripped !!!!
    }
}
Run Code Online (Sandbox Code Playgroud)

我也试过在PlatformWebAppConfig上面的课程中添加以下内容而没有运气:

@Override
public void configurePathMatch(PathMatchConfigurer matcher) {
    matcher.setUseSuffixPatternMatch(true);
    matcher.setUseRegisteredSuffixPatternMatch(true);
}
Run Code Online (Sandbox Code Playgroud)

我试图调试这个问题,我已经看到ContentNegotiationManagerFactoryBean.afterPropertiesSet肯定会看到favorPathExtension设置为false而没有设置内容协商策略(如预期的那样).

更新:

如果我将请求映射更改为

"/assets/{filename:.+}" …
Run Code Online (Sandbox Code Playgroud)

spring file-upload spring-mvc content-negotiation

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

使用Gradle 5.1“实现平台”代替Spring Dependency Management插件

我编写了一个Gradle插件,其中包含许多常用的设置配置,因此我们所有的项目都只需要应用该插件和一组依赖项即可。它使用Spring Dependency Management插件为Spring设置BOM导入,如下面的代码片段所示:

trait ConfigureDependencyManagement {
    void configureDependencyManagement(final Project project) {
        assert project != null

        project.apply(plugin: "io.spring.dependency-management")

        final DependencyManagementExtension dependencyManagementExtension = project.extensions.findByType(DependencyManagementExtension)
        dependencyManagementExtension.imports {                 
            mavenBom "org.springframework.boot:spring-boot-dependencies:2.1.0.RELEASE"
        }
     }
  }
Run Code Online (Sandbox Code Playgroud)

尽管在Gradle 5.1中仍然可以使用,但我想用BOM导入的新依赖机制替换Spring Dependency Management插件,所以我将上面的内容更新为:

trait ConfigureDependencyManagement {
    void configureDependencyManagement(final Project project) {
        assert project != null

        project.dependencies.platform("org.springframework.boot:spring-boot-dependencies:2.1.0.RELEASE")
    }
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,更改意味着没有导入由这些BOM定义的依赖项,并且在构建项目时遇到类似的错误?

找不到org.springframework.boot:spring-boot-starter-web:。要求:项目:

找不到org.springframework.boot:spring-boot-starter-data-jpa:。要求:项目:

找不到org.springframework.boot:spring-boot-starter-security:。要求:项目:

我是否认为Gradle 5.1不再需要Spring Dependency Management插件是正确的,如果是的话,我是否错过了一些使它起作用的东西?

dependencies byte-order-mark gradle spring-boot

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

如何让keycloak导出领域用户然后退出

我们在 AWS ECS 中运行 Keycloak docker 映像,我们需要一种使用 ansible 导出领域和所有用户以实现自动化目的的方法。我们可以使用 ansible 运行以下命令来运行导出

docker exec -i 702f2fd7858d \
  /bin/bash -c "export JDBC_PARAMS=?currentSchema=keycloak_service && 
  /opt/jboss/keycloak/bin/standalone.sh \
  -Djboss.socket.binding.port-offset=100 \
  -Dkeycloak.migration.action=export \
  -Dkeycloak.migration.provider=singleFile \
  -Dkeycloak.migration.realmName=API \
  -Dkeycloak.migration.usersExportStrategy=REALM_FILE \
  -Dkeycloak.migration.file=/tmp/my_realm.json"
Run Code Online (Sandbox Code Playgroud)

但 docker 容器在导​​出后继续运行。由于我们使用适用于 Docker 的 AWS 日志驱动程序阻止访问任何日志,因此我们无法 grep 查找导出过程完成的日志。遗憾的是,Keycloak REST API 不支持将用户包含在现有的部分导出端点中,或者至少具有触发将包含用户的领域导出到已安装的归档系统的端点。

export realm keycloak

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

keycloak 客户端协议映射器(脚本映射器)将请求头添加到令牌中

当我从 keycloak 请求令牌时,我希望将请求中提供的特定标头值(或额外的表单数据)放入生成的令牌的 JWT 负载中。我尝试使用脚本映射器来访问标头值,但我看不到如何访问以任何可用脚本变量发送的表单数据中的标头值或数据:user, realm, userSession, keyclockSession

mapper keycloak

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

空手道karate-config.js不是js函数

我正在尝试将空手道用于e2e测试,并且从最小的设置开始。我想创建一些配置项以karate-config.js供测试使用,但空手道报告该文件不是js函数,因此测试尝试获取配置失败:

Warning: Nashorn engine is planned to be removed from a future JDK release
12:16:35.264 [Test worker] WARN com.intuit.karate - not a js function or feature file: read('classpath:karate-config.js') - [type: NULL, value: null]
---------------------------------------------------------
feature: classpath:karate/insurer.feature
scenarios:  1 | passed:  0 | failed:  1 | time: 0.0163
---------------------------------------------------------
HTML report: (paste into browser to view) | Karate version: 0.9.1
file:/Users/srowatt/dev/repos/api/price-service/build/surefire-reports/karate.insurer.html
---------------------------------------------------------


-unknown-:4 - javascript evaluation failed: priceBaseUrl, ReferenceError: "priceBaseUrl" is not defined in <eval> at line number 1 …
Run Code Online (Sandbox Code Playgroud)

java testing karate

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

Java LocalDateTime.parse 具有毫秒精度但可选微秒精度

有没有办法创建一个 LocalDateTime 模式,该模式将解析至少具有毫秒精度但可选微秒精度的日期/时间,即在下面的毫秒日期/时间解析正常,但第二个以微秒为单位的时间失败。我认为模式“[”“]”中的可选指标将允许这项工作:

DateTimeFormatter DATE_TIME_FORMATTER = 
    DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS[SSS]");
System.out.println(LocalDateTime.parse("2019-02-14 11:04:52.784", DATE_TIME_FORMATTER));     
System.out.println(LocalDateTime.parse("2019-02-14 11:04:52.784108", DATE_TIME_FORMATTER));
Run Code Online (Sandbox Code Playgroud)

java datetime parsing

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