| 1 | package edu.ucsb.cs156.frontiers.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.frontiers.entities.User; | |
| 4 | import edu.ucsb.cs156.frontiers.enums.OrgStatus; | |
| 5 | import edu.ucsb.cs156.frontiers.repositories.CourseStaffRepository; | |
| 6 | import edu.ucsb.cs156.frontiers.repositories.RosterStudentRepository; | |
| 7 | import edu.ucsb.cs156.frontiers.repositories.UserRepository; | |
| 8 | import java.util.List; | |
| 9 | import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 11 | import org.springframework.security.core.Authentication; | |
| 12 | import org.springframework.security.core.GrantedAuthority; | |
| 13 | import org.springframework.security.core.context.SecurityContext; | |
| 14 | import org.springframework.security.core.context.SecurityContextHolder; | |
| 15 | import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken; | |
| 16 | import org.springframework.security.oauth2.core.oidc.user.OidcUser; | |
| 17 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 18 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 19 | import org.springframework.web.bind.annotation.RestController; | |
| 20 | ||
| 21 | @RestController | |
| 22 | @RequestMapping("/api/github") | |
| 23 | public class GithubController extends ApiController { | |
| 24 | ||
| 25 | @Autowired private UserRepository userRepository; | |
| 26 | @Autowired private CourseStaffRepository courseStaffRepository; | |
| 27 | @Autowired private RosterStudentRepository rosterStudentRepository; | |
| 28 | ||
| 29 | @PreAuthorize("hasRole('ROLE_GITHUB')") | |
| 30 | @DeleteMapping("/disconnect") | |
| 31 | public Object disconnect(SecurityContext context) { | |
| 32 | User currentUser = getCurrentUser().getUser(); | |
| 33 |
1
1. disconnect : removed call to edu/ucsb/cs156/frontiers/entities/User::setGithubId → KILLED |
currentUser.setGithubId(null); |
| 34 |
1
1. disconnect : removed call to edu/ucsb/cs156/frontiers/entities/User::setGithubLogin → KILLED |
currentUser.setGithubLogin(null); |
| 35 | userRepository.save(currentUser); | |
| 36 | ||
| 37 | rosterStudentRepository | |
| 38 | .findAllByEmail(currentUser.getEmail()) | |
| 39 |
1
1. disconnect : removed call to java/util/List::forEach → KILLED |
.forEach( |
| 40 | rs -> { | |
| 41 |
1
1. lambda$disconnect$0 : negated conditional → KILLED |
if (rs.getOrgStatus() == OrgStatus.INVITED) { |
| 42 |
1
1. lambda$disconnect$0 : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setGithubId → KILLED |
rs.setGithubId(null); |
| 43 |
1
1. lambda$disconnect$0 : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setGithubLogin → KILLED |
rs.setGithubLogin(null); |
| 44 |
1
1. lambda$disconnect$0 : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setOrgStatus → KILLED |
rs.setOrgStatus(OrgStatus.JOINCOURSE); |
| 45 | rosterStudentRepository.save(rs); | |
| 46 | } | |
| 47 | }); | |
| 48 | ||
| 49 | courseStaffRepository | |
| 50 | .findAllByEmail(currentUser.getEmail()) | |
| 51 |
1
1. disconnect : removed call to java/util/List::forEach → KILLED |
.forEach( |
| 52 | cs -> { | |
| 53 |
1
1. lambda$disconnect$1 : negated conditional → KILLED |
if (cs.getOrgStatus() == OrgStatus.INVITED) { |
| 54 |
1
1. lambda$disconnect$1 : removed call to edu/ucsb/cs156/frontiers/entities/CourseStaff::setGithubId → KILLED |
cs.setGithubId(null); |
| 55 |
1
1. lambda$disconnect$1 : removed call to edu/ucsb/cs156/frontiers/entities/CourseStaff::setGithubLogin → KILLED |
cs.setGithubLogin(null); |
| 56 |
1
1. lambda$disconnect$1 : removed call to edu/ucsb/cs156/frontiers/entities/CourseStaff::setOrgStatus → KILLED |
cs.setOrgStatus(OrgStatus.JOINCOURSE); |
| 57 | courseStaffRepository.save(cs); | |
| 58 | } | |
| 59 | }); | |
| 60 | ||
| 61 | Authentication auth = context.getAuthentication(); | |
| 62 | List<? extends GrantedAuthority> removedAuthority = | |
| 63 | auth.getAuthorities().stream() | |
| 64 |
2
1. lambda$disconnect$2 : replaced boolean return with true for edu/ucsb/cs156/frontiers/controllers/GithubController::lambda$disconnect$2 → KILLED 2. lambda$disconnect$2 : negated conditional → KILLED |
.filter(r -> !"ROLE_GITHUB".equals(r.getAuthority())) |
| 65 | .toList(); | |
| 66 | OAuth2AuthenticationToken token = (OAuth2AuthenticationToken) context.getAuthentication(); | |
| 67 |
1
1. disconnect : removed call to org/springframework/security/core/context/SecurityContext::setAuthentication → KILLED |
context.setAuthentication( |
| 68 | new OAuth2AuthenticationToken( | |
| 69 | (OidcUser) auth.getPrincipal(), | |
| 70 | removedAuthority, | |
| 71 | token.getAuthorizedClientRegistrationId())); | |
| 72 | SecurityContextHolder.setContext(context); | |
| 73 |
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."); |
| 74 | } | |
| 75 | } | |
Mutations | ||
| 33 |
1.1 |
|
| 34 |
1.1 |
|
| 39 |
1.1 |
|
| 41 |
1.1 |
|
| 42 |
1.1 |
|
| 43 |
1.1 |
|
| 44 |
1.1 |
|
| 51 |
1.1 |
|
| 53 |
1.1 |
|
| 54 |
1.1 |
|
| 55 |
1.1 |
|
| 56 |
1.1 |
|
| 64 |
1.1 2.2 |
|
| 67 |
1.1 |
|
| 73 |
1.1 |