Skip to content

Commit

Permalink
#179 - Create a Cognito group that allows authentication but no FormK…
Browse files Browse the repository at this point in the history
…iQ authorization
  • Loading branch information
mfriesen committed Nov 25, 2023
1 parent 8d1ffde commit a5c88b0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
9 changes: 9 additions & 0 deletions console/src/main/resources/cloudformation/template-users.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ Resources:
- Arn
UserPoolId:
Ref: CognitoUserPool

AuthenticationOnlyGroup:
Type: "AWS::Cognito::UserPoolGroup"
Properties:
Precedence: 0
GroupName: "authentication_only"
Description: "Authentication only group access"
UserPoolId:
Ref: CognitoUserPool

AdminGroupParameter:
Type: AWS::SSM::Parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ private Collection<String> loadJwtGroups(final ApiGatewayRequestEvent event) {
groups.add(DEFAULT_SITE_ID);
}
}

groups.remove("authentication_only");
return groups;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ void testApiAuthorizer08() throws Exception {
@Test
void testApiAuthorizer09() throws Exception {
// given
String s = "[formkiq_finance other]";
String s = "[finance other]";

ApiGatewayRequestEvent event = getJwtEvent(s);
event.setQueryStringParameters(Map.of("siteId", "finance"));
Expand All @@ -336,10 +336,11 @@ void testApiAuthorizer09() throws Exception {

// then
assertEquals("finance", api0.siteId());
assertEquals("finance", String.join(",", api0.siteIds()));
assertEquals("finance,other", String.join(",", api0.siteIds()));
assertEquals("DELETE,READ,WRITE",
api0.permissions().stream().map(p -> p.name()).sorted().collect(Collectors.joining(",")));
assertEquals("groups: finance (DELETE,READ,WRITE)", api0.accessSummary());
assertEquals("groups: finance (DELETE,READ,WRITE), other (DELETE,READ,WRITE)",
api0.accessSummary());
}

/**
Expand Down Expand Up @@ -398,4 +399,24 @@ void testApiAuthorizer11() throws Exception {
api1.permissions().stream().map(p -> p.name()).collect(Collectors.joining(",")));
assertEquals("groups: finance (READ,WRITE)", api1.accessSummary());
}

/**
* Basic 'authentication_only' access.
*/
@Test
void testApiAuthorizer12() throws Exception {
// given
String s0 = "[authentication_only]";
ApiGatewayRequestEvent event0 = getJwtEvent(s0);

// when
ApiAuthorization api0 = new ApiAuthorizationBuilder().build(event0);

// then
assertNull(api0.siteId());
assertEquals("", String.join(",", api0.siteIds()));
assertEquals("",
api0.permissions().stream().map(p -> p.name()).collect(Collectors.joining(",")));
assertEquals("no groups", api0.accessSummary());
}
}

0 comments on commit a5c88b0

Please sign in to comment.