Skip to content

Commit

Permalink
refactor(lnurl-auth): do not set details on authentication token
Browse files Browse the repository at this point in the history
  • Loading branch information
theborakompanioni committed Feb 14, 2024
1 parent e82ca0b commit 11bc7c3
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
)
@ActiveProfiles("test")
class AuthenticatedApiTest {
private static final String GUARDED_ENDPOINT = "/api/v1/authenticated/self";

private static final SecureRandom random = new SecureRandom();

private static SimpleLnurlWallet testWallet;
Expand All @@ -41,15 +43,12 @@ static void setUpAll() {

@Test
void itShouldFetchAuthenticatedUserJson() {
ResponseEntity<Object> request0 = restTemplate.exchange(RequestEntity
.get("/api/v1/authenticated/self")
.build(), Object.class);
ResponseEntity<Object> request0 = restTemplate.exchange(RequestEntity.get(GUARDED_ENDPOINT).build(), Object.class);
assertThat("user cannot see any guarded resource", request0.getStatusCode(), is(HttpStatus.FORBIDDEN));

Pair<SignedLnurlAuth, String> signedAuthAndSessionId = new LnurlAuthFlowTest.LnurlAuthFlowTestHelper(restTemplate, testWallet).login();

ResponseEntity<String> authTestRequest2ResponseEntity = restTemplate.exchange(RequestEntity
.get("/api/v1/authenticated/self")
ResponseEntity<String> authTestRequest2ResponseEntity = restTemplate.exchange(RequestEntity.get(GUARDED_ENDPOINT)
.header(HttpHeaders.COOKIE, "SESSION=%s".formatted(signedAuthAndSessionId.getSecond()))
.build(), String.class);
assertThat(authTestRequest2ResponseEntity.getStatusCode(), is(HttpStatus.OK));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ protected UserDetails retrieveUser(Authentication authentication) throws Authent
protected Authentication createSuccessAuthentication(Authentication authentication, UserDetails user) {
LnurlAuthSessionToken auth = (LnurlAuthSessionToken) authentication;

LnurlAuthSessionToken newAuth = new LnurlAuthSessionToken(auth.getK1(), user, user.getAuthorities());
newAuth.setDetails(user);

return newAuth;
return new LnurlAuthSessionToken(auth.getK1(), user, user.getAuthorities());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentExce
Assert.isTrue(!isAuthenticated, "Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead");
super.setAuthenticated(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ protected UserDetails retrieveUser(Authentication authentication) throws Authent
protected Authentication createSuccessAuthentication(Authentication authentication, UserDetails user) {
LnurlAuthWalletToken auth = (LnurlAuthWalletToken) authentication;

LnurlAuthWalletToken newAuth = new LnurlAuthWalletToken(auth.getAuth(), user, user.getAuthorities());
newAuth.setDetails(user);

return newAuth;
return new LnurlAuthWalletToken(auth.getAuth(), user, user.getAuthorities());
}

private boolean verifyLogin(SignedLnurlAuth auth) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ public Signature getSignature() {
public LinkingKey getLinkingKey() {
return auth.getLinkingKey();
}
}
}

0 comments on commit 11bc7c3

Please sign in to comment.