remove security (#1765)

This commit is contained in:
lor6
2017-05-01 19:35:13 +03:00
committed by Grzegorz Piwowarek
parent 4aff9d33d9
commit 196b869fff
6 changed files with 24 additions and 85 deletions
@@ -1,7 +1,7 @@
package com.baeldung.toggle;
import org.togglz.core.Feature;
import org.togglz.core.activation.UserRoleActivationStrategy;
import org.togglz.core.activation.SystemPropertyActivationStrategy;
import org.togglz.core.annotation.ActivationParameter;
import org.togglz.core.annotation.DefaultActivationStrategy;
import org.togglz.core.annotation.EnabledByDefault;
@@ -10,14 +10,13 @@ import org.togglz.core.context.FeatureContext;
public enum MyFeatures implements Feature {
@Label("Administrator Feature")
@EnabledByDefault
@DefaultActivationStrategy(id = UserRoleActivationStrategy.ID, parameters = { @ActivationParameter(name = UserRoleActivationStrategy.PARAM_ROLES_NAME, value = "ROLE_ADMIN") })
ADMIN_FEATURE;
@Label("Employee Management Feature") @EnabledByDefault @DefaultActivationStrategy(id = SystemPropertyActivationStrategy.ID,
parameters = { @ActivationParameter(name = SystemPropertyActivationStrategy.PARAM_PROPERTY_NAME, value = "employee.feature"),
@ActivationParameter(name = SystemPropertyActivationStrategy.PARAM_PROPERTY_VALUE, value = "true") })
EMPLOYEE_MANAGEMENT_FEATURE;
public boolean isActive() {
return FeatureContext.getFeatureManager()
.isActive(this);
return FeatureContext.getFeatureManager().isActive(this);
}
}
@@ -9,7 +9,7 @@ public class SalaryService {
@Autowired
EmployeeRepository employeeRepository;
@FeatureAssociation(value = MyFeatures.ADMIN_FEATURE)
@FeatureAssociation(value = MyFeatures.EMPLOYEE_MANAGEMENT_FEATURE)
public void increaseSalary(long id) {
Employee employee = employeeRepository.findOne(id);
employee.setSalary(employee.getSalary() + employee.getSalary() * 0.1);
@@ -1,33 +0,0 @@
package com.baeldung.toggle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
//@formatter:off
auth.inMemoryAuthentication()
.withUser("user").password("pass").roles("USER")
.and()
.withUser("admin").password("pass").roles("ADMIN");
//@formatter:on
}
@Override
public void configure(HttpSecurity http) throws Exception {
//@formatter:off
http.authorizeRequests().antMatchers("/increaseSalary").permitAll()
.and()
.csrf().disable()
.httpBasic();
//@formatter:on
}
}
@@ -2,14 +2,10 @@ package com.baeldung.toggle;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.togglz.core.manager.EnumBasedFeatureProvider;
import org.togglz.core.spi.FeatureProvider;
import org.togglz.core.user.UserProvider;
import org.togglz.spring.security.SpringSecurityUserProvider;
@Configuration
@EnableJpaRepositories("com.baeldung.toggle")
@@ -21,8 +17,4 @@ public class ToggleConfiguration {
return new EnumBasedFeatureProvider(MyFeatures.class);
}
@Bean
public UserProvider userProvider() {
return new SpringSecurityUserProvider("admin");
}
}