3838 * to idp name (depends on DataSource bean mitreIdStats)
3939 * <li><b>filter.[name].serviceProvidersMapTableName</b> - Name of the table with mapping of client_id (SP)
4040 * 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>
4143 * </ul>
4244 *
4345 * @author Dominik Baránek <[email protected] > @@ -52,12 +54,16 @@ public class ProxyStatisticsFilter extends PerunRequestFilter {
5254 private static final String STATISTICS_TABLE_NAME = "statisticsTableName" ;
5355 private static final String IDENTITY_PROVIDERS_MAP_TABLE_NAME = "identityProvidersMapTableName" ;
5456 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" ;
5559
5660 private final String idpNameAttributeName ;
5761 private final String idpEntityIdAttributeName ;
5862 private final String statisticsTableName ;
5963 private final String identityProvidersMapTableName ;
6064 private final String serviceProvidersMapTableName ;
65+ private final String idpIdColumnName ;
66+ private final String spIdColumnName ;
6167 /* END OF CONFIGURATION OPTIONS */
6268
6369 private final DataSource mitreIdStats ;
@@ -73,6 +79,8 @@ public ProxyStatisticsFilter(PerunRequestFilterParams params) {
7379 this .statisticsTableName = params .getProperty (STATISTICS_TABLE_NAME );
7480 this .identityProvidersMapTableName = params .getProperty (IDENTITY_PROVIDERS_MAP_TABLE_NAME );
7581 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 );
7684 this .filterName = params .getFilterName ();
7785 }
7886
@@ -120,8 +128,12 @@ private void insertOrUpdateLogin(String idpEntityId, String idpName, String spId
120128 c = mitreIdStats .getConnection ();
121129 insertOrUpdateIdpMap (c , idpEntityId , idpName );
122130 insertOrUpdateSpMap (c , spIdentifier , spName );
131+
123132 idpId = extractIdpId (c , idpEntityId );
133+ log .trace ("{} - extracted idpId: {}" , filterName , idpId );
134+
124135 spId = extractSpId (c , spIdentifier );
136+ log .trace ("{} - extracted spId: {}" , filterName , spId );
125137 } catch (SQLException ex ) {
126138 log .warn ("{} - caught SQLException" , filterName );
127139 log .debug ("{} - details:" , filterName , ex );
@@ -132,17 +144,18 @@ private void insertOrUpdateLogin(String idpEntityId, String idpName, String spId
132144
133145 try {
134146 insertLogin (date , c , idpId , spId , userId );
147+ log .trace ("{} - login entry inserted ({}, {}, {}, {}, {})" , filterName , idpEntityId , idpName ,
148+ spIdentifier , spName , userId );
135149 } catch (SQLException ex ) {
136150 try {
137151 updateLogin (date , c , idpId , spId , userId );
152+ log .trace ("{} - login entry updated ({}, {}, {}, {}, {})" , filterName , idpEntityId , idpName ,
153+ spIdentifier , spName , userId );
138154 } catch (SQLException e ) {
139155 log .warn ("{} - caught SQLException" , filterName );
140156 log .debug ("{} - details:" , filterName , e );
141157 }
142158 }
143-
144- log .trace ("{} - login entry stored ({}, {}, {}, {}, {})" , filterName , idpEntityId , idpName ,
145- spIdentifier , spName , userId );
146159 }
147160
148161 private int extractSpId (Connection c , String spIdentifier ) throws SQLException {
@@ -170,21 +183,21 @@ private int extractIdpId(Connection c, String idpEntityId) throws SQLException {
170183 private void insertOrUpdateIdpMap (Connection c , String idpEntityId , String idpName ) throws SQLException {
171184 try {
172185 insertIdpMap (c , idpEntityId , idpName );
186+ log .trace ("{} - IdP map entry inserted" , filterName );
173187 } catch (SQLException ex ) {
174188 updateIdpMap (c , idpEntityId , idpName );
189+ log .trace ("{} - IdP map entry updated" , filterName );
175190 }
176-
177- log .trace ("{} - IdP map entry inserted" , filterName );
178191 }
179192
180193 private void insertOrUpdateSpMap (Connection c , String spIdentifier , String idpName ) throws SQLException {
181194 try {
182195 insertSpMap (c , spIdentifier , idpName );
196+ log .trace ("{} - SP map entry inserted" , filterName );
183197 } catch (SQLException ex ) {
184198 updateSpMap (c , spIdentifier , idpName );
199+ log .trace ("{} - SP map entry updated" , filterName );
185200 }
186-
187- log .trace ("{} - SP map entry inserted" , filterName );
188201 }
189202
190203 private String changeParamEncoding (String original ) {
@@ -197,13 +210,13 @@ private String changeParamEncoding(String original) {
197210 }
198211
199212 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 ,
201214 spName , idpEntityId );
202215 }
203216
204217 private void insertLogin (LocalDate date , Connection c , int idpId , int spId , String userId ) throws SQLException {
205218 String insertLoginQuery = "INSERT INTO " + statisticsTableName +
206- "(day, idpId, spId , user, logins)" +
219+ "(day, " + idpIdColumnName + ", " + spIdColumnName + " , user, logins)" +
207220 " VALUES(?, ?, ?, ?, '1')" ;
208221
209222 PreparedStatement preparedStatement = c .prepareStatement (insertLoginQuery );
@@ -216,7 +229,7 @@ private void insertLogin(LocalDate date, Connection c, int idpId, int spId, Stri
216229
217230 private void updateLogin (LocalDate date , Connection c , int idpId , int spId , String userId ) throws SQLException {
218231 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 = ?" ;
220233
221234 PreparedStatement preparedStatement = c .prepareStatement (updateLoginQuery );
222235 preparedStatement .setDate (1 , Date .valueOf (date ));
@@ -227,7 +240,7 @@ private void updateLogin(LocalDate date, Connection c, int idpId, int spId, Stri
227240 }
228241
229242 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)" +
231244 " VALUES (?, ?)" ;
232245
233246 PreparedStatement preparedStatement = c .prepareStatement (insertIdpMapQuery );
@@ -237,7 +250,7 @@ private void insertIdpMap(Connection c, String idpEntityId, String idpName) thro
237250 }
238251
239252 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 = ?" ;
241254
242255 PreparedStatement preparedStatement = c .prepareStatement (updateIdpMapQuery );
243256 preparedStatement .setString (1 , idpName );
@@ -246,7 +259,7 @@ private void updateIdpMap(Connection c, String idpEntityId, String idpName) thro
246259 }
247260
248261 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)" +
250263 " VALUES (?, ?)" ;
251264
252265 try (PreparedStatement preparedStatement = c .prepareStatement (insertSpMapQuery )) {
@@ -257,7 +270,7 @@ private void insertSpMap(Connection c, String spIdentifier, String spName) throw
257270 }
258271
259272 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 = ?" ;
261274
262275 PreparedStatement preparedStatement = c .prepareStatement (updateSpMapQuery );
263276 preparedStatement .setString (1 , idpName );
0 commit comments