formatting work

This commit is contained in:
eugenp
2017-01-29 16:06:01 +02:00
parent 034cde6e20
commit 966e53a85b
58 changed files with 932 additions and 1046 deletions
@@ -9,8 +9,7 @@ import org.springframework.context.annotation.FilterType;
@Configuration
@EnableAutoConfiguration
@ComponentScan(excludeFilters =
@ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.baeldung.voter.*"))
@ComponentScan(excludeFilters = @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.baeldung.voter.*"))
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
@@ -7,7 +7,7 @@ import org.springframework.transaction.annotation.Transactional;
public interface UserRepository extends JpaRepository<User, Long> {
User findByUsername(final String username);
@Transactional
void removeUserByUsername(String username);
@@ -15,7 +15,7 @@ import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name="user_table")
@Table(name = "user_table")
public class User {
@Id
@@ -21,13 +21,6 @@ public class MinuteBasedVoter implements AccessDecisionVoter {
@Override
public int vote(Authentication authentication, Object object, Collection collection) {
return authentication
.getAuthorities()
.stream()
.map(GrantedAuthority::getAuthority)
.filter(r -> "ROLE_USER".equals(r) && LocalDateTime.now().getMinute() % 2 != 0)
.findAny()
.map(s -> ACCESS_DENIED)
.orElseGet(() -> ACCESS_ABSTAIN);
return authentication.getAuthorities().stream().map(GrantedAuthority::getAuthority).filter(r -> "ROLE_USER".equals(r) && LocalDateTime.now().getMinute() % 2 != 0).findAny().map(s -> ACCESS_DENIED).orElseGet(() -> ACCESS_ABSTAIN);
}
}
@@ -8,7 +8,7 @@ import org.springframework.context.annotation.FilterType;
@Configuration
@EnableAutoConfiguration
@ComponentScan(basePackages = {"org.baeldung.voter"})
@ComponentScan(basePackages = { "org.baeldung.voter" })
public class VoterApplication {
public static void main(String[] args) {
@@ -24,10 +24,7 @@ public class WebSecurityConfig 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");
auth.inMemoryAuthentication().withUser("user").password("pass").roles("USER").and().withUser("admin").password("pass").roles("ADMIN");
// @formatter: on
}
@@ -36,33 +33,15 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
// @formatter: off
http
// needed so our login could work
.csrf()
.disable()
.authorizeRequests()
.anyRequest()
.authenticated()
.accessDecisionManager(accessDecisionManager())
.antMatchers("/").hasAnyRole("ROLE_ADMIN", "ROLE_USER")
.and()
.formLogin()
.permitAll()
.and()
.logout()
.permitAll()
.deleteCookies("JSESSIONID")
.logoutSuccessUrl("/login");
.csrf().disable().authorizeRequests().anyRequest().authenticated().accessDecisionManager(accessDecisionManager()).antMatchers("/").hasAnyRole("ROLE_ADMIN", "ROLE_USER").and().formLogin().permitAll().and().logout().permitAll()
.deleteCookies("JSESSIONID").logoutSuccessUrl("/login");
// @formatter: on
}
@Bean
public AccessDecisionManager accessDecisionManager() {
// @formatter: off
List<AccessDecisionVoter<? extends Object>> decisionVoters =
Arrays.asList(
new WebExpressionVoter(),
new RoleVoter(),
new AuthenticatedVoter(),
new MinuteBasedVoter());
List<AccessDecisionVoter<? extends Object>> decisionVoters = Arrays.asList(new WebExpressionVoter(), new RoleVoter(), new AuthenticatedVoter(), new MinuteBasedVoter());
// @formatter: on
return new UnanimousBased(decisionVoters);
}
@@ -7,7 +7,7 @@ import org.springframework.context.annotation.ImportResource;
* Created by ambrusadrianz on 09/10/2016.
*/
@Configuration
@ImportResource({"classpath:spring-security.xml"})
@ImportResource({ "classpath:spring-security.xml" })
public class XmlSecurityConfig {
public XmlSecurityConfig() {
super();