| 1 | package edu.ucsb.cs156.frontiers.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.frontiers.entities.User; | |
| 4 | import edu.ucsb.cs156.frontiers.repositories.UserRepository; | |
| 5 | import java.util.List; | |
| 6 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 7 | import org.springframework.security.core.Authentication; | |
| 8 | import org.springframework.security.core.GrantedAuthority; | |
| 9 | import org.springframework.security.core.context.SecurityContext; | |
| 10 | import org.springframework.security.core.context.SecurityContextHolder; | |
| 11 | import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken; | |
| 12 | import org.springframework.security.oauth2.core.oidc.user.OidcUser; | |
| 13 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 14 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 15 | import org.springframework.web.bind.annotation.RestController; | |
| 16 | ||
| 17 | @RestController | |
| 18 | @RequestMapping("/api/github") | |
| 19 | public class GithubController extends ApiController { | |
| 20 | ||
| 21 | private final UserRepository userRepository; | |
| 22 | ||
| 23 | public GithubController(UserRepository userRepository) { | |
| 24 | super(); | |
| 25 | this.userRepository = userRepository; | |
| 26 | } | |
| 27 | ||
| 28 | @PreAuthorize("hasRole('ROLE_GITHUB')") | |
| 29 | @DeleteMapping("/disconnect") | |
| 30 | public Object disconnect(SecurityContext context) { | |
| 31 | User currentUser = getCurrentUser().getUser(); | |
| 32 |
1
1. disconnect : removed call to edu/ucsb/cs156/frontiers/entities/User::setGithubId → KILLED |
currentUser.setGithubId(null); |
| 33 |
1
1. disconnect : removed call to edu/ucsb/cs156/frontiers/entities/User::setGithubLogin → KILLED |
currentUser.setGithubLogin(null); |
| 34 | userRepository.save(currentUser); | |
| 35 | Authentication auth = context.getAuthentication(); | |
| 36 | List<? extends GrantedAuthority> removedAuthority = | |
| 37 | auth.getAuthorities().stream() | |
| 38 |
2
1. lambda$disconnect$0 : replaced boolean return with true for edu/ucsb/cs156/frontiers/controllers/GithubController::lambda$disconnect$0 → KILLED 2. lambda$disconnect$0 : negated conditional → KILLED |
.filter(r -> !"ROLE_GITHUB".equals(r.getAuthority())) |
| 39 | .toList(); | |
| 40 | OAuth2AuthenticationToken token = (OAuth2AuthenticationToken) context.getAuthentication(); | |
| 41 |
1
1. disconnect : removed call to org/springframework/security/core/context/SecurityContext::setAuthentication → KILLED |
context.setAuthentication( |
| 42 | new OAuth2AuthenticationToken( | |
| 43 | (OidcUser) auth.getPrincipal(), | |
| 44 | removedAuthority, | |
| 45 | token.getAuthorizedClientRegistrationId())); | |
| 46 | SecurityContextHolder.setContext(context); | |
| 47 |
1
1. disconnect : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/GithubController::disconnect → KILLED |
return genericMessage("Disconnected from GitHub. You may now log in with a different account."); |
| 48 | } | |
| 49 | } | |
Mutations | ||
| 32 |
1.1 |
|
| 33 |
1.1 |
|
| 38 |
1.1 2.2 |
|
| 41 |
1.1 |
|
| 47 |
1.1 |