-
-
Notifications
You must be signed in to change notification settings - Fork 403
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvements on webUser password change. Only own password can be cha…
…nged
- Loading branch information
Showing
6 changed files
with
50 additions
and
27 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,9 @@ | |
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter; | ||
|
||
import static de.rwth.idsg.steve.SteveConfiguration.CONFIG; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.security.web.access.expression.WebExpressionAuthorizationManager; | ||
import org.springframework.security.web.util.matcher.RequestMatcher; | ||
|
||
/** | ||
* @author Sevket Goekay <[email protected]> | ||
|
@@ -60,6 +63,8 @@ public PasswordEncoder passwordEncoder() { | |
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { | ||
final String prefix = CONFIG.getSpringManagerMapping(); | ||
|
||
RequestMatcher toOverview = (request) -> request.getParameter("backToOverview") != null; | ||
|
||
return http | ||
.authorizeHttpRequests( | ||
req -> req | ||
|
@@ -70,9 +75,14 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti | |
"/WEB-INF/views/**" // https://github.com/spring-projects/spring-security/issues/13285#issuecomment-1579097065 | ||
).permitAll() | ||
.requestMatchers(prefix + "/home").hasAnyAuthority("USER", "ADMIN") | ||
// webuser | ||
.requestMatchers(prefix + "/webusers").hasAnyAuthority("USER", "ADMIN") | ||
.requestMatchers(prefix + "/webusers" + "/details/**").hasAnyAuthority("USER", "ADMIN") | ||
// webuser | ||
//only allowed to change the own password | ||
.requestMatchers(prefix + "/webusers" + "/password/{name}") | ||
.access(new WebExpressionAuthorizationManager("#name == authentication.name")) | ||
// otherwise denies access on backToOverview! | ||
.requestMatchers(toOverview).hasAnyAuthority("USER", "ADMIN") | ||
.requestMatchers(HttpMethod.GET, prefix + "/webusers/**").hasAnyAuthority("USER", "ADMIN") | ||
.requestMatchers(HttpMethod.POST, prefix + "/webusers/**").hasAuthority("ADMIN") | ||
// users | ||
.requestMatchers(prefix + "/users").hasAnyAuthority("USER", "ADMIN") | ||
.requestMatchers(prefix + "/users" + "/details/**").hasAnyAuthority("USER", "ADMIN") | ||
|
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
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
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