-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use CSRF filter after authentication for remote auth modules
- Loading branch information
1 parent
c9a3935
commit 11c2f42
Showing
4 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...volveum/midpoint/authentication/impl/filter/UseCsrfFilterOnlyForAuthenticatedRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (c) 2023 Evolveum and contributors | ||
* | ||
* This work is dual-licensed under the Apache License 2.0 | ||
* and European Union Public License. See LICENSE file for details. | ||
*/ | ||
|
||
package com.evolveum.midpoint.authentication.impl.filter; | ||
|
||
import com.evolveum.midpoint.authentication.api.config.MidpointAuthentication; | ||
import com.evolveum.midpoint.authentication.api.util.AuthUtil; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import org.springframework.security.web.csrf.CsrfFilter; | ||
import org.springframework.security.web.util.matcher.RequestMatcher; | ||
|
||
public class UseCsrfFilterOnlyForAuthenticatedRequest implements RequestMatcher { | ||
|
||
private final RequestMatcher requireCsrfProtectionMatcher = CsrfFilter.DEFAULT_CSRF_MATCHER; | ||
|
||
@Override | ||
public boolean matches(HttpServletRequest request) { | ||
MidpointAuthentication mPAuthentication = AuthUtil.getMidpointAuthentication(); | ||
if (mPAuthentication != null && mPAuthentication.isAuthenticated()) { | ||
return requireCsrfProtectionMatcher.matches(request); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public MatchResult matcher(HttpServletRequest request) { | ||
return requireCsrfProtectionMatcher.matcher(request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters