提交 b46ccfc3 编写于 作者: J Jesse Glick

Merge branch 'security-stable-2.7' into security-stable-2.19

...@@ -279,7 +279,7 @@ public class HudsonPrivateSecurityRealm extends AbstractPasswordBasedSecurityRea ...@@ -279,7 +279,7 @@ public class HudsonPrivateSecurityRealm extends AbstractPasswordBasedSecurityRea
public User createAccountByAdmin(StaplerRequest req, StaplerResponse rsp, String addUserView, String successView) throws IOException, ServletException { public User createAccountByAdmin(StaplerRequest req, StaplerResponse rsp, String addUserView, String successView) throws IOException, ServletException {
checkPermission(Jenkins.ADMINISTER); checkPermission(Jenkins.ADMINISTER);
User u = createAccount(req, rsp, false, addUserView); User u = createAccount(req, rsp, false, addUserView);
if(u != null) { if (u != null && successView != null) {
rsp.sendRedirect(successView); rsp.sendRedirect(successView);
} }
return u; return u;
......
...@@ -42,6 +42,7 @@ import hudson.model.User; ...@@ -42,6 +42,7 @@ import hudson.model.User;
import hudson.security.FullControlOnceLoggedInAuthorizationStrategy; import hudson.security.FullControlOnceLoggedInAuthorizationStrategy;
import hudson.security.HudsonPrivateSecurityRealm; import hudson.security.HudsonPrivateSecurityRealm;
import hudson.security.SecurityRealm; import hudson.security.SecurityRealm;
import hudson.security.csrf.CrumbIssuer;
import hudson.security.csrf.DefaultCrumbIssuer; import hudson.security.csrf.DefaultCrumbIssuer;
import hudson.util.HttpResponses; import hudson.util.HttpResponses;
import hudson.util.PluginServletFilter; import hudson.util.PluginServletFilter;
...@@ -216,7 +217,7 @@ public class SetupWizard extends PageDecorator { ...@@ -216,7 +217,7 @@ public class SetupWizard extends PageDecorator {
* Called during the initial setup to create an admin user * Called during the initial setup to create an admin user
*/ */
@RequirePOST @RequirePOST
public void doCreateAdminUser(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { public HttpResponse doCreateAdminUser(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
Jenkins j = Jenkins.getInstance(); Jenkins j = Jenkins.getInstance();
j.checkPermission(Jenkins.ADMINISTER); j.checkPermission(Jenkins.ADMINISTER);
...@@ -229,7 +230,7 @@ public class SetupWizard extends PageDecorator { ...@@ -229,7 +230,7 @@ public class SetupWizard extends PageDecorator {
admin.delete(); // assume the new user may well be 'admin' admin.delete(); // assume the new user may well be 'admin'
} }
User u = securityRealm.createAccountByAdmin(req, rsp, "/jenkins/install/SetupWizard/setupWizardFirstUser.jelly", req.getContextPath() + "/"); User u = securityRealm.createAccountByAdmin(req, rsp, "/jenkins/install/SetupWizard/setupWizardFirstUser.jelly", null);
if (u != null) { if (u != null) {
if(admin != null) { if(admin != null) {
admin = null; admin = null;
...@@ -248,6 +249,11 @@ public class SetupWizard extends PageDecorator { ...@@ -248,6 +249,11 @@ public class SetupWizard extends PageDecorator {
Authentication a = new UsernamePasswordAuthenticationToken(u.getId(),req.getParameter("password1")); Authentication a = new UsernamePasswordAuthenticationToken(u.getId(),req.getParameter("password1"));
a = securityRealm.getSecurityComponents().manager.authenticate(a); a = securityRealm.getSecurityComponents().manager.authenticate(a);
SecurityContextHolder.getContext().setAuthentication(a); SecurityContextHolder.getContext().setAuthentication(a);
CrumbIssuer crumbIssuer = Jenkins.getInstance().getCrumbIssuer();
JSONObject data = new JSONObject().accumulate("crumbRequestField", crumbIssuer.getCrumbRequestField()).accumulate("crumb", crumbIssuer.getCrumb(req));
return HttpResponses.okJSON(data);
} else {
return HttpResponses.okJSON();
} }
} finally { } finally {
if(admin != null) { if(admin != null) {
...@@ -454,6 +460,7 @@ public class SetupWizard extends PageDecorator { ...@@ -454,6 +460,7 @@ public class SetupWizard extends PageDecorator {
/** /**
* Remove the setupWizard filter, ensure all updates are written to disk, etc * Remove the setupWizard filter, ensure all updates are written to disk, etc
*/ */
@RequirePOST
public HttpResponse doCompleteInstall() throws IOException, ServletException { public HttpResponse doCompleteInstall() throws IOException, ServletException {
completeSetup(); completeSetup();
return HttpResponses.okJSON(); return HttpResponses.okJSON();
......
...@@ -177,7 +177,7 @@ exports.incompleteInstallStatus = function(handler, correlationId) { ...@@ -177,7 +177,7 @@ exports.incompleteInstallStatus = function(handler, correlationId) {
* Call this to complete the installation without installing anything * Call this to complete the installation without installing anything
*/ */
exports.completeInstall = function(handler) { exports.completeInstall = function(handler) {
jenkins.get('/setupWizard/completeInstall', function() { jenkins.post('/setupWizard/completeInstall', {}, function() {
handler.call({ isError: false }); handler.call({ isError: false });
}, { }, {
timeout: pluginManagerErrorTimeoutMillis, timeout: pluginManagerErrorTimeoutMillis,
...@@ -219,7 +219,7 @@ exports.installPluginsDone = function(handler) { ...@@ -219,7 +219,7 @@ exports.installPluginsDone = function(handler) {
* Restart Jenkins * Restart Jenkins
*/ */
exports.restartJenkins = function(handler) { exports.restartJenkins = function(handler) {
jenkins.get('/updateCenter/safeRestart', function() { jenkins.post('/updateCenter/safeRestart', {}, function() {
handler.call({ isError: false }); handler.call({ isError: false });
}, { }, {
timeout: pluginManagerErrorTimeoutMillis, timeout: pluginManagerErrorTimeoutMillis,
......
...@@ -11,8 +11,13 @@ exports.saveFirstUser = function($form, success, error) { ...@@ -11,8 +11,13 @@ exports.saveFirstUser = function($form, success, error) {
jenkins.staplerPost( jenkins.staplerPost(
'/setupWizard/createAdminUser', '/setupWizard/createAdminUser',
$form, $form,
success, { function(response) {
dataType: 'html', var crumbRequestField = response.data.crumbRequestField;
if (crumbRequestField) {
require('window-handle').getWindow().crumb.init(crumbRequestField, response.data.crumb);
}
success(response);
}, {
error: error error: error
}); });
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册