| 1 | package edu.ucsb.cs156.frontiers.config; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.frontiers.entities.CourseApiKey; | |
| 4 | import edu.ucsb.cs156.frontiers.entities.User; | |
| 5 | import java.util.Collection; | |
| 6 | import lombok.Getter; | |
| 7 | import org.springframework.security.authentication.AbstractAuthenticationToken; | |
| 8 | import org.springframework.security.core.GrantedAuthority; | |
| 9 | ||
| 10 | public class ApiKeyToken extends AbstractAuthenticationToken { | |
| 11 | ||
| 12 | @Getter private final Long courseId; | |
| 13 | private final User user; | |
| 14 | ||
| 15 | /** | |
| 16 | * Creates a token with the supplied array of authorities. | |
| 17 | * | |
| 18 | * @param authorities the collection of <tt>GrantedAuthority</tt>s for the principal represented | |
| 19 | * by this authentication object. | |
| 20 | */ | |
| 21 | public ApiKeyToken( | |
| 22 | CourseApiKey key, User user, Collection<? extends GrantedAuthority> authorities) { | |
| 23 | super(authorities); | |
| 24 | this.courseId = key.getCourse().getId(); | |
| 25 | this.user = user; | |
| 26 |
2
1. lambda$new$0 : replaced boolean return with false for edu/ucsb/cs156/frontiers/config/ApiKeyToken::lambda$new$0 → KILLED 2. lambda$new$0 : replaced boolean return with true for edu/ucsb/cs156/frontiers/config/ApiKeyToken::lambda$new$0 → KILLED |
assert (authorities.stream().anyMatch(a -> a.getAuthority().equals("ROLE_API_KEY"))) |
| 27 | : "Collection must contain ROLE_API_KEY"; | |
| 28 | } | |
| 29 | ||
| 30 | @Override | |
| 31 | public boolean isAuthenticated() { | |
| 32 |
1
1. isAuthenticated : replaced boolean return with false for edu/ucsb/cs156/frontiers/config/ApiKeyToken::isAuthenticated → KILLED |
return true; |
| 33 | } | |
| 34 | ||
| 35 | @Override | |
| 36 | public Object getCredentials() { | |
| 37 | return null; | |
| 38 | } | |
| 39 | ||
| 40 | @Override | |
| 41 | public User getPrincipal() { | |
| 42 |
1
1. getPrincipal : replaced return value with null for edu/ucsb/cs156/frontiers/config/ApiKeyToken::getPrincipal → KILLED |
return this.user; |
| 43 | } | |
| 44 | ||
| 45 | @Override | |
| 46 | public String getName() { | |
| 47 |
1
1. getName : replaced return value with "" for edu/ucsb/cs156/frontiers/config/ApiKeyToken::getName → KILLED |
return this.user.getEmail(); |
| 48 | } | |
| 49 | } | |
Mutations | ||
| 26 |
1.1 2.2 |
|
| 32 |
1.1 |
|
| 42 |
1.1 |
|
| 47 |
1.1 |