38
38
* to idp name (depends on DataSource bean mitreIdStats)
39
39
* <li><b>filter.[name].serviceProvidersMapTableName</b> - Name of the table with mapping of client_id (SP)
40
40
* to client name (depends on DataSource bean mitreIdStats)</li>
41
+ * <li><b>filter.[name].ipdIdColumnName</b> - Name for the column which stores IDs of IdPs in statisticsTable</li>
42
+ * <li><b>filter.[name].spIdColumnName</b> - Name for the column which stores IDs of SPs in statisticsTable</li>
41
43
* </ul>
42
44
*
43
45
* @author Dominik Baránek <baranek@ics.muni.cz>
@@ -52,12 +54,16 @@ public class ProxyStatisticsFilter extends PerunRequestFilter {
52
54
private static final String STATISTICS_TABLE_NAME = "statisticsTableName" ;
53
55
private static final String IDENTITY_PROVIDERS_MAP_TABLE_NAME = "identityProvidersMapTableName" ;
54
56
private static final String SERVICE_PROVIDERS_MAP_TABLE_NAME = "serviceProvidersMapTableName" ;
57
+ private static final String IDP_ID_COLUMN_NAME = "idpIdColumnName" ;
58
+ private static final String SP_ID_COLUMN_NAME = "spIdColumnName" ;
55
59
56
60
private final String idpNameAttributeName ;
57
61
private final String idpEntityIdAttributeName ;
58
62
private final String statisticsTableName ;
59
63
private final String identityProvidersMapTableName ;
60
64
private final String serviceProvidersMapTableName ;
65
+ private final String idpIdColumnName ;
66
+ private final String spIdColumnName ;
61
67
/* END OF CONFIGURATION OPTIONS */
62
68
63
69
private final DataSource mitreIdStats ;
@@ -73,6 +79,8 @@ public ProxyStatisticsFilter(PerunRequestFilterParams params) {
73
79
this .statisticsTableName = params .getProperty (STATISTICS_TABLE_NAME );
74
80
this .identityProvidersMapTableName = params .getProperty (IDENTITY_PROVIDERS_MAP_TABLE_NAME );
75
81
this .serviceProvidersMapTableName = params .getProperty (SERVICE_PROVIDERS_MAP_TABLE_NAME );
82
+ this .idpIdColumnName = params .getProperty (IDP_ID_COLUMN_NAME );
83
+ this .spIdColumnName = params .getProperty (SP_ID_COLUMN_NAME );
76
84
this .filterName = params .getFilterName ();
77
85
}
78
86
@@ -120,8 +128,12 @@ private void insertOrUpdateLogin(String idpEntityId, String idpName, String spId
120
128
c = mitreIdStats .getConnection ();
121
129
insertOrUpdateIdpMap (c , idpEntityId , idpName );
122
130
insertOrUpdateSpMap (c , spIdentifier , spName );
131
+
123
132
idpId = extractIdpId (c , idpEntityId );
133
+ log .trace ("{} - extracted idpId: {}" , filterName , idpId );
134
+
124
135
spId = extractSpId (c , spIdentifier );
136
+ log .trace ("{} - extracted spId: {}" , filterName , spId );
125
137
} catch (SQLException ex ) {
126
138
log .warn ("{} - caught SQLException" , filterName );
127
139
log .debug ("{} - details:" , filterName , ex );
@@ -132,17 +144,18 @@ private void insertOrUpdateLogin(String idpEntityId, String idpName, String spId
132
144
133
145
try {
134
146
insertLogin (date , c , idpId , spId , userId );
147
+ log .trace ("{} - login entry inserted ({}, {}, {}, {}, {})" , filterName , idpEntityId , idpName ,
148
+ spIdentifier , spName , userId );
135
149
} catch (SQLException ex ) {
136
150
try {
137
151
updateLogin (date , c , idpId , spId , userId );
152
+ log .trace ("{} - login entry updated ({}, {}, {}, {}, {})" , filterName , idpEntityId , idpName ,
153
+ spIdentifier , spName , userId );
138
154
} catch (SQLException e ) {
139
155
log .warn ("{} - caught SQLException" , filterName );
140
156
log .debug ("{} - details:" , filterName , e );
141
157
}
142
158
}
143
-
144
- log .trace ("{} - login entry stored ({}, {}, {}, {}, {})" , filterName , idpEntityId , idpName ,
145
- spIdentifier , spName , userId );
146
159
}
147
160
148
161
private int extractSpId (Connection c , String spIdentifier ) throws SQLException {
@@ -170,21 +183,21 @@ private int extractIdpId(Connection c, String idpEntityId) throws SQLException {
170
183
private void insertOrUpdateIdpMap (Connection c , String idpEntityId , String idpName ) throws SQLException {
171
184
try {
172
185
insertIdpMap (c , idpEntityId , idpName );
186
+ log .trace ("{} - IdP map entry inserted" , filterName );
173
187
} catch (SQLException ex ) {
174
188
updateIdpMap (c , idpEntityId , idpName );
189
+ log .trace ("{} - IdP map entry updated" , filterName );
175
190
}
176
-
177
- log .trace ("{} - IdP map entry inserted" , filterName );
178
191
}
179
192
180
193
private void insertOrUpdateSpMap (Connection c , String spIdentifier , String idpName ) throws SQLException {
181
194
try {
182
195
insertSpMap (c , spIdentifier , idpName );
196
+ log .trace ("{} - SP map entry inserted" , filterName );
183
197
} catch (SQLException ex ) {
184
198
updateSpMap (c , spIdentifier , idpName );
199
+ log .trace ("{} - SP map entry updated" , filterName );
185
200
}
186
-
187
- log .trace ("{} - SP map entry inserted" , filterName );
188
201
}
189
202
190
203
private String changeParamEncoding (String original ) {
@@ -197,13 +210,13 @@ private String changeParamEncoding(String original) {
197
210
}
198
211
199
212
private void logUserLogin (String idpEntityId , String spIdentifier , String spName , String userId ) {
200
- log .info ("User identity: {}, service: {}, serviceName: {}, via IdP: {}" , userId , spIdentifier ,
213
+ log .info ("{} - User identity: {}, service: {}, serviceName: {}, via IdP: {}" , filterName , userId , spIdentifier ,
201
214
spName , idpEntityId );
202
215
}
203
216
204
217
private void insertLogin (LocalDate date , Connection c , int idpId , int spId , String userId ) throws SQLException {
205
218
String insertLoginQuery = "INSERT INTO " + statisticsTableName +
206
- "(day, idpId, spId , user, logins)" +
219
+ "(day, " + idpIdColumnName + ", " + spIdColumnName + " , user, logins)" +
207
220
" VALUES(?, ?, ?, ?, '1')" ;
208
221
209
222
PreparedStatement preparedStatement = c .prepareStatement (insertLoginQuery );
@@ -216,7 +229,7 @@ private void insertLogin(LocalDate date, Connection c, int idpId, int spId, Stri
216
229
217
230
private void updateLogin (LocalDate date , Connection c , int idpId , int spId , String userId ) throws SQLException {
218
231
String updateLoginQuery = "UPDATE " + statisticsTableName + " SET logins = logins + 1" +
219
- " WHERE day = ? AND idpId = ? AND spId = ? AND user = ?" ;
232
+ " WHERE day = ? AND " + idpIdColumnName + " = ? AND " + spIdColumnName + " = ? AND user = ?" ;
220
233
221
234
PreparedStatement preparedStatement = c .prepareStatement (updateLoginQuery );
222
235
preparedStatement .setDate (1 , Date .valueOf (date ));
@@ -227,7 +240,7 @@ private void updateLogin(LocalDate date, Connection c, int idpId, int spId, Stri
227
240
}
228
241
229
242
private void insertIdpMap (Connection c , String idpEntityId , String idpName ) throws SQLException {
230
- String insertIdpMapQuery = "INSERT INTO " + identityProvidersMapTableName + "(identifier, name)" +
243
+ String insertIdpMapQuery = "INSERT INTO " + identityProvidersMapTableName + " (identifier, name)" +
231
244
" VALUES (?, ?)" ;
232
245
233
246
PreparedStatement preparedStatement = c .prepareStatement (insertIdpMapQuery );
@@ -237,7 +250,7 @@ private void insertIdpMap(Connection c, String idpEntityId, String idpName) thro
237
250
}
238
251
239
252
private void updateIdpMap (Connection c , String idpEntityId , String idpName ) throws SQLException {
240
- String updateIdpMapQuery = "UPDATE " + identityProvidersMapTableName + "SET name = ? WHERE identifier = ?" ;
253
+ String updateIdpMapQuery = "UPDATE " + identityProvidersMapTableName + " SET name = ? WHERE identifier = ?" ;
241
254
242
255
PreparedStatement preparedStatement = c .prepareStatement (updateIdpMapQuery );
243
256
preparedStatement .setString (1 , idpName );
@@ -246,7 +259,7 @@ private void updateIdpMap(Connection c, String idpEntityId, String idpName) thro
246
259
}
247
260
248
261
private void insertSpMap (Connection c , String spIdentifier , String spName ) throws SQLException {
249
- String insertSpMapQuery = "INSERT INTO " + serviceProvidersMapTableName + "(identifier, name)" +
262
+ String insertSpMapQuery = "INSERT INTO " + serviceProvidersMapTableName + " (identifier, name)" +
250
263
" VALUES (?, ?)" ;
251
264
252
265
try (PreparedStatement preparedStatement = c .prepareStatement (insertSpMapQuery )) {
@@ -257,7 +270,7 @@ private void insertSpMap(Connection c, String spIdentifier, String spName) throw
257
270
}
258
271
259
272
private void updateSpMap (Connection c , String spIdentifier , String idpName ) throws SQLException {
260
- String updateSpMapQuery = "UPDATE " + serviceProvidersMapTableName + "SET name = ? WHERE identifier = ?" ;
273
+ String updateSpMapQuery = "UPDATE " + serviceProvidersMapTableName + " SET name = ? WHERE identifier = ?" ;
261
274
262
275
PreparedStatement preparedStatement = c .prepareStatement (updateSpMapQuery );
263
276
preparedStatement .setString (1 , idpName );
0 commit comments