Update sectraining.md
This commit is contained in:
parent
a83bc196e3
commit
becb68794d
1 changed files with 29 additions and 0 deletions
|
|
@ -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() { ... }
|
||||
...
|
||||
}
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue