Update sectraining.md

This commit is contained in:
Sander Hautvast 2024-02-05 12:07:49 +01:00 committed by GitHub
parent a83bc196e3
commit becb68794d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -125,3 +125,32 @@ private static boolean isLocal(String path) {
return path.startsWith("/") && !path.startsWith("//");
}
```
### Broken Authorization
#### prevention in java (spring boot)
```java
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity security) throws Exception {
http
.authorizeRequests()
.antMatchers("/admin/**").hasRole("ROLE_ADMIN");
}
...
}
```
and
```java
@Service
public class AdminService {
@PreAuthorize("hasRole('ROLE_ADMIN')")
public List<Organization> findAllOrganizations() { ... }
...
}
```