Skip to content

Commit 6c1b7c2

Browse files
committed
Implement de-authentication test
Fixes #59
1 parent b7037db commit 6c1b7c2

File tree

9 files changed

+850
-24
lines changed

9 files changed

+850
-24
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.2.1
2+
* Added more tests
3+
* Updated dependencies
4+
15
# 1.2.0
26
* Added ``LoginUrlStore``
37
* Stores the login url so that it can be used inside other parts of applications to e.g. display dedicated login components

oauth2-oidc/src/main/java/software/xdev/sse/oauth2/checkauth/OAuth2ProviderOfflineManager.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,20 @@ public class OAuth2ProviderOfflineManager
4141
public OAuth2ProviderOfflineManager(
4242
final AuthProviderOfflineConfig config,
4343
final List<OAuth2ProviderOfflineManagerMetricsHandler> metricsHandlers)
44+
{
45+
this(config, metricsHandlers, false);
46+
}
47+
48+
protected OAuth2ProviderOfflineManager(
49+
final AuthProviderOfflineConfig config,
50+
final List<OAuth2ProviderOfflineManagerMetricsHandler> metricsHandlers,
51+
final boolean silent)
4452
{
4553
this.config = config;
46-
LOG.info("Instantiated with {}", this.config);
54+
if(!silent)
55+
{
56+
LOG.info("Instantiated with {}", this.config);
57+
}
4758

4859
metricsHandlers.stream()
4960
.filter(OAuth2ProviderOfflineManagerMetricsHandler::enabled)

oauth2-oidc/src/main/java/software/xdev/sse/oauth2/filter/OAuth2RefreshFilter.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public void doFilter(final ServletRequest request, final ServletResponse respons
104104
}
105105

106106
@SuppressWarnings("java:S3626") // Incorrect
107-
private void checkAuth(final ServletRequest request, final ServletResponse response)
107+
protected void checkAuth(final ServletRequest request, final ServletResponse response)
108108
{
109109
if(request instanceof final HttpServletRequest httpRequest
110110
&& this.ignoreRequestMatcher.matches(httpRequest))
@@ -113,15 +113,14 @@ private void checkAuth(final ServletRequest request, final ServletResponse respo
113113
return;
114114
}
115115

116-
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
116+
final Authentication authentication = this.getCurrentAuth(request, response);
117117
if(!(authentication instanceof final OAuth2AuthenticationToken auth))
118118
{
119119
this.communicateReload(OAuth2RefreshReloadCommunicator.Source.NO_AUTH, request, response);
120120
this.metrics.noAuth();
121121
return;
122122
}
123123

124-
// Client may be null on initial login -> Do not log out
125124
final OAuth2AuthChecker.AuthCheckResult authCheckResult =
126125
this.oAuth2AuthChecker.check(auth, this.clientService::loadAuthorizedClient);
127126
this.metrics.authCheckMetricsIncrement(authCheckResult.outcome());
@@ -157,6 +156,12 @@ else if(authCheckResult.outcome() == OAuth2AuthChecker.AuthCheckOutcome.VALID)
157156
}
158157
}
159158

159+
@SuppressWarnings("java:S1172")
160+
protected Authentication getCurrentAuth(final ServletRequest request, final ServletResponse response)
161+
{
162+
return SecurityContextHolder.getContext().getAuthentication();
163+
}
164+
160165
protected Collection<OAuth2RefreshHandler> oAuth2RefreshHandlers()
161166
{
162167
return this.refreshHandlersProvider.get();

0 commit comments

Comments
 (0)