-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from razakpm/main
chore: update error message #15
- Loading branch information
Showing
2 changed files
with
8 additions
and
4 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
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 |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
import java.util.Optional; | ||
|
||
public class GitHubUserAuthorizationFilter extends OncePerRequestFilter { | ||
|
||
private static final String supportEmail = "NYeC QCS Support <[email protected]>"; | ||
private static final Logger LOGGER = LoggerFactory.getLogger(GitHubUserAuthorizationFilter.class); | ||
|
||
static List<Controller.AuthenticatedUser> newListUsers; | ||
|
@@ -30,7 +30,8 @@ protected void doFilterInternal(@NotNull HttpServletRequest request, @NotNull Ht | |
try { | ||
newListUsers = new GitHubUserService().getUserList().users(); | ||
for (Controller.AuthenticatedUser user : newListUsers) { | ||
LOGGER.info("List of Users available in sensitive repo: \ngithub-id: {}\nname: {}\ntenantId: {}\nroles: {}", | ||
LOGGER.info( | ||
"[GITHUB-AUTH] List of Users available in sensitive repo: \tgithub-id: {}\tname: {}\ttenantId: {}\troles: {}", | ||
user.gitHubId(), user.name(), user.tenantId(), user.roles()); | ||
} | ||
} catch (IOException e) { | ||
|
@@ -40,12 +41,15 @@ protected void doFilterInternal(@NotNull HttpServletRequest request, @NotNull Ht | |
if (authentication != null && authentication.isAuthenticated()) { | ||
DefaultOAuth2User authUser = (DefaultOAuth2User) authentication.getPrincipal(); | ||
String githubId = authUser.getAttribute("login"); | ||
LOGGER.info("[GITHUB-AUTH] Attempted User: \t github-id: {}\t name: {}", | ||
githubId, authUser.getAttribute("name")); | ||
Optional<Controller.AuthenticatedUser> user = newListUsers.stream() | ||
.filter(u -> u.gitHubId().equals(githubId) && u.roles().contains("USER")) | ||
.findFirst(); | ||
if (!user.isPresent()) { | ||
response.setStatus(HttpServletResponse.SC_FORBIDDEN); | ||
response.getWriter().write("Access Denied"); | ||
response.getWriter().write("You do not have permission to access this resource. Please send an email to " | ||
+ supportEmail + " with your GitHub ID to request access."); | ||
return; | ||
} | ||
|
||
|