public Iterable<String> getOrgs() { try { final List<String> allOrgs = new ArrayList<>(); allOrgs.add(getCurrentLogin()); allOrgs.addAll(this.gh.getMyOrganizations().keySet()); return allOrgs; } catch (final IOException e) { throw new RuntimeException(e); } } }
/** * For some reason I can't get the github api to tell me for the current * user the groups to which he belongs. * * So this is a slightly larger consideration. If the authenticated user is * part of any team within the organization then they have permission. * * @param candidateName * @param organization * @return */ public boolean hasOrganizationPermission(String candidateName, String organization) { try { Map<String, GHOrganization> myOrgsMap = gh.getMyOrganizations(); if (myOrgsMap.keySet().contains(organization)) return true; return false; } catch (IOException e) { throw new RuntimeException("authorization failed for user = " + candidateName, e); } }
@Override public void scan() { try { getGitHubClient().getMyOrganizations().forEach((name, org) -> { scanOrganization(org); }); } catch (IOException e) { throw new MercatorException(e); } }
public GithubAuthenticationToken(String accessToken, String githubServer) throws IOException { super(new GrantedAuthority[] {}); this.accessToken = accessToken; this.gh = GitHub.connectUsingOAuth(githubServer, accessToken); GHUser me = gh.getMyself(); assert me!=null; setAuthenticated(true); this.userName = me.getLogin(); authorities.add(SecurityRealm.AUTHENTICATED_AUTHORITY); for (String name : gh.getMyOrganizations().keySet()) authorities.add(new GrantedAuthorityImpl(name)); }