BAEL-1524: Chain of Responsibility Design Pattern in Java (#3780)
* BAEL-1422: measure performance of Random and ThreadLocalRandom using JMH * BAEL-1422: updated benchmarking examples of Random and ThreadLocalRandom to use newWorkStealingPool that leverages ForkJoinPool * BAEL-1422: refactored benchmarking examples for comparing performance of ThreadLocalRandom and Random - initialised the collection of Callable before running benchmarking - removed for loop for submitting task and instead used executor.invokeAll(collection_of_callable) * BAEL-1282: added TDD type junit tests for geospatial queries elasticsearch * BAEL-1524: added example for chain of responsibility design pattern * BAEL-1524: added BDD style jUnit test to test unknown handler in ChainOfResponsibility design pattern * BAEL-1524: refactored ChainOfResponsibility design pattern example * BAEL-1524: refactored ChainOfResponsibility design pattern example * BAEL-1524: updated ChainOfResponsibility design pattern example * BAEL-1524: updated ChainOfResponsibility design pattern example * BAEL-1524: moved chain of responsibility example from core-java module to patterns module
This commit is contained in:
committed by
Josh Cummings
parent
67092ccc49
commit
00c022388f
-13
@@ -1,13 +0,0 @@
|
||||
package com.baeldung.designpatterns.chainofresponsibility;
|
||||
|
||||
public abstract class AuthenticationProcessor {
|
||||
|
||||
// next element in chain or responsibility
|
||||
public AuthenticationProcessor nextProcessor;
|
||||
|
||||
public AuthenticationProcessor(AuthenticationProcessor nextProcessor) {
|
||||
this.nextProcessor = nextProcessor;
|
||||
}
|
||||
|
||||
public abstract boolean isAuthorized(AuthenticationProvider authProvider);
|
||||
}
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
package com.baeldung.designpatterns.chainofresponsibility;
|
||||
|
||||
public interface AuthenticationProvider {
|
||||
|
||||
}
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
package com.baeldung.designpatterns.chainofresponsibility;
|
||||
|
||||
public class OAuthAuthenticationProcessor extends AuthenticationProcessor {
|
||||
|
||||
public OAuthAuthenticationProcessor(AuthenticationProcessor nextProcessor) {
|
||||
super(nextProcessor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAuthorized(AuthenticationProvider authProvider) {
|
||||
|
||||
if (authProvider instanceof OAuthTokenProvider) {
|
||||
return Boolean.TRUE;
|
||||
} else if (nextProcessor != null) {
|
||||
return nextProcessor.isAuthorized(authProvider);
|
||||
} else {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
package com.baeldung.designpatterns.chainofresponsibility;
|
||||
|
||||
public class OAuthTokenProvider implements AuthenticationProvider {
|
||||
|
||||
}
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
package com.baeldung.designpatterns.chainofresponsibility;
|
||||
|
||||
public class SamlAuthenticationProvider implements AuthenticationProvider {
|
||||
|
||||
}
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
package com.baeldung.designpatterns.chainofresponsibility;
|
||||
|
||||
public class UsernamePasswordAuthenticationProcessor extends AuthenticationProcessor {
|
||||
|
||||
public UsernamePasswordAuthenticationProcessor(AuthenticationProcessor nextProcessor) {
|
||||
super(nextProcessor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAuthorized(AuthenticationProvider authProvider) {
|
||||
if (authProvider instanceof UsernamePasswordProvider) {
|
||||
return Boolean.TRUE;
|
||||
} else if (nextProcessor != null) {
|
||||
return nextProcessor.isAuthorized(authProvider);
|
||||
} else {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
package com.baeldung.designpatterns.chainofresponsibility;
|
||||
|
||||
public class UsernamePasswordProvider implements AuthenticationProvider {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user