Skip to content

Commit

Permalink
Add configuration for not deployed profile
Browse files Browse the repository at this point in the history
Added changes to disable CSRF when app is not deployed
to make fab54d7 work.

JIRA: LIGHTY-213
Signed-off-by: tobias.pobocik <tobias.pobocik@pantheon.tech>
Signed-off-by: Ivan Hrasko <ivan.hrasko@pantheon.tech>
  • Loading branch information
Tobianas authored and ihrasko committed Apr 24, 2023
1 parent 728c93c commit 3a16951
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2021 PANTHEON.tech s.r.o. All Rights Reserved.
* Copyright (c) 2018 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,
Expand All @@ -12,6 +12,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;
Expand All @@ -21,13 +22,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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2023 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;

@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
.csrf()
.disable()
.addFilterBefore(new JCasBinFilter(enforcer, userAccessService), BasicAuthenticationFilter.class)
.securityMatcher("/services/data/**")
.build();
}
}

0 comments on commit 3a16951

Please sign in to comment.