-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #793 Allow API access to Elide for services without user authe…
…ntication
- Loading branch information
1 parent
555c745
commit c4d6d21
Showing
21 changed files
with
218 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
package com.faforever.api.user; | ||
|
||
import com.faforever.api.AbstractIntegrationTest; | ||
import com.faforever.api.security.FafRole; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Set; | ||
|
||
import static com.faforever.api.data.domain.GroupPermission.ROLE_READ_ACCOUNT_PRIVATE_DETAILS; | ||
import static com.faforever.api.data.domain.GroupPermission.ROLE_USER; | ||
import static org.hamcrest.Matchers.containsInAnyOrder; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
|
@@ -29,6 +31,9 @@ public void withActiveUserGetResult() throws Exception { | |
.andExpect(jsonPath("$.data.attributes.userName", is(AUTH_ACTIVE_USER))) | ||
.andExpect(jsonPath("$.data.attributes.email", is("[email protected]"))) | ||
.andExpect(jsonPath("$.data.attributes.permissions", | ||
containsInAnyOrder(ROLE_READ_ACCOUNT_PRIVATE_DETAILS, "ROLE_" + ROLE_READ_ACCOUNT_PRIVATE_DETAILS))); | ||
containsInAnyOrder( | ||
ROLE_READ_ACCOUNT_PRIVATE_DETAILS, FafRole.ROLE_PREFIX + ROLE_READ_ACCOUNT_PRIVATE_DETAILS, | ||
ROLE_USER, FafRole.ROLE_PREFIX + ROLE_USER | ||
))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 14 additions & 8 deletions
22
src/main/java/com/faforever/api/security/FafAuthenticationConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/com/faforever/api/security/FafServiceAuthenticationToken.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.faforever.api.security; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import lombok.Getter; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Collection; | ||
|
||
@Getter | ||
public final class FafServiceAuthenticationToken extends FafAuthenticationToken { | ||
|
||
private final String serviceName; | ||
|
||
public FafServiceAuthenticationToken( | ||
String serviceName, | ||
@NotNull Collection<FafScope> scopes | ||
) { | ||
super( | ||
scopes, | ||
ImmutableList.<FafRole>builder() | ||
.add(new FafRole("SERVICE")) | ||
.build() | ||
); | ||
this.serviceName = serviceName; | ||
// since the access token was already verified, each FafAuthenticationToken is implicitly authenticated | ||
this.setAuthenticated(true); | ||
} | ||
|
||
@Override | ||
public Object getPrincipal() { | ||
return serviceName; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return String.format("Service %s", serviceName); | ||
} | ||
} |
Oops, something went wrong.