public Username(final Username userName, String displayName) { this(userName.getUsername(), displayName); }
private User getUser(HttpServletRequest request) { Long userId = SessionUtils.getUserId(request); if (userId == null) { final GoUserPrinciple currentUser = SessionUtils.getCurrentUser(); Username userName = new Username(currentUser.getUsername()); if (userName.isAnonymous() || userName.isGoAgentUser()) { return new NullUser(); } return userService.findUserByName(CaseInsensitiveString.str(userName.getUsername())); } else { return userService.load(userId); } } }
public EmailBodyGenerator(MaterialRevisions materialRevisions, Username cancelledBy, SystemEnvironment systemEnvironment, StageIdentifier stageIdentifier) { this.systemEnvironment = systemEnvironment; this.stageIdentifier = stageIdentifier; emailBody = new StringBuilder(); if (!Username.BLANK.equals(cancelledBy)) { emailBody.append("The stage was cancelled by ").append(CaseInsensitiveString.str(cancelledBy.getUsername())).append(".\n"); } addStageLink(); addMaterialRevisions(materialRevisions); }
public static BuildCause createManualForced(MaterialRevisions materialRevisions, Username username) { if (username == null) { throw new IllegalArgumentException("Username cannot be null"); } String message = String.format("Forced by %s", username.getDisplayName()); return new BuildCause(materialRevisions, BuildTrigger.forForced(message), CaseInsensitiveString.str(username.getUsername())); }
public GoUserPrinciple(String username, String displayName, Set<GrantedAuthority> authorities) { this.username = new Username(username, displayName); this.authorities = authorities; this.displayName = displayName; }
public Username getUsername() { return Username.valueOf(name); }
public boolean isAnonymous() { return this.equals(ANONYMOUS); }
private void pausePipeline(String pipelineName, String pauseCause, Username pauseBy) { String mutexPipelineName = mutexForPausePipeline(pipelineName); synchronized (mutexPipelineName) { String sanitizedPauseCause = pauseCause.substring(0, Math.min(255, pauseCause.length())); String pauseByDisplayName = pauseBy.getDisplayName(); String sanitizedPauseBy = pauseByDisplayName.substring(0, Math.min(255, pauseByDisplayName.length())); pipelineSqlMapDao.pause(pipelineName, sanitizedPauseCause, sanitizedPauseBy); LOGGER.info("[Pipeline Pause] Pipeline [{}] is paused by [{}] because [{}]", pipelineName, pauseBy, pauseCause); notifyListeners(PipelinePauseChangeListener.Event.pause(pipelineName, pauseBy)); } }
public void checkNonAnonymousUser(Request req, Response res) { if (currentUsername().isAnonymous()) { throw renderForbiddenResponse(); } }
public Username agentUsername(String uuId, String ipAddress, String hostNameForDisplay) { return new Username(String.format("agent_%s_%s_%s", uuId, ipAddress, hostNameForDisplay)); }
@Override public boolean canContinue(CruiseConfig cruiseConfig) { if (!goConfigService.isAdministrator(username.getUsername())) { result.forbidden(LocalizedMessage.forbiddenToEditResource("environment", environmentConfig.name(), username.getDisplayName()), HealthStateType.forbidden()); return false; } return true; }
public Stage findStageWithIdentifier(String pipelineName, int pipelineCounter, String stageName, String stageCounter, String username, OperationResult result) { if (!goConfigService.currentCruiseConfig().hasPipelineNamed(new CaseInsensitiveString(pipelineName))) { String message = String.format("Pipeline '%s' not found", pipelineName); result.notFound("Not Found", message, HealthStateType.general(HealthStateScope.GLOBAL)); return null; } if (!securityService.hasViewPermissionForPipeline(Username.valueOf(username), pipelineName)) { result.forbidden("Unauthorized", NOT_AUTHORIZED_TO_VIEW_PIPELINE, HealthStateType.general(HealthStateScope.forPipeline(pipelineName))); return null; } Pipeline pipeline = pipelineDao.findPipelineByNameAndCounter(pipelineName, pipelineCounter); if (pipeline == null) { String message = String.format("Pipeline '%s' with counter '%s' not found", pipelineName, pipelineCounter); result.notFound("Not Found", message, HealthStateType.general(HealthStateScope.GLOBAL)); return null; } return findStageWithIdentifier(new StageIdentifier(pipelineName, pipelineCounter, stageName, stageCounter)); }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof GoUserPrinciple)) return false; GoUserPrinciple that = (GoUserPrinciple) o; if (authorities != null ? !authorities.equals(that.authorities) : that.authorities != null) return false; if (displayName != null ? !displayName.equals(that.displayName) : that.displayName != null) return false; return username != null ? username.equals(that.username) : that.username == null; }
@Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Username userName = SessionUtils.currentUsername(); String pipeline = pipeline(request); if (authorizedToViewPipeline(userName, pipeline)) { super.service(request, response); return; } response.sendError(SC_FORBIDDEN, String.format("%s is not authorized to view the pipeline %s", userName.getDisplayName(), pipeline)); }
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { final AuthenticationToken<?> authentication = SessionUtils.getAuthenticationToken(request); final Set<GrantedAuthority> authorities = authentication.getUser().getAuthorities(); if (authorityVerifier.hasAnyAuthorityMatching(authorities)) { LOGGER.debug("User {} authorized to access {}", authentication.getUser().getUsername(), request.getRequestURI()); filterChain.doFilter(request, response); } else { LOGGER.debug("User {} not authorized to access {}: has authorities {}", authentication.getUser().getUsername(), request.getRequestURI(), authentication.getUser().getAuthorities()); if (SessionUtils.getCurrentUser().asUsernameObject().isAnonymous()) { requestHandler.handle(request, response, SC_UNAUTHORIZED, "You are not authenticated!"); } else { requestHandler.handle(request, response, SC_FORBIDDEN, "You are not authorized to access this resource!"); } } } }
private String calcEtag(Username username, List<GoDashboardPipelineGroup> pipelineGroups, List<GoDashboardEnvironment> environments) { final String pipelineSegment = pipelineGroups.stream(). map(GoDashboardPipelineGroup::etag).collect(Collectors.joining(SEP_CHAR)); final String environmentSegment = environments.stream(). map(GoDashboardEnvironment::etag).collect(Collectors.joining(SEP_CHAR)); return DigestUtils.md5Hex(StringUtils.joinWith(SEP_CHAR, username.getUsername(), pipelineSegment, environmentSegment)); }
public Username usernameFor(String pluginId) { return new Username(format("plugin-%s", pluginId)); }
public StageInstanceModels findDetailedStageHistoryByOffset(String pipelineName, String stageName, Pagination pagination, String username, OperationResult result) { if (!goConfigService.currentCruiseConfig().hasPipelineNamed(new CaseInsensitiveString(pipelineName))) { result.notFound("Not Found", "Pipeline not found", HealthStateType.general(HealthStateScope.GLOBAL)); return null; } if (!securityService.hasViewPermissionForPipeline(Username.valueOf(username), pipelineName)) { result.forbidden("Unauthorized", NOT_AUTHORIZED_TO_VIEW_PIPELINE, HealthStateType.general(HealthStateScope.forPipeline(pipelineName))); return null; } return stageDao.findDetailedStageHistoryByOffset(pipelineName, stageName, pagination); }
public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } StageResultMessage that = (StageResultMessage) o; if (cancelledBy != null ? !cancelledBy.equals(that.cancelledBy) : that.cancelledBy != null) { return false; } if (event != that.event) { return false; } if (stageIdentifier != null ? !stageIdentifier.equals(that.stageIdentifier) : that.stageIdentifier != null) { return false; } return true; }
private String calcEtag(Username username, List<GoDashboardPipelineGroup> pipelineGroups, List<GoDashboardEnvironment> environments) { final String pipelineSegment = pipelineGroups.stream(). map(GoDashboardPipelineGroup::etag).collect(Collectors.joining(SEP_CHAR)); final String environmentSegment = environments.stream(). map(GoDashboardEnvironment::etag).collect(Collectors.joining(SEP_CHAR)); return DigestUtils.md5Hex(StringUtils.joinWith(SEP_CHAR, username.getUsername(), pipelineSegment, environmentSegment)); }