org.gitlab.api.models.GitlabGroup Java Examples
The following examples show how to use
org.gitlab.api.models.GitlabGroup.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GitlabApiClient.java From nexus3-gitlabauth-plugin with MIT License | 6 votes |
private GitlabPrincipal doAuthz(String loginName, char[] token) throws GitlabAuthenticationException { GitlabUser gitlabUser; List<GitlabGroup> groups = null; try { GitlabAPI gitlabAPI = GitlabAPI.connect(configuration.getGitlabApiUrl(), String.valueOf(token)); gitlabUser = gitlabAPI.getUser(); } catch (Exception e) { throw new GitlabAuthenticationException(e); } if (gitlabUser==null || !loginName.equals(gitlabUser.getEmail())) { throw new GitlabAuthenticationException("Given username not found or does not match Github Username!"); } GitlabPrincipal principal = new GitlabPrincipal(); principal.setUsername(gitlabUser.getEmail()); principal.setGroups(getGroups((gitlabUser.getUsername()))); return principal; }
Example #2
Source File: GitLabAuthenticationToken.java From gitlab-oauth-plugin with MIT License | 6 votes |
/** * For some reason I can't get the gitlab 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. * * It caches user organizations for 24 hours for faster web navigation. * * @param candidateName * @param organization * @return */ public boolean hasOrganizationPermission(String candidateName, String organization) { try { Set<String> v = userOrganizationCache.get(candidateName, new Callable<Set<String>>() { @Override public Set<String> call() throws Exception { List<GitlabGroup> groups = gitLabAPI.getGroups(); Set<String> groupsNames = new HashSet<String>(); for (GitlabGroup group : groups) { groupsNames.add(group.getName()); } return groupsNames; } }); return v.contains(organization); } catch (ExecutionException e) { throw new RuntimeException("authorization failed for user = " + candidateName, e); } }
Example #3
Source File: GitLabAuthenticationToken.java From gitlab-oauth-plugin with MIT License | 6 votes |
/** * @since 0.21 */ public GitLabOAuthUserDetails getUserDetails(String username) { GitlabUser user = loadUser(username); if (user != null) { // FIXME to implement List<GrantedAuthority> groups = new ArrayList<GrantedAuthority>(); try { List<GitlabGroup> gitLabGroups = gitLabAPI.getGroups(); for (GitlabGroup gitlabGroup : gitLabGroups) { groups.add(new GrantedAuthorityImpl(gitlabGroup.getName())); } } catch (IOException e) { LOGGER.log(Level.FINE, e.getMessage(), e); } return new GitLabOAuthUserDetails(user, groups.toArray(new GrantedAuthority[groups.size()])); } return null; }
Example #4
Source File: GitlabApiClient.java From nexus3-gitlabauth-plugin with MIT License | 5 votes |
private Set<String> getGroups(String username) throws GitlabAuthenticationException { List<GitlabGroup> groups; try { groups = client.getGroupsViaSudo(username,new Pagination().withPerPage(Pagination.MAX_ITEMS_PER_PAGE)); } catch (IOException e) { throw new GitlabAuthenticationException("Could not fetch groups for given username"); } return groups.stream().map(this::mapGitlabGroupToNexusRole).collect(Collectors.toSet()); }
Example #5
Source File: GitLabAPI.java From gitlab-branch-source-plugin with GNU General Public License v2.0 | 5 votes |
public GitLabGroup getGroup(int id) throws GitLabAPIException { try { return delegate.retrieve().to(GitlabGroup.URL + PATH_SEP + id, GitLabGroup.class); } catch (Exception e) { throw new GitLabAPIException(e); } }
Example #6
Source File: GitLabAPI.java From gitlab-branch-source-plugin with GNU General Public License v2.0 | 5 votes |
private String projectUrl(String group, GitLabProjectSelector selector, GitLabProjectVisibility visibility, String searchPattern) { StringBuilder urlBuilder = new StringBuilder(GitlabGroup.URL).append(PATH_SEP).append(group).append(GitLabProject.URL).append("?membership=true"); if (!VISIBLE.equals(selector)) { urlBuilder.append("&").append(selector.id()).append("=true"); } if (!ALL.equals(visibility)) { urlBuilder.append("&visibility=").append(visibility.id()); } if (!StringUtils.isEmpty(searchPattern)) { urlBuilder.append("&search=").append(searchPattern); } return urlBuilder.toString(); }
Example #7
Source File: GitLabAuthenticationToken.java From gitlab-oauth-plugin with MIT License | 5 votes |
public GitlabGroup loadOrganization(String organization) { if(StringUtils.isEmpty(organization)) return null; try { if (gitLabAPI != null && isAuthenticated() && !gitLabAPI.getGroups().isEmpty()) { return gitLabAPI.getGroups().stream().filter(group -> group.getName().contains(organization) || organization.contains(group.getName())).findFirst().orElse(null); } } catch (IOException e) { LOGGER.log(Level.FINEST, e.getMessage(), e); } return null; }
Example #8
Source File: GitLabAuthenticationToken.java From gitlab-oauth-plugin with MIT License | 5 votes |
public List<GitlabProject> getGroupProjects(final GitlabGroup group) { try { List<GitlabProject> groupProjects = groupRepositoriesCache.get(group.getPath(), new Callable<List<GitlabProject>>() { @Override public List<GitlabProject> call() throws Exception { return gitLabAPI.getGroupProjects(group); } }); return groupProjects; } catch (ExecutionException e) { LOGGER.log(Level.SEVERE, "an exception was thrown", e); throw new RuntimeException("authorization failed for user = " + getName(), e); } }
Example #9
Source File: GitLabSecurityRealm.java From gitlab-oauth-plugin with MIT License | 5 votes |
/** * * @param groupName * @return * @throws UsernameNotFoundException * @throws DataAccessException */ @Override public GroupDetails loadGroupByGroupname(String groupName) throws UsernameNotFoundException, DataAccessException { GitLabAuthenticationToken authToken = (GitLabAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); if (authToken == null) { throw new UsernameNotFoundException("No known group: " + groupName); } GitlabGroup gitlabGroup = authToken.loadOrganization(groupName); return new GitLabOAuthGroupDetails(gitlabGroup); }
Example #10
Source File: GitlabApiClient.java From nexus3-gitlabauth-plugin with MIT License | 4 votes |
private String mapGitlabGroupToNexusRole(GitlabGroup team) { return team.getPath(); }
Example #11
Source File: GitLabOAuthGroupDetails.java From gitlab-oauth-plugin with MIT License | 4 votes |
/** * Group based on organization name * @param gitlabGroup */ public GitLabOAuthGroupDetails(GitlabGroup gitlabGroup) { super(); this.gitlabGroup = gitlabGroup; }