Skip to content

Commit

Permalink
[CH] AuthChains now support method chain calls
Browse files Browse the repository at this point in the history
  • Loading branch information
CrAfTsArMy committed Dec 7, 2024
1 parent 446f60d commit ba5165a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,25 @@ public abstract class AuthChain {
* during future authentication attempts.
*
* @param adapter The {@link AuthAdapter} to be added to the authentication chain.
* @return The instance of {@link AuthChain} used for chain method calls.
*/
public abstract void append(AuthAdapter adapter);
public abstract AuthChain append(AuthAdapter adapter);

/**
* Removes a specific {@link AuthAdapter} from the authentication chain.
*
* @param adapter The {@link AuthAdapter} to be removed from the authentication chain.
* @return The instance of {@link AuthChain} used for chain method calls.
*/
public abstract void remove(AuthAdapter adapter);
public abstract AuthChain remove(AuthAdapter adapter);

/**
* Removes all {@link AuthAdapter} instances of the specified type from the authentication chain.
* This can be used to clear all adapters of a certain type (e.g., all token-based authenticators).
*
* @param adapter The class type of {@link AuthAdapter} to be removed.
* @return The instance of {@link AuthChain} used for chain method calls.
*/
public abstract void removeAll(Class<? extends AuthAdapter> adapter);
public abstract AuthChain removeAll(Class<? extends AuthAdapter> adapter);

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,52 +64,61 @@ public AuthResult authenticate(final Exchange exchange) {
* it will not be added again.
*
* @param adapter The {@link AuthAdapter} to be appended to the chain.
* @return The instance of {@link SimpleAuthChain} used for chain method calls.
*/
@Override
public void append(AuthAdapter adapter) {
if (!adapters.isEmpty() && adapters.contains(adapter)) return;
public SimpleAuthChain append(AuthAdapter adapter) {
if (!adapters.isEmpty() && adapters.contains(adapter)) return this;
adapters.add(adapter);
return this;
}

/**
* Removes a specific {@link AuthAdapter} from the chain.
*
* @param adapter The {@link AuthAdapter} to be removed from the chain.
* @return The instance of {@link SimpleAuthChain} used for chain method calls.
*/
@Override
public void remove(AuthAdapter adapter) {
public SimpleAuthChain remove(AuthAdapter adapter) {
adapters.remove(adapter);
return this;
}

/**
* Removes all instances of the specified {@link AuthAdapter} class from the chain.
*
* @param adapter The class type of the {@link AuthAdapter} to be removed.
* @return The instance of {@link SimpleAuthChain} used for chain method calls.
*/
@Override
public void removeAll(Class<? extends AuthAdapter> adapter) {
public SimpleAuthChain removeAll(Class<? extends AuthAdapter> adapter) {
adapters.stream()
.filter(adapter::isInstance)
.forEach(this::remove);
return this;
}

/**
* Adds a new url pattern to the exclusion list, preventing matching requests from undergoing authentication.
*
* @param pattern The exclusion pattern to add, typically a regex string matching URLs to exclude.
* @return The instance of {@link SimpleAuthChain} used for chain method calls.
*/
public void addExclusion(String pattern) {
public SimpleAuthChain addExclusion(String pattern) {
excluded.add(pattern);
return this;
}

/**
* Removes an url pattern from the exclusion list, allowing matching requests to undergo authentication again.
*
* @param pattern The exclusion pattern to remove.
* @return The instance of {@link SimpleAuthChain} used for chain method calls.
*/
public void removeExclusion(String pattern) {
public SimpleAuthChain removeExclusion(String pattern) {
excluded.remove(pattern);
return this;
}


}

0 comments on commit ba5165a

Please sign in to comment.