Skip to content
This repository was archived by the owner on Sep 28, 2022. It is now read-only.

Commit 31710bf

Browse files
author
Dominik Frantisek Bucik
committed
fix: 🐛 Fix inserting and reading properties in the stats filter
1 parent 231638c commit 31710bf

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

perun-oidc-server/src/main/java/cz/muni/ics/oidc/server/filters/PerunRequestFilterParams.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ public String getProperty(String name) {
3131
return this.properties.getProperty(propertyPrefix + '.' + name);
3232
}
3333

34+
public String getProperty(String name, String defaultValue) {
35+
if (this.properties.containsKey(propertyPrefix + '.' + name)) {
36+
return this.properties.getProperty(propertyPrefix + '.' + name);
37+
}
38+
return defaultValue;
39+
}
40+
3441
public BeanUtil getBeanUtil() {
3542
return beanUtil;
3643
}

perun-oidc-server/src/main/java/cz/muni/ics/oidc/server/filters/impl/ProxyStatisticsFilter.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,16 @@ public ProxyStatisticsFilter(PerunRequestFilterParams params) {
8383
this.mitreIdStats = beanUtil.getBean("mitreIdStats", DataSource.class);
8484
this.samlProperties = beanUtil.getBean(SamlProperties.class);
8585

86-
Properties props = params.getProperties();
87-
this.idpNameAttributeName = props.getProperty(IDP_NAME_ATTRIBUTE_NAME,
86+
this.idpNameAttributeName = params.getProperty(IDP_NAME_ATTRIBUTE_NAME,
8887
"urn:cesnet:proxyidp:attribute:sourceIdPName");
89-
this.idpEntityIdAttributeName = props.getProperty(IDP_ENTITY_ID_ATTRIBUTE_NAME,
88+
this.idpEntityIdAttributeName = params.getProperty(IDP_ENTITY_ID_ATTRIBUTE_NAME,
9089
"urn:cesnet:proxyidp:attribute:sourceIdPEntityID");
91-
this.statisticsTableName = props.getProperty(STATISTICS_TABLE_NAME, "statistics_per_user");
92-
this.identityProvidersMapTableName = props.getProperty(IDENTITY_PROVIDERS_MAP_TABLE_NAME, "statistics_idp");
93-
this.serviceProvidersMapTableName = props.getProperty(SERVICE_PROVIDERS_MAP_TABLE_NAME, "statistics_sp");
94-
this.idpIdColumnName = props.getProperty(IDP_ID_COLUMN_NAME, "idpId");
95-
this.spIdColumnName = props.getProperty(SP_ID_COLUMN_NAME, "spId");
96-
this.usernameColumnName = props.getProperty(USERNAME_COLUMN_NAME, "user");
90+
this.statisticsTableName = params.getProperty(STATISTICS_TABLE_NAME, "statistics_per_user");
91+
this.identityProvidersMapTableName = params.getProperty(IDENTITY_PROVIDERS_MAP_TABLE_NAME, "statistics_idp");
92+
this.serviceProvidersMapTableName = params.getProperty(SERVICE_PROVIDERS_MAP_TABLE_NAME, "statistics_sp");
93+
this.idpIdColumnName = params.getProperty(IDP_ID_COLUMN_NAME, "idpId");
94+
this.spIdColumnName = params.getProperty(SP_ID_COLUMN_NAME, "spId");
95+
this.usernameColumnName = params.getProperty(USERNAME_COLUMN_NAME, "user");
9796
this.filterName = params.getFilterName();
9897
}
9998

@@ -156,7 +155,8 @@ private void insertOrUpdateLogin(String idpEntityId, String idpName, String spId
156155
if (spId == null) {
157156
return;
158157
}
159-
log.trace("{} - Extracted IDs for SP and IdP: spId={}, idpId ={}", filterName, spId, idpId);
158+
log.trace("{} - Extracted IDs for SP and IdP: spId={}({}), idpId={}({})",
159+
filterName, spId, spIdentifier, idpId, idpEntityId);
160160
insertOrUpdateLogin(c, idpId, spId, userId);
161161
} catch (SQLException ex) {
162162
log.warn("{} - caught SQLException", filterName);
@@ -177,12 +177,14 @@ private boolean fetchLogin(Connection c, Long idpId, Long spId, String userId) {
177177
String query = "SELECT COUNT(*) AS res FROM " + statisticsTableName +
178178
" WHERE " + idpIdColumnName + " = ?" +
179179
" AND " + spIdColumnName + " = ?" +
180-
" AND " + usernameColumnName + " = ?";
180+
" AND " + usernameColumnName + " = ?" +
181+
" AND day = ?";
181182

182183
try (PreparedStatement ps = c.prepareStatement(query)) {
183184
ps.setLong(1, idpId);
184185
ps.setLong(2, spId);
185186
ps.setString(3, userId);
187+
ps.setDate(4, Date.valueOf(LocalDate.now()));
186188
ResultSet rs = ps.executeQuery();
187189
if (rs.next()) {
188190
return rs.getInt("res") > 0;
@@ -301,7 +303,8 @@ private void insertLogin(Connection c, Long idpId, Long spId, String userId) {
301303
ps.setLong(3, spId);
302304
ps.setString(4, userId);
303305
ps.execute();
304-
log.debug("{} - login inserted", filterName);
306+
log.debug("{} - Inserted first login for combination: idpId={}, spId={}, userId={}",
307+
filterName, idpId, spId, userId);
305308
} catch (SQLException ex) {
306309
log.warn("{} - caught SQLException when inserting login entry", filterName);
307310
log.debug("{} - details:", filterName, ex);
@@ -321,8 +324,8 @@ private void updateLogin(Connection c, Long idpId, Long spId, String userId) {
321324
ps.setLong(2, idpId);
322325
ps.setLong(3, spId);
323326
ps.setString(4, userId);
324-
ps.execute();
325-
log.debug("{} - login updated", filterName);
327+
log.debug("{} - Updated login count by 1 for combination: idpId={}, spId={}, userId={}",
328+
filterName, idpId, spId, userId);
326329
} catch (SQLException ex) {
327330
log.warn("{} - caught SQLException when updating login entry", filterName);
328331
log.debug("{} - details:", filterName, ex);

0 commit comments

Comments
 (0)