blob: 902b635a359f56404c5412f904c3d09948e5d044 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
/*
* Copyright (c) 2004-2013 Eike Stepper (Berlin, Germany) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Eike Stepper - initial API and implementation
*/
package org.eclipse.emf.cdo.server.internal.security.bundle;
import org.eclipse.emf.cdo.server.security.ISecurityManager;
import org.eclipse.emf.cdo.server.security.SecurityManagerUtil;
import org.eclipse.emf.cdo.spi.server.CDOCommand;
import org.eclipse.emf.cdo.spi.server.InternalRepository;
import org.eclipse.net4j.util.factory.ProductCreationException;
/**
* @author Eike Stepper
*/
public class AddUserCommand extends CDOCommand.WithRepository
{
public static final String NAME = "adduser";
public AddUserCommand()
{
super(NAME, "adds a user to the security realm of a repository", parameter("username"), optional("password"));
}
@Override
public void execute(InternalRepository repository, String[] args) throws Exception
{
ISecurityManager securityManager = SecurityManagerUtil.getSecurityManager(repository);
if (securityManager == null)
{
throw new CommandException("Security manager not found for " + repository);
}
String username = args[0];
String password = args[1];
if (password != null)
{
securityManager.addUser(username, password);
}
else
{
securityManager.addUser(username);
}
println("User " + username + " added");
}
/**
* @author Eike Stepper
*/
public static class Factory extends CDOCommand.Factory
{
public Factory()
{
super(NAME);
}
@Override
public CDOCommand create(String description) throws ProductCreationException
{
return new AddUserCommand();
}
}
}
|