Performance: Why authorization matters
Authorization affects server response time and user experience by controlling access to resources, impacting backend processing and frontend rendering speed.
Jump into concepts and practice - no test required
@PreAuthorize("hasRole('USER')") public String getUserData() { return fetchData(); }
public String getUserData() {
if (!userHasAccess()) {
throw new AccessDeniedException();
}
return fetchData();
}| Pattern | Backend Processing | Network Impact | Frontend Rendering | Verdict |
|---|---|---|---|---|
| Late manual authorization checks | High CPU usage | Increased response time | Delayed content display | [X] Bad |
| Declarative authorization with annotations | Low CPU usage | Faster response | Quicker content display | [OK] Good |
/admin/dashboard?
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().authenticated();
}@Secured("USER")
public String getUserData() {
return "data";
}http.authorizeRequests()
.antMatchers("/sensitive/**").hasAnyRole("ADMIN", "MANAGER")
.anyRequest().authenticated();
B) http.authorizeRequests()
.antMatchers("/sensitive/**").hasRole("ADMIN")
.antMatchers("/sensitive/**").hasRole("MANAGER")
.anyRequest().authenticated();
C) http.authorizeRequests()
.antMatchers("/sensitive/**").permitAll()
.anyRequest().authenticated();
D) http.authorizeRequests()
.antMatchers("/sensitive/**").denyAll()
.anyRequest().authenticated();