mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-02-05 22:29:11 +01:00
Encrypt user password via CLI (#2080)
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
package sonia.scm.user.cli;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import org.apache.shiro.authc.credential.PasswordService;
|
||||
import picocli.CommandLine;
|
||||
import sonia.scm.cli.ParentCommand;
|
||||
import sonia.scm.user.User;
|
||||
@@ -39,6 +40,7 @@ class UserConvertToInternalCommand implements Runnable {
|
||||
@CommandLine.Mixin
|
||||
private final UserTemplateRenderer templateRenderer;
|
||||
private final UserManager manager;
|
||||
private final PasswordService passwordService;
|
||||
|
||||
@CommandLine.Parameters(index = "0", paramLabel = "<username>", descriptionKey = "scm.user.username")
|
||||
private String username;
|
||||
@@ -47,9 +49,10 @@ class UserConvertToInternalCommand implements Runnable {
|
||||
private String password;
|
||||
|
||||
@Inject
|
||||
UserConvertToInternalCommand(UserTemplateRenderer templateRenderer, UserManager manager) {
|
||||
UserConvertToInternalCommand(UserTemplateRenderer templateRenderer, UserManager manager, PasswordService passwordService) {
|
||||
this.templateRenderer = templateRenderer;
|
||||
this.manager = manager;
|
||||
this.passwordService = passwordService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -58,7 +61,7 @@ class UserConvertToInternalCommand implements Runnable {
|
||||
|
||||
if (user != null) {
|
||||
user.setExternal(false);
|
||||
user.setPassword(password);
|
||||
user.setPassword(passwordService.encryptPassword(password));
|
||||
manager.modify(user);
|
||||
templateRenderer.render(user);
|
||||
} else {
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
package sonia.scm.user.cli;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import org.apache.shiro.authc.credential.PasswordService;
|
||||
import picocli.CommandLine;
|
||||
import sonia.scm.cli.CommandValidator;
|
||||
import sonia.scm.cli.ParentCommand;
|
||||
@@ -43,6 +44,7 @@ class UserCreateCommand implements Runnable {
|
||||
@CommandLine.Mixin
|
||||
private final CommandValidator validator;
|
||||
private final UserManager manager;
|
||||
private final PasswordService passwordService;
|
||||
|
||||
@CommandLine.Parameters(index = "0", paramLabel = "<username>", descriptionKey = "scm.user.username")
|
||||
private String username;
|
||||
@@ -66,10 +68,11 @@ class UserCreateCommand implements Runnable {
|
||||
@Inject
|
||||
public UserCreateCommand(UserTemplateRenderer templateRenderer,
|
||||
CommandValidator validator,
|
||||
UserManager manager) {
|
||||
UserManager manager, PasswordService passwordService) {
|
||||
this.templateRenderer = templateRenderer;
|
||||
this.validator = validator;
|
||||
this.manager = manager;
|
||||
this.passwordService = passwordService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -84,7 +87,7 @@ class UserCreateCommand implements Runnable {
|
||||
if (password == null) {
|
||||
templateRenderer.renderPasswordError();
|
||||
}
|
||||
newUser.setPassword(password);
|
||||
newUser.setPassword(passwordService.encryptPassword(password));
|
||||
newUser.setActive(!inactive);
|
||||
} else {
|
||||
if (inactive) {
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
package sonia.scm.user.cli;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import org.apache.shiro.authc.credential.PasswordService;
|
||||
import picocli.CommandLine;
|
||||
import sonia.scm.cli.CommandValidator;
|
||||
import sonia.scm.cli.ParentCommand;
|
||||
@@ -43,6 +44,7 @@ class UserModifyCommand implements Runnable {
|
||||
@CommandLine.Mixin
|
||||
private final CommandValidator validator;
|
||||
private final UserManager manager;
|
||||
private final PasswordService passwordService;
|
||||
|
||||
@CommandLine.Parameters(index = "0", paramLabel = "<username>", descriptionKey = "scm.user.username")
|
||||
private String username;
|
||||
@@ -58,10 +60,11 @@ class UserModifyCommand implements Runnable {
|
||||
private String password;
|
||||
|
||||
@Inject
|
||||
UserModifyCommand(UserTemplateRenderer templateRenderer, CommandValidator validator, UserManager manager) {
|
||||
UserModifyCommand(UserTemplateRenderer templateRenderer, CommandValidator validator, UserManager manager, PasswordService passwordService) {
|
||||
this.templateRenderer = templateRenderer;
|
||||
this.validator = validator;
|
||||
this.manager = manager;
|
||||
this.passwordService = passwordService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,7 +81,7 @@ class UserModifyCommand implements Runnable {
|
||||
user.setMail(email);
|
||||
}
|
||||
if (password != null) {
|
||||
user.setPassword(password);
|
||||
user.setPassword(passwordService.encryptPassword(password));
|
||||
}
|
||||
manager.modify(user);
|
||||
templateRenderer.render(user);
|
||||
|
||||
Reference in New Issue
Block a user