Skip to content

Commit

Permalink
Merge pull request #32 from razakpm/main
Browse files Browse the repository at this point in the history
chore: update error message #15
  • Loading branch information
ratheesh-kr authored Jun 14, 2024
2 parents 5cab470 + eb6acb1 commit 2a8d45f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion hub-prime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>
<groupId>org.techbd</groupId>
<artifactId>hub-prime</artifactId>
<version>0.65.2</version>
<version>0.65.3</version>
<packaging>war</packaging>
<name>TechBD Hub (Prime)</name>
<description>TechBD Hub (Primary)</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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;
}

Expand Down

0 comments on commit 2a8d45f

Please sign in to comment.