1 | package edu.ucsb.cs156.example.services; | |
2 | ||
3 | import java.util.Collection; | |
4 | ||
5 | import org.springframework.security.core.Authentication; | |
6 | import org.springframework.security.core.GrantedAuthority; | |
7 | import org.springframework.security.core.context.SecurityContext; | |
8 | import org.springframework.security.core.context.SecurityContextHolder; | |
9 | import org.springframework.stereotype.Service; | |
10 | ||
11 | import lombok.extern.slf4j.Slf4j; | |
12 | ||
13 | /** | |
14 | * The is a service that retrieves and logs the granted authorities for the | |
15 | * current user's authentication. | |
16 | */ | |
17 | @Slf4j | |
18 | @Service("grantedAuthorities") | |
19 | public class GrantedAuthoritiesService { | |
20 | ||
21 | /** | |
22 | * The function retrieves and logs the granted authorities from the current security context in a | |
23 | * Java application. | |
24 | * | |
25 | * @return collection of authorities granted to the currently authenticated user. | |
26 | */ | |
27 | public Collection<? extends GrantedAuthority> getGrantedAuthorities() { | |
28 | SecurityContext securityContext = SecurityContextHolder.getContext(); | |
29 | Authentication authentication = securityContext.getAuthentication(); | |
30 | Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities(); | |
31 | log.info("authorities={}", authorities); | |
32 |
1
1. getGrantedAuthorities : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/services/GrantedAuthoritiesService::getGrantedAuthorities → KILLED |
return authorities; |
33 | } | |
34 | ||
35 | } | |
Mutations | ||
32 |
1.1 |