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.monitor.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
|
sql = "INSERT INTO grantedauthorityimpl (id,uuid, authority) VALUES (5,'216a56bf-cd1a-43ff-9cb1-039c823c38af', 'ALL.ADMIN')";
|
54
|
datasource.executeUpdate(sql);
|
55
|
|
56
|
//insert useraccount_grantedauthority for user admin
|
57
|
|
58
|
/*sql = "INSERT INTO useraccount_grantedauthorityimpl (UserAccount_id, grantedauthorities_id) VALUES ((SELECT id FROM useraccount WHERE username LIKE 'admin'), 4)";
|
59
|
datasource.executeUpdate(sql);
|
60
|
|
61
|
sql = "INSERT INTO useraccount_grantedauthorityimpl (UserAccount_id, grantedauthorities_id) VALUES ((SELECT id FROM useraccount WHERE username LIKE 'admin'), 3)";
|
62
|
datasource.executeUpdate(sql);
|
63
|
|
64
|
sql = "INSERT INTO useraccount_grantedauthorityimpl (UserAccount_id, grantedauthorities_id) VALUES ((SELECT id FROM useraccount WHERE username LIKE 'admin'), 2)";
|
65
|
datasource.executeUpdate(sql);
|
66
|
|
67
|
sql = "INSERT INTO useraccount_grantedauthorityimpl (UserAccount_id, grantedauthorities_id) VALUES ((SELECT id FROM useraccount WHERE username LIKE 'admin'), 1)";
|
68
|
datasource.executeUpdate(sql);
|
69
|
*/
|
70
|
sql = "INSERT INTO useraccount_grantedauthorityimpl (UserAccount_id, grantedauthorities_id) VALUES ((SELECT id FROM useraccount WHERE username LIKE 'admin'), 5)";
|
71
|
datasource.executeUpdate(sql);
|
72
|
|
73
|
return null;
|
74
|
}
|
75
|
|
76
|
|
77
|
|
78
|
}
|