@Override public GoApiResponse process(GoApiRequest goPluginApiRequest) { try { String version = goPluginApiRequest.apiVersion(); if (!goSupportedVersions.contains(version)) { throw new RuntimeException( String.format( "Unsupported '%s' API version: %s. Supported versions: %s", AUTHENTICATE_USER_REQUEST, version, goSupportedVersions)); } User user = messageHandlerMap .get(version) .responseMessageForAuthenticateUser(goPluginApiRequest.requestBody()); if (user == null) { throw new RuntimeException( String.format( "Could not parse User details. Request Body: %s", goPluginApiRequest.requestBody())); } GoUserPrinciple goUserPrincipal = getGoUserPrincipal(user); Authentication authentication = getAuthenticationToken(goUserPrincipal); userService.addUserIfDoesNotExist(UserHelper.getUserName(authentication)); getSecurityContext().setAuthentication(authentication); return new DefaultGoApiResponse(200); } catch (Exception e) { LOGGER.error("Error occurred while authenticating user", e); } return new DefaultGoApiResponse(500); }
private String setUpPipelineGroupsWithAdminPermissions() throws IOException { setCurrentUser("ram"); assertThat(CaseInsensitiveString.str(UserHelper.getUserName().getUsername()), is("ram")); configHelper.addPipelineWithGroup("studios", "go", "stage", "build1", "build2"); configHelper.setAdminPermissionForGroup("studios", "barrow"); configHelper.addPipelineWithGroup("consulting", "bcg", "stage", "build1", "build2"); configHelper.setAdminPermissionForGroup("consulting", "ram"); configHelper.addTemplate("newTemplate", "stage"); return goConfigDao.md5OfConfigFile(); }
@RequestMapping(value = "/**/pipelineHistory.json", method = RequestMethod.GET) public ModelAndView list( @RequestParam("pipelineName") String pipelineName, @RequestParam(value = "perPage", required = false) Integer perPageParam, @RequestParam(value = "start", required = false) Integer startParam, HttpServletResponse response, HttpServletRequest request) throws NamingException { PipelineConfig pipelineConfig = goConfigService.pipelineConfigNamed(new CaseInsensitiveString(pipelineName)); String username = CaseInsensitiveString.str(UserHelper.getUserName().getUsername()); Pagination pagination; try { pagination = Pagination.pageStartingAt( startParam, pipelineHistoryService.totalCount(pipelineName), perPageParam); } catch (Exception e) { Map<String, Object> json = new LinkedHashMap<>(); addDeveloperErrorMessage(json, e); return jsonNotAcceptable(json).respond(response); } PipelinePauseInfo pauseInfo = pipelinePauseService.pipelinePauseInfo(pipelineName); boolean hasBuildCauseInBuffer = pipelineScheduleQueue.hasBuildCause(CaseInsensitiveString.str(pipelineConfig.name())); PipelineInstanceModels pipelineHistory = pipelineHistoryService.load(pipelineName, pagination, username, true); boolean hasForcedBuildCause = pipelineScheduleQueue.hasForcedBuildCause(pipelineName); PipelineHistoryJsonPresentationModel historyJsonPresenter = new PipelineHistoryJsonPresentationModel( pauseInfo, pipelineHistory, pipelineConfig, pagination, canForce(pipelineConfig, username), hasForcedBuildCause, hasBuildCauseInBuffer, canPause(pipelineConfig, username)); return jsonFound(historyJsonPresenter.toJson()).respond(response); }