blob: 5a032f38e9cdba728e2ee534554d4901a9a99cc2 (
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) 2012, 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.tests;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.security.Realm;
import org.eclipse.emf.cdo.security.User;
import org.eclipse.emf.cdo.server.security.ISecurityManager;
import org.eclipse.emf.cdo.server.security.SecurityManagerUtil;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTest.CleanRepositoriesAfter;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTest.CleanRepositoriesBefore;
import org.eclipse.emf.cdo.tests.config.impl.RepositoryConfig;
import org.eclipse.emf.cdo.tests.config.impl.SessionConfig;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.net4j.util.security.IPasswordCredentialsProvider;
import org.eclipse.net4j.util.security.PasswordCredentialsProvider;
/**
* @author Eike Stepper
*/
@CleanRepositoriesBefore(reason = "TEST_SECURITY_MANAGER")
@CleanRepositoriesAfter(reason = "TEST_SECURITY_MANAGER")
public class SecurityManagerTest extends AbstractCDOTest
{
private static final String USER_ID = "Stepper";
private static final String PASSWORD = "12345";
public void testCommit() throws Exception
{
ISecurityManager securityManager = startRepository();
securityManager.modify(new ISecurityManager.RealmOperation()
{
public void execute(Realm realm)
{
User user = realm.addUser(USER_ID, PASSWORD);
user.getGroups().add(realm.getGroup("Users"));
user.getRoles().add(realm.getRole("All Objects Writer"));
}
});
CDOSession session = openSession();
CDOTransaction transaction = session.openTransaction();
CDOResource resource = transaction.createResource(getResourcePath("/res"));
resource.getContents().add(getModel1Factory().createProduct1());
transaction.commit();
}
private ISecurityManager startRepository()
{
ISecurityManager securityManager = SecurityManagerUtil.createSecurityManager("/security", getServerContainer());
getTestProperties().put(RepositoryConfig.PROP_TEST_SECURITY_MANAGER, securityManager);
IPasswordCredentialsProvider credentialsProvider = new PasswordCredentialsProvider(USER_ID, PASSWORD);
getTestProperties().put(SessionConfig.PROP_TEST_CREDENTIALS_PROVIDER, credentialsProvider);
getRepository(); // Start repository
return securityManager;
}
}
|