| 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 edu.ucsb.cs156.frontiers.services.UpdateUserService; | |
| 6 | import java.util.List; | |
| 7 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 8 | import org.springframework.security.core.Authentication; | |
| 9 | import org.springframework.security.core.GrantedAuthority; | |
| 10 | import org.springframework.security.core.context.SecurityContext; | |
| 11 | import org.springframework.security.core.context.SecurityContextHolder; | |
| 12 | import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken; | |
| 13 | import org.springframework.security.oauth2.core.oidc.user.OidcUser; | |
| 14 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 15 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 16 | import org.springframework.web.bind.annotation.RestController; | |
| 17 | ||
| 18 | @RestController | |
| 19 | @RequestMapping("/api/github") | |
| 20 | public class GithubController extends ApiController { | |
| 21 | ||
| 22 | private final UserRepository userRepository; | |
| 23 | private final UpdateUserService updateUserService; | |
| 24 | ||
| 25 | public GithubController(UserRepository userRepository, UpdateUserService updateUserService) { | |
| 26 | super(); | |
| 27 | this.userRepository = userRepository; | |
| 28 | this.updateUserService = updateUserService; | |
| 29 | } | |
| 30 | ||
| 31 | @PreAuthorize("hasRole('ROLE_GITHUB')") | |
| 32 | @DeleteMapping("/disconnect") | |
| 33 | public Object disconnect(SecurityContext context) { | |
| 34 | User currentUser = getCurrentUser().getUser(); | |
| 35 |
1
1. disconnect : removed call to edu/ucsb/cs156/frontiers/services/UpdateUserService::resetPendingInvitations → KILLED |
updateUserService.resetPendingInvitations(currentUser); |
| 36 |
1
1. disconnect : removed call to edu/ucsb/cs156/frontiers/entities/User::setGithubId → KILLED |
currentUser.setGithubId(null); |
| 37 |
1
1. disconnect : removed call to edu/ucsb/cs156/frontiers/entities/User::setGithubLogin → KILLED |
currentUser.setGithubLogin(null); |
| 38 | userRepository.save(currentUser); | |
| 39 | Authentication auth = context.getAuthentication(); | |
| 40 | List<? extends GrantedAuthority> removedAuthority = | |
| 41 | auth.getAuthorities().stream() | |
| 42 |
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())) |
| 43 | .toList(); | |
| 44 | OAuth2AuthenticationToken token = (OAuth2AuthenticationToken) context.getAuthentication(); | |
| 45 |
1
1. disconnect : removed call to org/springframework/security/core/context/SecurityContext::setAuthentication → KILLED |
context.setAuthentication( |
| 46 | new OAuth2AuthenticationToken( | |
| 47 | (OidcUser) auth.getPrincipal(), | |
| 48 | removedAuthority, | |
| 49 | token.getAuthorizedClientRegistrationId())); | |
| 50 | SecurityContextHolder.setContext(context); | |
| 51 |
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."); |
| 52 | } | |
| 53 | } | |
Mutations | ||
| 35 |
1.1 |
|
| 36 |
1.1 |
|
| 37 |
1.1 |
|
| 42 |
1.1 2.2 |
|
| 45 |
1.1 |
|
| 51 |
1.1 |