Skip to content

Commit 71f4ddf

Browse files
committed
Use synchronized method for initial admin account creation
1 parent 96eb2d8 commit 71f4ddf

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

core/src/main/java/hudson/security/HudsonPrivateSecurityRealm.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -356,30 +356,25 @@ private String getErrorMessages(SignupInfo si) {
356356
return messages.toString();
357357
}
358358

359-
/**
360-
* Lock used to make initial admin account creation atomic.
361-
*/
362-
private static final Object CREATE_FIRST_ACCOUNT_LOCK = new Object();
363-
364359
/**
365360
* Creates a first admin user account.
366361
*
367362
* <p>
368363
* This can be run by anyone, but only to create the very first user account.
369364
*/
370365
@RequirePOST
371-
public void doCreateFirstAccount(StaplerRequest2 req, StaplerResponse2 rsp)
366+
public synchronized void doCreateFirstAccount(StaplerRequest2 req, StaplerResponse2 rsp)
372367
throws IOException, ServletException {
373-
synchronized (CREATE_FIRST_ACCOUNT_LOCK) {
374-
if (hasSomeUser()) {
375-
rsp.sendError(SC_UNAUTHORIZED, "First user was already created");
376-
return;
377-
}
378-
User u = createAccount(req, rsp, false, "firstUser.jelly");
379-
if (u != null) {
380-
tryToMakeAdmin(u);
381-
loginAndTakeBack(req, rsp, u);
382-
}
368+
369+
if (hasSomeUser()) {
370+
rsp.sendError(SC_UNAUTHORIZED, "First user was already created");
371+
return;
372+
}
373+
374+
User u = createAccount(req, rsp, false, "firstUser.jelly");
375+
if (u != null) {
376+
tryToMakeAdmin(u);
377+
loginAndTakeBack(req, rsp, u);
383378
}
384379
}
385380

0 commit comments

Comments
 (0)