|
1 |
package eu.etaxonomy.cdm.database.update.permissions;
|
|
2 |
|
|
3 |
import java.sql.SQLException;
|
|
4 |
import java.util.List;
|
|
5 |
|
|
6 |
import eu.etaxonomy.cdm.database.update.SchemaUpdaterStepBase;
|
|
7 |
import eu.etaxonomy.cdm.common.IProgressMonitor;
|
|
8 |
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
|
9 |
import eu.etaxonomy.cdm.database.update.ISchemaUpdaterStep;
|
|
10 |
import eu.etaxonomy.cdm.database.update.v30_31.LanguageLabelUpdater;
|
|
11 |
|
|
12 |
public class PermissionsUpdater extends SchemaUpdaterStepBase implements
|
|
13 |
ISchemaUpdaterStep {
|
|
14 |
|
|
15 |
private static final String stepName = "Update granted authorities and grantedAuthorities_useraccount";
|
|
16 |
|
|
17 |
public static final PermissionsUpdater NewInstance(){
|
|
18 |
return new PermissionsUpdater(stepName);
|
|
19 |
}
|
|
20 |
|
|
21 |
protected PermissionsUpdater(String stepName) {
|
|
22 |
super(stepName);
|
|
23 |
}
|
|
24 |
|
|
25 |
@Override
|
|
26 |
public Integer invoke(ICdmDataSource datasource, IProgressMonitor monitor)
|
|
27 |
throws SQLException {
|
|
28 |
String sql;
|
|
29 |
|
|
30 |
//insert admin into useraccount if not available
|
|
31 |
sql = "INSERT INTO useraccount "+
|
|
32 |
"(id, uuid, accountnonexpired, accountnonlocked, credentialsnonexpired, enabled, password, username) "+
|
|
33 |
"SELECT (SELECT MAX(id)+1 FROM useraccount), '2b78fd58-1179-4e93-a8cb-ff5d2ba50e07', 1, 1, 1, 1, '6d54445d1b1cdc44e668a1e07ee4ab4a', 'admin2' "+
|
|
34 |
"FROM useraccount "+
|
|
35 |
"WHERE (SELECT COUNT(*) FROM useraccount WHERE username LIKE 'admin')=0";
|
|
36 |
|
|
37 |
datasource.executeUpdate(sql);
|
|
38 |
|
|
39 |
//insert granted authorities
|
|
40 |
|
|
41 |
sql = "INSERT INTO grantedauthorityimpl (id,uuid, authority) VALUES (1,'889f9961-8d0f-41a9-95ec-59905b3941bf', 'USER.Edit')";
|
|
42 |
datasource.executeUpdate(sql);
|
|
43 |
|
|
44 |
sql = "INSERT INTO grantedauthorityimpl (id,uuid, authority) VALUES (2,'841a1711-20f1-4209-82df-7944ad2050da', 'USER.Create')";
|
|
45 |
datasource.executeUpdate(sql);
|
|
46 |
|
|
47 |
sql = "INSERT INTO grantedauthorityimpl (id,uuid, authority) VALUES (3,'bb9e2547-1e28-45fd-8c35-d1ceffbfcb36', 'USER.Delete')";
|
|
48 |
datasource.executeUpdate(sql);
|
|
49 |
|
|
50 |
sql = "INSERT INTO grantedauthorityimpl (id,uuid, authority) VALUES (4,'8a61c102-4643-4e81-a3b6-c40d60d2ba99', 'USER.Admin')";
|
|
51 |
datasource.executeUpdate(sql);
|
|
52 |
|
|
53 |
//insert useraccount_grantedauthority for user admin
|
|
54 |
|
|
55 |
sql = "INSERT INTO useraccount_grantedauthorityimpl (UserAccount_id, grantedauthorities_id) VALUES ((SELECT id FROM useraccount WHERE username LIKE 'admin'), 4)";
|
|
56 |
datasource.executeUpdate(sql);
|
|
57 |
|
|
58 |
sql = "INSERT INTO useraccount_grantedauthorityimpl (UserAccount_id, grantedauthorities_id) VALUES ((SELECT id FROM useraccount WHERE username LIKE 'admin'), 3)";
|
|
59 |
datasource.executeUpdate(sql);
|
|
60 |
|
|
61 |
sql = "INSERT INTO useraccount_grantedauthorityimpl (UserAccount_id, grantedauthorities_id) VALUES ((SELECT id FROM useraccount WHERE username LIKE 'admin'), 2)";
|
|
62 |
datasource.executeUpdate(sql);
|
|
63 |
|
|
64 |
sql = "INSERT INTO useraccount_grantedauthorityimpl (UserAccount_id, grantedauthorities_id) VALUES ((SELECT id FROM useraccount WHERE username LIKE 'admin'), 1)";
|
|
65 |
datasource.executeUpdate(sql);
|
|
66 |
return null;
|
|
67 |
}
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
}
|
update script for permission evaluation