0

zk springboot with security-zats

asked 2020-04-16 08:21:17 +0800

wastemails gravatar image wastemails
30

updated 2020-04-16 14:02:32 +0800

cor3000 gravatar image cor3000
5173 2 7
ZK Team
  1. How to exclude spring security using zats testing?
  2. How to use spring custom properties file during unit testing?
delete flag offensive retag edit

1 Reply

Sort by ยป oldest newest

answered 2020-04-16 14:58:42 +0800

cor3000 gravatar image cor3000
5173 2 7
ZK Team

1) there are multiple options using just spring configuration:

disable spring security conditionally when Zats classes are on the classpath (indicating a test run):

in this example the java config in WebSecurityConfig.java can be disabled just like this

 @Configuration
 @EnableWebSecurity
 @ConditionalOnMissingClass("org.zkoss.zats.mimic.Zats") //Disable security during Zats tests
 public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    ...    
    @Override
    protected void configure(HttpSecurity http) throws Exception {

use a spring profile to disable the config explicitely

 @Configuration
 @EnableWebSecurity
 @Profile("!test") //Disable security during test
 public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    ...    
    @Override
    protected void configure(HttpSecurity http) throws Exception {

There are multiple ways of activating a spring profile ... e.g. using a system variable

SPRING_PROFILES_ACTIVE=test mvn clean test

2) for your test properties

Another benefit of profiles in spring boot is the automatic loading based on the convention application-[profile].properties

so when activating the test profile you can add your overriding properties into an application-test.properties

3) what you didn't ask (maybe it's helpful)

It may also be possible to test your application using ZATS with security activated, as in this example test case: SecurePageTest.java - it performs a login, and follows redirects during a test.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2020-04-16 08:21:17 +0800

Seen: 6 times

Last updated: Apr 16

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More