1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package jdbcadmin.core.access;
21
22 import java.util.ArrayList;
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Map;
26
27 /***
28 * Implementation of {@link IConfigurableAuthorizationAccess} with declaration of authorized Tables ans Schemas.
29 * Iems not declared are not authorired.
30 * @author Thomas Recloux (trecloux@norsys.fr)
31 */
32 public class DeclarativeAccessImpl implements IConfigurableAuthorizationAccess {
33
34
35 /***
36 * Map on authorized schemas, key of the map : schema name.
37 */
38 private Map authorizations = new HashMap();
39
40
41 /*** {@inheritDoc} */
42 public void addTable(String aTableName, String aSchemaName) {
43 String nomSchema;
44 if (aSchemaName == null) {
45 nomSchema = "";
46 } else {
47 nomSchema = aSchemaName;
48 }
49 SchemaAuthorization schemaAuthorization = (SchemaAuthorization) authorizations.get(nomSchema);
50 schemaAuthorization.addTable(aTableName);
51 }
52
53 /*** {@inheritDoc} */
54 public void addSchema(String aSchemaName, boolean aAutorisationTotale) {
55 String nomSchema;
56 if (aSchemaName == null) {
57 nomSchema = "";
58 } else {
59 nomSchema = aSchemaName;
60 }
61 SchemaAuthorization schema = new SchemaAuthorization();
62 schema.setCompletelyAuthorized(aAutorisationTotale);
63 authorizations.put(nomSchema, schema);
64 }
65
66 /*** {@inheritDoc} */
67 public boolean isTableAuthorized(String aTableName, String aSchemaName) {
68 String nomSchema;
69 if (aSchemaName == null) {
70 nomSchema = "";
71 } else {
72 nomSchema = aSchemaName;
73 }
74
75 SchemaAuthorization schemaAuthorization = (SchemaAuthorization) authorizations.get(nomSchema);
76 if (schemaAuthorization != null) {
77 return schemaAuthorization.isTableAuthorized(aTableName);
78 } else {
79 return false;
80 }
81 }
82
83 /*** {@inheritDoc} */
84 public boolean isSchemaAuthorized(String aSchemaName) {
85 String nomSchema;
86 if (aSchemaName == null) {
87 nomSchema = "";
88 } else {
89 nomSchema = aSchemaName;
90 }
91
92 SchemaAuthorization schemaAuthorization = (SchemaAuthorization) authorizations.get(nomSchema);
93
94 return schemaAuthorization != null;
95 }
96
97 /***
98 * Represents the schema authorization.
99 * @author Thomas Recloux (trecloux@norsys.fr)
100 */
101 private class SchemaAuthorization {
102 /*** Table list. */
103 private List tables = new ArrayList();
104
105 /*** Indicate wether the schméa is completely authorized. */
106 private boolean completelyAuthorized = false;
107
108 /***
109 * Add authorisation on a table.
110 * @param aTableName table name.
111 */
112 public void addTable(String aTableName) {
113 tables.add(aTableName);
114 }
115
116 /***
117 * Indicate whether the table is authorized.
118 * @param aTableName table name
119 * @return <code>true</code> if authorized, <code>false</code> otherwise.
120 */
121 public boolean isTableAuthorized(String aTableName) {
122 if (completelyAuthorized) {
123 return true;
124 } else {
125 return tables.contains(aTableName);
126 }
127 }
128
129 /***
130 * @return Returns the completelyAuthorized.
131 */
132 public boolean isCompletelyAuthorized() {
133 return completelyAuthorized;
134 }
135
136 /***
137 * @param aCompletelyAuthorized The completelyAuthorized to set.
138 */
139 public void setCompletelyAuthorized(boolean aCompletelyAuthorized) {
140 this.completelyAuthorized = aCompletelyAuthorized;
141 }
142 }
143 }