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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
/*
* Copyright (c) 2013, 2015 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;
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;
/**
* @author Eike Stepper
*/
public abstract class SecurityManagerCommand extends CDOCommand.WithRepository
{
public SecurityManagerCommand(String name, String description, CommandParameter... parameters)
{
super(name, description, parameters);
}
public SecurityManagerCommand(String name, String description)
{
super(name, description);
}
@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);
}
execute(securityManager, args);
}
protected abstract void execute(ISecurityManager securityManager, String[] args);
/**
* @author Eike Stepper
*/
public static final class AddUser extends SecurityManagerCommand
{
public AddUser()
{
super("adduser", "adds a user to the security realm of a repository", parameter("username"), optional("password"));
}
@Override
protected void execute(ISecurityManager securityManager, String[] args)
{
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 final class SetPassword extends SecurityManagerCommand
{
public SetPassword()
{
super("setpassword", "sets or unsets the password of a repository user", parameter("username"), optional("password"));
}
@Override
protected void execute(ISecurityManager securityManager, String[] args)
{
String username = args[0];
String password = args[1];
securityManager.setPassword(username, password);
println("Password of user " + username + (password != null ? " set" : " unset"));
}
}
}
|