|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| package org.globus.cas.impl.databaseAccess; |
|
12 |
| |
|
13 |
| import java.sql.ResultSet; |
|
14 |
| import java.sql.SQLException; |
|
15 |
| import java.sql.Connection; |
|
16 |
| import java.sql.Statement; |
|
17 |
| |
|
18 |
| import org.apache.commons.logging.Log; |
|
19 |
| import org.apache.commons.logging.LogFactory; |
|
20 |
| |
|
21 |
| import org.globus.cas.impl.CasConstants; |
|
22 |
| |
|
23 |
| import org.globus.cas.types.CasObjectData; |
|
24 |
| import org.globus.cas.types.TrustAnchorData; |
|
25 |
| |
|
26 |
| import org.globus.util.I18n; |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| public class TrustAnchorDataHandler { |
|
32 |
| |
|
33 |
| static Log logger = LogFactory.getLog(TrustAnchorData.class.getName() ); |
|
34 |
| |
|
35 |
| private static I18n i18n = |
|
36 |
| I18n.getI18n("org.globus.cas.impl.databaseAccess.errors", |
|
37 |
| TrustAnchorDataHandler.class.getClassLoader()); |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
0
| public static String storeObject(TrustAnchorData dataObject)
|
|
44 |
| throws CasDBException { |
|
45 |
| |
|
46 |
0
| String columnString = "insert into" + CasDBConstants.TABLE_TRUSTANCHOR
|
|
47 |
| + " (" + CasDBConstants.COL_TRUST_NICKNAME + "," |
|
48 |
| + CasDBConstants.COL_AUTHMETHOD + "," |
|
49 |
| + CasDBConstants.COL_AUTHDATA + ") values ('"; |
|
50 |
0
| StringBuffer query = new StringBuffer(columnString);
|
|
51 |
0
| query = query.append(dataObject.getNickname()).append("','")
|
|
52 |
| .append(dataObject.getAuthMethod()).append("','") |
|
53 |
| .append(dataObject.getAuthData()).append("')"); |
|
54 |
0
| CasDBStorage.runUpdateQuery(query.toString());
|
|
55 |
0
| return dataObject.getNickname();
|
|
56 |
| } |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
0
| public static String[] list() throws CasDBException {
|
|
62 |
| |
|
63 |
0
| String query = "select" + CasDBConstants.COL_TRUST_NICKNAME + " from"
|
|
64 |
| + CasDBConstants.TABLE_TRUSTANCHOR; |
|
65 |
0
| return CasDBStorage.runListQuery(query,
|
|
66 |
| CasDBConstants.COL_TRUST_NICKNAME); |
|
67 |
| } |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
0
| public static CasObjectData retrieveObject(String nickname)
|
|
74 |
| throws CasDBException { |
|
75 |
| |
|
76 |
0
| TrustAnchorData returnObject = null;
|
|
77 |
0
| String query = "select * from" + CasDBConstants.TABLE_TRUSTANCHOR
|
|
78 |
| + " where" + CasDBConstants.COL_TRUST_NICKNAME + " = '" |
|
79 |
| + nickname.trim() + "'"; |
|
80 |
0
| Connection connection = CasDBStorage.getDBConnection();
|
|
81 |
0
| Statement statement = null;
|
|
82 |
0
| ResultSet resultSet = null;
|
|
83 |
0
| try {
|
|
84 |
0
| statement = connection.createStatement();
|
|
85 |
0
| resultSet = statement.executeQuery(query);
|
|
86 |
0
| if (resultSet!=null) {
|
|
87 |
0
| if (resultSet.next()) {
|
|
88 |
0
| returnObject = new TrustAnchorData();
|
|
89 |
0
| returnObject.setNickname(
|
|
90 |
| resultSet.getString( |
|
91 |
| CasDBConstants.COL_TRUST_NICKNAME.trim())); |
|
92 |
0
| returnObject.setAuthMethod(
|
|
93 |
| resultSet.getString( |
|
94 |
| CasDBConstants.COL_AUTHMETHOD.trim())); |
|
95 |
0
| returnObject.setAuthData(
|
|
96 |
| resultSet.getString( |
|
97 |
| CasDBConstants.COL_AUTHDATA.trim())); |
|
98 |
| } |
|
99 |
| } |
|
100 |
| } |
|
101 |
| catch (SQLException exp) { |
|
102 |
0
| logger.error(i18n.getMessage("retrieveErr", new Object[] {
|
|
103 |
| "trust anchor", query }), exp); |
|
104 |
0
| throw new CasDBException(i18n.getMessage("retrieveErr",
|
|
105 |
| new Object[] { |
|
106 |
| "trust anchor", |
|
107 |
| exp.getMessage() }), |
|
108 |
| exp); |
|
109 |
| } |
|
110 |
| finally { |
|
111 |
| |
|
112 |
| |
|
113 |
0
| CasDBStorage.returnDBConnection(connection);
|
|
114 |
0
| try {
|
|
115 |
0
| if (resultSet != null)
|
|
116 |
0
| resultSet.close();
|
|
117 |
0
| if (statement != null)
|
|
118 |
0
| statement.close();
|
|
119 |
| } |
|
120 |
| catch (SQLException exp) { |
|
121 |
0
| logger.error(i18n.getMessage("retrieveErrClose",
|
|
122 |
| "trust anchor"), exp); |
|
123 |
0
| throw new CasDBException(i18n.getMessage("retrieveErrClose",
|
|
124 |
| "trust anchor") |
|
125 |
| + exp.getMessage(), exp); |
|
126 |
| } |
|
127 |
| } |
|
128 |
0
| return returnObject;
|
|
129 |
| } |
|
130 |
| |
|
131 |
| |
|
132 |
| |
|
133 |
| |
|
134 |
| |
|
135 |
0
| public static void deleteObject(String nickname) throws CasDBException {
|
|
136 |
| |
|
137 |
| |
|
138 |
| |
|
139 |
0
| if (ObjectGroupDataHandler.isMember(nickname.trim(),
|
|
140 |
| CasConstants.TRUSTANCHOR_SPEC)) { |
|
141 |
0
| String errMesg = i18n.getMessage("memberOfGpErr", new Object[] {
|
|
142 |
| "Trust anchor", nickname.trim(), "object group" }); |
|
143 |
0
| logger.debug(errMesg);
|
|
144 |
0
| throw new CasDBException(errMesg);
|
|
145 |
| } |
|
146 |
0
| String query = "delete from" + CasDBConstants.TABLE_TRUSTANCHOR
|
|
147 |
| + " where" + CasDBConstants.COL_TRUST_NICKNAME + " = '" |
|
148 |
| + nickname.trim() + "'"; |
|
149 |
0
| int result = CasDBStorage.runUpdateQuery(query);
|
|
150 |
0
| if (result <= 0) {
|
|
151 |
0
| String err = i18n.getMessage("trustAnchorDelError", nickname);
|
|
152 |
0
| logger.error(err);
|
|
153 |
0
| throw new CasDBException(err);
|
|
154 |
| } |
|
155 |
| } |
|
156 |
| |
|
157 |
0
| public static String getNickname(String authData, String authMeth)
|
|
158 |
| throws CasDBException { |
|
159 |
| |
|
160 |
0
| logger.debug("authData " + authData + " authMeth " + authMeth);
|
|
161 |
0
| String query = "select" + CasDBConstants.COL_TRUST_NICKNAME + " from"
|
|
162 |
| + CasDBConstants.TABLE_TRUSTANCHOR + " where (" |
|
163 |
| + CasDBConstants.COL_AUTHMETHOD + " ='" + authMeth.trim() |
|
164 |
| + "') and (" + CasDBConstants.COL_AUTHDATA + " ='" |
|
165 |
| + authData.trim() + "')"; |
|
166 |
0
| Connection connection = CasDBStorage.getDBConnection();
|
|
167 |
0
| Statement statement = null;
|
|
168 |
0
| ResultSet resultSet = null;
|
|
169 |
0
| String nickname = null;
|
|
170 |
0
| try {
|
|
171 |
0
| statement = connection.createStatement();
|
|
172 |
0
| resultSet = statement.executeQuery(query);
|
|
173 |
0
| if (resultSet!=null) {
|
|
174 |
0
| if (resultSet.next()) {
|
|
175 |
0
| nickname =
|
|
176 |
| resultSet.getString( |
|
177 |
| CasDBConstants.COL_TRUST_NICKNAME.trim()); |
|
178 |
| } |
|
179 |
| } |
|
180 |
| } |
|
181 |
| catch (SQLException exp) { |
|
182 |
0
| logger.error(i18n.getMessage("retrieveErr", new Object[] {
|
|
183 |
| "trust anchor nickname", query }), exp); |
|
184 |
0
| throw new CasDBException(i18n.getMessage("retrieveErr",
|
|
185 |
| new Object[] { "trust anchor nickname", |
|
186 |
| exp.getMessage() }), exp); |
|
187 |
| } |
|
188 |
| finally { |
|
189 |
| |
|
190 |
| |
|
191 |
0
| CasDBStorage.returnDBConnection(connection);
|
|
192 |
0
| try {
|
|
193 |
0
| if (resultSet != null)
|
|
194 |
0
| resultSet.close();
|
|
195 |
0
| if (statement != null)
|
|
196 |
0
| statement.close();
|
|
197 |
| } |
|
198 |
| catch (SQLException exp) { |
|
199 |
0
| logger.warn(i18n.getMessage("retrieveErrClose",
|
|
200 |
| "trust anchor name"), exp); |
|
201 |
| } |
|
202 |
| } |
|
203 |
0
| return nickname;
|
|
204 |
| } |
|
205 |
| } |