diff --git a/lighty-examples/lighty-controller-springboot-netconf/src/main/java/io/lighty/core/controller/springboot/config/SecurityConfiguration.java b/lighty-examples/lighty-controller-springboot-netconf/src/main/java/io/lighty/core/controller/springboot/config/SecurityConfigurationDeployed.java similarity index 89% rename from lighty-examples/lighty-controller-springboot-netconf/src/main/java/io/lighty/core/controller/springboot/config/SecurityConfiguration.java rename to lighty-examples/lighty-controller-springboot-netconf/src/main/java/io/lighty/core/controller/springboot/config/SecurityConfigurationDeployed.java index 9e5ab67f62..ce0aae7fa3 100644 --- a/lighty-examples/lighty-controller-springboot-netconf/src/main/java/io/lighty/core/controller/springboot/config/SecurityConfiguration.java +++ b/lighty-examples/lighty-controller-springboot-netconf/src/main/java/io/lighty/core/controller/springboot/config/SecurityConfigurationDeployed.java @@ -5,6 +5,7 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at https://www.eclipse.org/legal/epl-v10.html */ + package io.lighty.core.controller.springboot.config; import io.lighty.core.controller.springboot.services.UserAccessService; @@ -12,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; import org.springframework.core.annotation.Order; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; @@ -21,13 +23,14 @@ @EnableWebSecurity @Configuration -public class SecurityConfiguration { +@Profile("deployed") +public class SecurityConfigurationDeployed { private final Enforcer enforcer; private final UserAccessService userAccessService; @Autowired - public SecurityConfiguration(Enforcer enforcer, UserAccessService userAccessService) { + public SecurityConfigurationDeployed(Enforcer enforcer, UserAccessService userAccessService) { this.enforcer = enforcer; this.userAccessService = userAccessService; } @@ -43,4 +46,5 @@ protected SecurityFilterChain auth0FilterChain(HttpSecurity httpSecurity) throws .securityMatcher("/services/data/**") .build(); } + } diff --git a/lighty-examples/lighty-controller-springboot-netconf/src/main/java/io/lighty/core/controller/springboot/config/SecurityConfigurationNotDeployed.java b/lighty-examples/lighty-controller-springboot-netconf/src/main/java/io/lighty/core/controller/springboot/config/SecurityConfigurationNotDeployed.java new file mode 100644 index 0000000000..1c33caccf6 --- /dev/null +++ b/lighty-examples/lighty-controller-springboot-netconf/src/main/java/io/lighty/core/controller/springboot/config/SecurityConfigurationNotDeployed.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2018-2021 PANTHEON.tech s.r.o. All Rights Reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at https://www.eclipse.org/legal/epl-v10.html + */ +package io.lighty.core.controller.springboot.config; + +import io.lighty.core.controller.springboot.services.UserAccessService; +import org.casbin.jcasbin.main.Enforcer; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.core.annotation.Order; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.web.SecurityFilterChain; +import org.springframework.security.web.authentication.www.BasicAuthenticationFilter; +import org.springframework.security.web.csrf.CookieCsrfTokenRepository; + +@EnableWebSecurity +@Configuration +@Profile("!deployed") //Not(!) deployed profile +public class SecurityConfigurationNotDeployed { + + private final Enforcer enforcer; + private final UserAccessService userAccessService; + + @Autowired + public SecurityConfigurationNotDeployed(Enforcer enforcer, UserAccessService userAccessService) { + this.enforcer = enforcer; + this.userAccessService = userAccessService; + } + + @Bean + @Order(1) + protected SecurityFilterChain auth0FilterChain(HttpSecurity httpSecurity) throws Exception { + return httpSecurity + .addFilterBefore(new JCasBinFilter(enforcer, userAccessService), BasicAuthenticationFilter.class) + .securityMatcher("/services/data/**") + .csrf() + .disable() + .build(); + } +}