use of com.palantir.stash.stashbot.persistence.JenkinsServerConfiguration.AuthenticationMode in project stashbot by palantir.
the class JenkinsConfigurationServlet method doGet.
@Override
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
// Authenticate user
try {
permissionValidationService.validateAuthenticated();
} catch (AuthorisationException notLoggedInException) {
log.debug("User not logged in, redirecting to login page");
// not logged in, redirect
res.sendRedirect(lup.getLoginUri(getUri(req)).toASCIIString());
return;
}
log.debug("User {} logged in", req.getRemoteUser());
try {
permissionValidationService.validateForGlobal(Permission.SYS_ADMIN);
} catch (AuthorisationException notAdminException) {
log.warn("User {} is not a system administrator", req.getRemoteUser());
res.sendError(HttpServletResponse.SC_UNAUTHORIZED, "You do not have permission to access this page.");
return;
}
// Handle deletes
String pathInfo = req.getPathInfo();
String relUrl = req.getRequestURL().toString();
relUrl = relUrl.replaceAll("/+$", "").replaceAll("/delete/?.*$", "").replaceAll("/reload-all/?.*$", "").replaceAll("/create-new/?.*$", "").replaceAll("\\?notice=.*$", "").replaceAll("\\?error=.*$", "");
String[] parts = pathInfo.replaceFirst(PATH_PREFIX, "").split("/");
if (parts.length >= 2) {
if (parts[1].equals("delete")) {
log.info("Deleting configuration " + parts[2]);
configurationPersistanceManager.deleteJenkinsServerConfiguration(parts[2]);
res.sendRedirect(relUrl);
return;
}
if (parts[1].equals("reload-all")) {
jenkinsManager.updateAllJobs();
res.sendRedirect(relUrl);
}
if (parts[1].equals("create-new")) {
jenkinsManager.createMissingJobs();
res.sendRedirect(relUrl);
}
}
String error = req.getParameter("error");
if (error == null) {
error = new String();
}
String notice = req.getParameter("notice");
if (notice == null) {
notice = new String();
}
res.setContentType("text/html;charset=UTF-8");
try {
// Build select data for authentication modes
// Structure is: { "jenkinsServerName" => [ { "text" => "auth description", "value" => "auth code" }, { ... } ], ... }
ImmutableMap.Builder<String, ImmutableList<ImmutableMap<String, String>>> authDataBuilder = ImmutableMap.builder();
ImmutableMap.Builder<String, String> authDataSelectedBuilder = ImmutableMap.builder();
for (JenkinsServerConfiguration jsc : configurationPersistanceManager.getAllJenkinsServerConfigurations()) {
AuthenticationMode am = jsc.getAuthenticationMode();
ImmutableList<ImmutableMap<String, String>> selectList = AuthenticationMode.getSelectList(am);
authDataBuilder.put(jsc.getName(), selectList);
// For convenience, store the value of the selected field in a separate map
authDataSelectedBuilder.put(jsc.getName(), jsc.getAuthenticationMode().getSelectListEntry(false).get("value"));
}
pageBuilderService.assembler().resources().requireContext("plugin.page.stashbot");
ImmutableCollection<JenkinsServerConfiguration> jenkinsConfigs = configurationPersistanceManager.getAllJenkinsServerConfigurations();
soyTemplateRenderer.render(res.getWriter(), "com.palantir.stash.stashbot:stashbotConfigurationResources", "plugin.page.stashbot.jenkinsConfigurationPanel", ImmutableMap.<String, Object>builder().put("relUrl", relUrl).put("jenkinsConfigs", jenkinsConfigs).put("error", error).put("notice", notice).put("authenticationModeData", authDataBuilder.build()).put("authenticationModeDataSelected", authDataSelectedBuilder.build()).build());
} catch (SoyException e) {
Throwable cause = e.getCause();
if (cause instanceof IOException) {
throw (IOException) cause;
} else {
throw new ServletException(e);
}
} catch (SQLException e) {
throw new ServletException(e);
}
}
use of com.palantir.stash.stashbot.persistence.JenkinsServerConfiguration.AuthenticationMode in project stashbot by palantir.
the class ConfigurationPersistenceImpl method setJenkinsServerConfigurationFromRequest.
/* (non-Javadoc)
* @see com.palantir.stash.stashbot.config.ConfigurationPersistenceService#setJenkinsServerConfigurationFromRequest(javax.servlet.http.HttpServletRequest)
*/
@Override
public void setJenkinsServerConfigurationFromRequest(HttpServletRequest req) throws SQLException, NumberFormatException {
String name = req.getParameter("name");
String url = req.getParameter("url");
String username = req.getParameter("username");
String password = req.getParameter("password");
AuthenticationMode am = AuthenticationMode.fromMode(req.getParameter("authenticationMode"));
String stashUsername = req.getParameter("stashUsername");
String stashPassword = req.getParameter("stashPassword");
Integer maxVerifyChain = Integer.parseInt(req.getParameter("maxVerifyChain"));
String lockStr = req.getParameter("locked");
Boolean isLocked = (lockStr == null || !lockStr.equals("on")) ? false : true;
setJenkinsServerConfiguration(name, url, username, password, am, stashUsername, stashPassword, maxVerifyChain, isLocked);
}
Aggregations