minor formatting work
This commit is contained in:
parent
67fcde1009
commit
29c0fd8371
|
@ -7,15 +7,15 @@ import java.util.UUID;
|
||||||
|
|
||||||
public class TransactionFactory {
|
public class TransactionFactory {
|
||||||
|
|
||||||
private static final String[] NAMES = {"John", "Susan", "Marc", "Samantha"};
|
private static final String[] NAMES = { "John", "Susan", "Marc", "Samantha" };
|
||||||
private static long nextId = 1;
|
private static long nextId = 1;
|
||||||
|
|
||||||
public Transfer newInstance() {
|
public Transfer newInstance() {
|
||||||
String transactionId = String.valueOf( nextId++ );
|
String transactionId = String.valueOf(nextId++);
|
||||||
String owner = NAMES[ (int) floor(random()*NAMES.length) ];
|
String owner = NAMES[(int) floor(random() * NAMES.length)];
|
||||||
long amount = (long) (random()*1500 + 500);
|
long amount = (long) (random() * 1500 + 500);
|
||||||
Transfer tx = new Transfer(transactionId, owner, amount);
|
Transfer tx = new Transfer(transactionId, owner, amount);
|
||||||
return tx;
|
return tx;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,8 @@ public class TransferDemo {
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
Transfer tx = transactionFactory.newInstance();
|
Transfer tx = transactionFactory.newInstance();
|
||||||
|
|
||||||
//Runnable task = new Log4JRunnable(tx);
|
// Runnable task = new Log4JRunnable(tx);
|
||||||
//Runnable task = new Log4J2Runnable(tx);
|
// Runnable task = new Log4J2Runnable(tx);
|
||||||
Runnable task = new Slf4jRunnable(tx);
|
Runnable task = new Slf4jRunnable(tx);
|
||||||
|
|
||||||
executor.submit(task);
|
executor.submit(task);
|
||||||
|
|
|
@ -13,7 +13,6 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
import com.baeldung.ndc.Investment;
|
import com.baeldung.ndc.Investment;
|
||||||
import com.baeldung.ndc.service.InvestmentService;
|
import com.baeldung.ndc.service.InvestmentService;
|
||||||
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class JBossLoggingController {
|
public class JBossLoggingController {
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
|
@ -18,154 +18,113 @@ public class RxJavaBackpressureTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenColdObservable_shouldNotThrowException() {
|
public void givenColdObservable_shouldNotThrowException() {
|
||||||
//given
|
// given
|
||||||
TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
|
TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
|
||||||
|
|
||||||
//when
|
// when
|
||||||
Observable
|
Observable.range(1, 1_000_000).observeOn(Schedulers.computation()).subscribe(testSubscriber);
|
||||||
.range(1, 1_000_000)
|
|
||||||
.observeOn(Schedulers.computation())
|
|
||||||
.subscribe(testSubscriber);
|
|
||||||
|
|
||||||
//then
|
// then
|
||||||
testSubscriber.awaitTerminalEvent();
|
testSubscriber.awaitTerminalEvent();
|
||||||
assertTrue(testSubscriber
|
assertTrue(testSubscriber.getOnErrorEvents().size() == 0);
|
||||||
.getOnErrorEvents()
|
|
||||||
.size() == 0);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenHotObservable_whenBackpressureNotDefined_shouldTrowException() {
|
public void givenHotObservable_whenBackpressureNotDefined_shouldTrowException() {
|
||||||
//given
|
// given
|
||||||
TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
|
TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
|
||||||
PublishSubject<Integer> source = PublishSubject.<Integer> create();
|
PublishSubject<Integer> source = PublishSubject.<Integer> create();
|
||||||
|
|
||||||
source
|
source.observeOn(Schedulers.computation()).subscribe(testSubscriber);
|
||||||
.observeOn(Schedulers.computation())
|
|
||||||
.subscribe(testSubscriber);
|
|
||||||
|
|
||||||
//when
|
// when
|
||||||
IntStream
|
IntStream.range(0, 1_000_000).forEach(source::onNext);
|
||||||
.range(0, 1_000_000)
|
|
||||||
.forEach(source::onNext);
|
|
||||||
|
|
||||||
//then
|
// then
|
||||||
testSubscriber.awaitTerminalEvent();
|
testSubscriber.awaitTerminalEvent();
|
||||||
testSubscriber.assertError(MissingBackpressureException.class);
|
testSubscriber.assertError(MissingBackpressureException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenHotObservable_whenWindowIsDefined_shouldNotThrowException() {
|
public void givenHotObservable_whenWindowIsDefined_shouldNotThrowException() {
|
||||||
//given
|
// given
|
||||||
TestSubscriber<Observable<Integer>> testSubscriber = new TestSubscriber<>();
|
TestSubscriber<Observable<Integer>> testSubscriber = new TestSubscriber<>();
|
||||||
PublishSubject<Integer> source = PublishSubject.<Integer> create();
|
PublishSubject<Integer> source = PublishSubject.<Integer> create();
|
||||||
|
|
||||||
//when
|
// when
|
||||||
source
|
source.window(500).observeOn(Schedulers.computation()).subscribe(testSubscriber);
|
||||||
.window(500)
|
|
||||||
.observeOn(Schedulers.computation())
|
|
||||||
.subscribe(testSubscriber);
|
|
||||||
|
|
||||||
IntStream
|
IntStream.range(0, 1_000).forEach(source::onNext);
|
||||||
.range(0, 1_000)
|
|
||||||
.forEach(source::onNext);
|
|
||||||
|
|
||||||
//then
|
// then
|
||||||
testSubscriber.awaitTerminalEvent(2, TimeUnit.SECONDS);
|
testSubscriber.awaitTerminalEvent(2, TimeUnit.SECONDS);
|
||||||
assertTrue(testSubscriber
|
assertTrue(testSubscriber.getOnErrorEvents().size() == 0);
|
||||||
.getOnErrorEvents()
|
|
||||||
.size() == 0);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenHotObservable_whenBufferIsDefined_shouldNotThrowException() {
|
public void givenHotObservable_whenBufferIsDefined_shouldNotThrowException() {
|
||||||
//given
|
// given
|
||||||
TestSubscriber<List<Integer>> testSubscriber = new TestSubscriber<>();
|
TestSubscriber<List<Integer>> testSubscriber = new TestSubscriber<>();
|
||||||
PublishSubject<Integer> source = PublishSubject.<Integer> create();
|
PublishSubject<Integer> source = PublishSubject.<Integer> create();
|
||||||
|
|
||||||
//when
|
// when
|
||||||
source
|
source.buffer(1024).observeOn(Schedulers.computation()).subscribe(testSubscriber);
|
||||||
.buffer(1024)
|
|
||||||
.observeOn(Schedulers.computation())
|
|
||||||
.subscribe(testSubscriber);
|
|
||||||
|
|
||||||
IntStream
|
IntStream.range(0, 1_000).forEach(source::onNext);
|
||||||
.range(0, 1_000)
|
|
||||||
.forEach(source::onNext);
|
|
||||||
|
|
||||||
|
// then
|
||||||
//then
|
|
||||||
testSubscriber.awaitTerminalEvent(2, TimeUnit.SECONDS);
|
testSubscriber.awaitTerminalEvent(2, TimeUnit.SECONDS);
|
||||||
assertTrue(testSubscriber
|
assertTrue(testSubscriber.getOnErrorEvents().size() == 0);
|
||||||
.getOnErrorEvents()
|
|
||||||
.size() == 0);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenHotObservable_whenSkippingOperationIsDefined_shouldNotThrowException() {
|
public void givenHotObservable_whenSkippingOperationIsDefined_shouldNotThrowException() {
|
||||||
//given
|
// given
|
||||||
TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
|
TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
|
||||||
PublishSubject<Integer> source = PublishSubject.<Integer> create();
|
PublishSubject<Integer> source = PublishSubject.<Integer> create();
|
||||||
|
|
||||||
//when
|
// when
|
||||||
source.sample(100, TimeUnit.MILLISECONDS)
|
source.sample(100, TimeUnit.MILLISECONDS)
|
||||||
// .throttleFirst(100, TimeUnit.MILLISECONDS)
|
// .throttleFirst(100, TimeUnit.MILLISECONDS)
|
||||||
.observeOn(Schedulers.computation())
|
.observeOn(Schedulers.computation()).subscribe(testSubscriber);
|
||||||
.subscribe(testSubscriber);
|
|
||||||
|
|
||||||
IntStream
|
IntStream.range(0, 1_000).forEach(source::onNext);
|
||||||
.range(0, 1_000)
|
|
||||||
.forEach(source::onNext);
|
|
||||||
|
|
||||||
|
// then
|
||||||
//then
|
|
||||||
testSubscriber.awaitTerminalEvent(2, TimeUnit.SECONDS);
|
testSubscriber.awaitTerminalEvent(2, TimeUnit.SECONDS);
|
||||||
assertTrue(testSubscriber
|
assertTrue(testSubscriber.getOnErrorEvents().size() == 0);
|
||||||
.getOnErrorEvents()
|
|
||||||
.size() == 0);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenHotObservable_whenOnBackpressureBufferDefined_shouldNotThrowException() {
|
public void givenHotObservable_whenOnBackpressureBufferDefined_shouldNotThrowException() {
|
||||||
//given
|
// given
|
||||||
TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
|
TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
|
||||||
|
|
||||||
//when
|
// when
|
||||||
Observable
|
Observable.range(1, 1_000_000).onBackpressureBuffer(16, () -> {
|
||||||
.range(1, 1_000_000)
|
}, BackpressureOverflow.ON_OVERFLOW_DROP_OLDEST).observeOn(Schedulers.computation()).subscribe(testSubscriber);
|
||||||
.onBackpressureBuffer(16, () -> {}, BackpressureOverflow.ON_OVERFLOW_DROP_OLDEST)
|
|
||||||
.observeOn(Schedulers.computation())
|
|
||||||
.subscribe(testSubscriber);
|
|
||||||
|
|
||||||
//then
|
// then
|
||||||
testSubscriber.awaitTerminalEvent(2, TimeUnit.SECONDS);
|
testSubscriber.awaitTerminalEvent(2, TimeUnit.SECONDS);
|
||||||
assertTrue(testSubscriber
|
assertTrue(testSubscriber.getOnErrorEvents().size() == 0);
|
||||||
.getOnErrorEvents()
|
|
||||||
.size() == 0);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenHotObservable_whenOnBackpressureDropDefined_shouldNotThrowException() {
|
public void givenHotObservable_whenOnBackpressureDropDefined_shouldNotThrowException() {
|
||||||
//given
|
// given
|
||||||
TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
|
TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
|
||||||
|
|
||||||
//when
|
// when
|
||||||
Observable
|
Observable.range(1, 1_000_000).onBackpressureDrop().observeOn(Schedulers.computation()).subscribe(testSubscriber);
|
||||||
.range(1, 1_000_000)
|
|
||||||
.onBackpressureDrop()
|
|
||||||
.observeOn(Schedulers.computation())
|
|
||||||
.subscribe(testSubscriber);
|
|
||||||
|
|
||||||
//then
|
// then
|
||||||
testSubscriber.awaitTerminalEvent(2, TimeUnit.SECONDS);
|
testSubscriber.awaitTerminalEvent(2, TimeUnit.SECONDS);
|
||||||
assertTrue(testSubscriber
|
assertTrue(testSubscriber.getOnErrorEvents().size() == 0);
|
||||||
.getOnErrorEvents()
|
|
||||||
.size() == 0);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,22 +13,18 @@ import java.util.concurrent.TimeUnit;
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
|
||||||
public class RxJavaTesting {
|
public class RxJavaTesting {
|
||||||
@Test
|
@Test
|
||||||
public void givenObservable_whenZip_shouldAssertBlockingInASameThread() {
|
public void givenObservable_whenZip_shouldAssertBlockingInASameThread() {
|
||||||
//given
|
// given
|
||||||
List<String> letters = Arrays.asList("A", "B", "C", "D", "E");
|
List<String> letters = Arrays.asList("A", "B", "C", "D", "E");
|
||||||
List<String> results = new ArrayList<>();
|
List<String> results = new ArrayList<>();
|
||||||
Observable<String> observable = Observable
|
Observable<String> observable = Observable.from(letters).zipWith(Observable.range(1, Integer.MAX_VALUE), (string, index) -> index + "-" + string);
|
||||||
.from(letters)
|
|
||||||
.zipWith(Observable.range(1, Integer.MAX_VALUE),
|
|
||||||
(string, index) -> index + "-" + string);
|
|
||||||
|
|
||||||
//when
|
// when
|
||||||
observable.subscribe(results::add);
|
observable.subscribe(results::add);
|
||||||
|
|
||||||
//then
|
// then
|
||||||
assertThat(results, notNullValue());
|
assertThat(results, notNullValue());
|
||||||
assertThat(results, hasSize(5));
|
assertThat(results, hasSize(5));
|
||||||
assertThat(results, hasItems("1-A", "2-B", "3-C", "4-D", "5-E"));
|
assertThat(results, hasItems("1-A", "2-B", "3-C", "4-D", "5-E"));
|
||||||
|
@ -36,19 +32,16 @@ public class RxJavaTesting {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenObservable_whenZip_shouldAssertOnTestSubscriber() {
|
public void givenObservable_whenZip_shouldAssertOnTestSubscriber() {
|
||||||
//given
|
// given
|
||||||
List<String> letters = Arrays.asList("A", "B", "C", "D", "E");
|
List<String> letters = Arrays.asList("A", "B", "C", "D", "E");
|
||||||
TestSubscriber<String> subscriber = new TestSubscriber<>();
|
TestSubscriber<String> subscriber = new TestSubscriber<>();
|
||||||
|
|
||||||
Observable<String> observable = Observable
|
Observable<String> observable = Observable.from(letters).zipWith(Observable.range(1, Integer.MAX_VALUE), ((string, index) -> index + "-" + string));
|
||||||
.from(letters)
|
|
||||||
.zipWith(Observable.range(1, Integer.MAX_VALUE),
|
|
||||||
((string, index) -> index + "-" + string));
|
|
||||||
|
|
||||||
//when
|
// when
|
||||||
observable.subscribe(subscriber);
|
observable.subscribe(subscriber);
|
||||||
|
|
||||||
//then
|
// then
|
||||||
subscriber.assertCompleted();
|
subscriber.assertCompleted();
|
||||||
subscriber.assertNoErrors();
|
subscriber.assertNoErrors();
|
||||||
subscriber.assertValueCount(5);
|
subscriber.assertValueCount(5);
|
||||||
|
@ -57,52 +50,45 @@ public class RxJavaTesting {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenTestObserver_whenExceptionWasThrowsOnObservable_observerShouldGetError() {
|
public void givenTestObserver_whenExceptionWasThrowsOnObservable_observerShouldGetError() {
|
||||||
//given
|
// given
|
||||||
List<String> letters = Arrays.asList("A", "B", "C", "D", "E");
|
List<String> letters = Arrays.asList("A", "B", "C", "D", "E");
|
||||||
TestSubscriber<String> subscriber = new TestSubscriber<>();
|
TestSubscriber<String> subscriber = new TestSubscriber<>();
|
||||||
|
|
||||||
|
Observable<String> observable = Observable.from(letters).zipWith(Observable.range(1, Integer.MAX_VALUE), ((string, index) -> index + "-" + string)).concatWith(Observable.error(new RuntimeException("error in Observable")));
|
||||||
|
|
||||||
Observable<String> observable = Observable
|
// when
|
||||||
.from(letters)
|
|
||||||
.zipWith(Observable.range(1, Integer.MAX_VALUE),
|
|
||||||
((string, index) -> index + "-" + string))
|
|
||||||
.concatWith(Observable.error(new RuntimeException("error in Observable")));
|
|
||||||
|
|
||||||
//when
|
|
||||||
observable.subscribe(subscriber);
|
observable.subscribe(subscriber);
|
||||||
|
|
||||||
//then
|
// then
|
||||||
subscriber.assertError(RuntimeException.class);
|
subscriber.assertError(RuntimeException.class);
|
||||||
subscriber.assertNotCompleted();
|
subscriber.assertNotCompleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenObservableThatEmitsEventPerSecond_whenUseAdvanceByTime_shouldEmitEventPerSecond() {
|
public void givenObservableThatEmitsEventPerSecond_whenUseAdvanceByTime_shouldEmitEventPerSecond() {
|
||||||
//given
|
// given
|
||||||
List<String> letters = Arrays.asList("A", "B", "C", "D", "E");
|
List<String> letters = Arrays.asList("A", "B", "C", "D", "E");
|
||||||
TestScheduler scheduler = new TestScheduler();
|
TestScheduler scheduler = new TestScheduler();
|
||||||
TestSubscriber<String> subscriber = new TestSubscriber<>();
|
TestSubscriber<String> subscriber = new TestSubscriber<>();
|
||||||
Observable<Long> tick = Observable.interval(1, TimeUnit.SECONDS, scheduler);
|
Observable<Long> tick = Observable.interval(1, TimeUnit.SECONDS, scheduler);
|
||||||
|
|
||||||
Observable<String> observable = Observable.from(letters)
|
Observable<String> observable = Observable.from(letters).zipWith(tick, (string, index) -> index + "-" + string);
|
||||||
.zipWith(tick, (string, index) -> index + "-" + string);
|
|
||||||
|
|
||||||
observable.subscribeOn(scheduler)
|
observable.subscribeOn(scheduler).subscribe(subscriber);
|
||||||
.subscribe(subscriber);
|
|
||||||
|
|
||||||
//expect
|
// expect
|
||||||
subscriber.assertNoValues();
|
subscriber.assertNoValues();
|
||||||
subscriber.assertNotCompleted();
|
subscriber.assertNotCompleted();
|
||||||
|
|
||||||
//when
|
// when
|
||||||
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
|
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
|
||||||
|
|
||||||
//then
|
// then
|
||||||
subscriber.assertNoErrors();
|
subscriber.assertNoErrors();
|
||||||
subscriber.assertValueCount(1);
|
subscriber.assertValueCount(1);
|
||||||
subscriber.assertValues("0-A");
|
subscriber.assertValues("0-A");
|
||||||
|
|
||||||
//when
|
// when
|
||||||
scheduler.advanceTimeTo(6, TimeUnit.SECONDS);
|
scheduler.advanceTimeTo(6, TimeUnit.SECONDS);
|
||||||
subscriber.assertCompleted();
|
subscriber.assertCompleted();
|
||||||
subscriber.assertNoErrors();
|
subscriber.assertNoErrors();
|
||||||
|
@ -110,4 +96,3 @@ public class RxJavaTesting {
|
||||||
assertThat(subscriber.getOnNextEvents(), hasItems("0-A", "1-B", "2-C", "3-D", "4-E"));
|
assertThat(subscriber.getOnNextEvents(), hasItems("0-A", "1-B", "2-C", "3-D", "4-E"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import org.springframework.context.annotation.FilterType;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
@ComponentScan(excludeFilters = {@ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.baeldung.voter.*"), @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.baeldung.multiplelogin.*")})
|
@ComponentScan(excludeFilters = { @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.baeldung.voter.*"), @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.baeldung.multiplelogin.*") })
|
||||||
public class Application extends SpringBootServletInitializer {
|
public class Application extends SpringBootServletInitializer {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(Application.class, args);
|
SpringApplication.run(Application.class, args);
|
||||||
|
|
|
@ -15,8 +15,8 @@ public class MultipleLoginApplication extends SpringBootServletInitializer {
|
||||||
SpringApplication.run(MultipleLoginApplication.class, args);
|
SpringApplication.run(MultipleLoginApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||||
return application.sources(MultipleLoginApplication.class);
|
return application.sources(MultipleLoginApplication.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -21,14 +21,8 @@ public class MultipleLoginSecurityConfig {
|
||||||
@Bean
|
@Bean
|
||||||
public UserDetailsService userDetailsService() throws Exception {
|
public UserDetailsService userDetailsService() throws Exception {
|
||||||
InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
|
InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
|
||||||
manager.createUser(User.withUsername("user")
|
manager.createUser(User.withUsername("user").password("userPass").roles("USER").build());
|
||||||
.password("userPass")
|
manager.createUser(User.withUsername("admin").password("adminPass").roles("ADMIN").build());
|
||||||
.roles("USER")
|
|
||||||
.build());
|
|
||||||
manager.createUser(User.withUsername("admin")
|
|
||||||
.password("adminPass")
|
|
||||||
.roles("ADMIN")
|
|
||||||
.build());
|
|
||||||
return manager;
|
return manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,37 +36,16 @@ public class MultipleLoginSecurityConfig {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||||
auth.inMemoryAuthentication()
|
auth.inMemoryAuthentication().withUser("admin").password("admin").roles("ADMIN");
|
||||||
.withUser("admin")
|
|
||||||
.password("admin")
|
|
||||||
.roles("ADMIN");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
protected void configure(HttpSecurity http) throws Exception {
|
||||||
http.antMatcher("/admin*")
|
http.antMatcher("/admin*").authorizeRequests().anyRequest().hasRole("ADMIN")
|
||||||
.authorizeRequests()
|
// log in
|
||||||
.anyRequest()
|
.and().formLogin().loginPage("/loginAdmin").loginProcessingUrl("/admin_login").failureUrl("/loginAdmin?error=loginError").defaultSuccessUrl("/adminPage")
|
||||||
.hasRole("ADMIN")
|
// logout
|
||||||
// log in
|
.and().logout().logoutUrl("/admin_logout").logoutSuccessUrl("/protectedLinks").deleteCookies("JSESSIONID").and().exceptionHandling().accessDeniedPage("/403").and().csrf().disable();
|
||||||
.and()
|
|
||||||
.formLogin()
|
|
||||||
.loginPage("/loginAdmin")
|
|
||||||
.loginProcessingUrl("/admin_login")
|
|
||||||
.failureUrl("/loginAdmin?error=loginError")
|
|
||||||
.defaultSuccessUrl("/adminPage")
|
|
||||||
// logout
|
|
||||||
.and()
|
|
||||||
.logout()
|
|
||||||
.logoutUrl("/admin_logout")
|
|
||||||
.logoutSuccessUrl("/protectedLinks")
|
|
||||||
.deleteCookies("JSESSIONID")
|
|
||||||
.and()
|
|
||||||
.exceptionHandling()
|
|
||||||
.accessDeniedPage("/403")
|
|
||||||
.and()
|
|
||||||
.csrf()
|
|
||||||
.disable();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,36 +59,15 @@ public class MultipleLoginSecurityConfig {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||||
auth.inMemoryAuthentication()
|
auth.inMemoryAuthentication().withUser("user").password("user").roles("USER");
|
||||||
.withUser("user")
|
|
||||||
.password("user")
|
|
||||||
.roles("USER");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
protected void configure(HttpSecurity http) throws Exception {
|
||||||
http.antMatcher("/user*")
|
http.antMatcher("/user*").authorizeRequests().anyRequest().hasRole("USER")
|
||||||
.authorizeRequests()
|
// log in
|
||||||
.anyRequest()
|
.and().formLogin().loginPage("/loginUser").loginProcessingUrl("/user_login").failureUrl("/loginUser?error=loginError").defaultSuccessUrl("/userPage")
|
||||||
.hasRole("USER")
|
// logout
|
||||||
// log in
|
.and().logout().logoutUrl("/user_logout").logoutSuccessUrl("/protectedLinks").deleteCookies("JSESSIONID").and().exceptionHandling().accessDeniedPage("/403").and().csrf().disable();
|
||||||
.and()
|
|
||||||
.formLogin()
|
|
||||||
.loginPage("/loginUser")
|
|
||||||
.loginProcessingUrl("/user_login")
|
|
||||||
.failureUrl("/loginUser?error=loginError")
|
|
||||||
.defaultSuccessUrl("/userPage")
|
|
||||||
// logout
|
|
||||||
.and()
|
|
||||||
.logout()
|
|
||||||
.logoutUrl("/user_logout")
|
|
||||||
.logoutSuccessUrl("/protectedLinks")
|
|
||||||
.deleteCookies("JSESSIONID")
|
|
||||||
.and()
|
|
||||||
.exceptionHandling()
|
|
||||||
.accessDeniedPage("/403")
|
|
||||||
.and()
|
|
||||||
.csrf()
|
|
||||||
.disable();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@ import org.springframework.context.annotation.ImportResource;
|
||||||
/**
|
/**
|
||||||
* Created by ambrusadrianz on 09/10/2016.
|
* Created by ambrusadrianz on 09/10/2016.
|
||||||
*/
|
*/
|
||||||
//@Configuration
|
// @Configuration
|
||||||
//@ImportResource({ "classpath:spring-security-custom-voter.xml" })
|
// @ImportResource({ "classpath:spring-security-custom-voter.xml" })
|
||||||
public class XmlSecurityConfig {
|
public class XmlSecurityConfig {
|
||||||
public XmlSecurityConfig() {
|
public XmlSecurityConfig() {
|
||||||
super();
|
super();
|
||||||
|
|
Loading…
Reference in New Issue