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

Commit f85cd5c

Browse files
author
Dominik Frantisek Bucik
committed
refactor: 💡 Removed PerunACR and PerunDeviceACR
Removed models and repositories, removed scheduled tasks tied to these classes. Acr is now instead stored together with the User authentication
1 parent 7155e4a commit f85cd5c

File tree

7 files changed

+1
-524
lines changed

7 files changed

+1
-524
lines changed

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

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import cz.muni.ics.oauth2.model.DeviceCode;
55
import cz.muni.ics.oauth2.model.OAuth2AccessTokenEntity;
66
import cz.muni.ics.oauth2.model.OAuth2RefreshTokenEntity;
7-
import cz.muni.ics.openid.connect.models.Acr;
8-
import cz.muni.ics.openid.connect.models.DeviceCodeAcr;
97
import java.time.Instant;
108
import java.util.Date;
119
import javax.persistence.EntityManager;
@@ -135,38 +133,4 @@ public int clearExpiredDeviceCodes(long timeout) {
135133
return count;
136134
}
137135

138-
public int clearExpiredAcrs(long timeout) {
139-
manager.flush();
140-
manager.clear();
141-
int count = 0;
142-
Query query = manager.createNamedQuery(Acr.DELETE_EXPIRED);
143-
query.setParameter(Acr.PARAM_EXPIRES_AT, Instant.now().toEpochMilli());
144-
if (timeout > 0) {
145-
query.setHint("javax.persistence.query.timeout", timeout);
146-
}
147-
try {
148-
count += query.executeUpdate();
149-
} catch (QueryTimeoutException e) {
150-
// this is OK
151-
}
152-
return count;
153-
}
154-
155-
public int clearExpiredDeviceCodeAcrs(long timeout) {
156-
manager.flush();
157-
manager.clear();
158-
int count = 0;
159-
Query query = manager.createNamedQuery(DeviceCodeAcr.DELETE_EXPIRED);
160-
query.setParameter(DeviceCodeAcr.PARAM_EXPIRES_AT, Instant.now().toEpochMilli());
161-
if (timeout > 0) {
162-
query.setHint("javax.persistence.query.timeout", timeout);
163-
}
164-
try {
165-
count += query.executeUpdate();
166-
} catch (QueryTimeoutException e) {
167-
// this is OK
168-
}
169-
return count;
170-
}
171-
172136
}

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

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -105,34 +105,4 @@ public void clearExpiredDeviceCodes() {
105105
log.info("clearExpiredDeviceCodes took {}ms, deleted {} records", execution, count);
106106
}
107107

108-
@Transactional(value = "defaultTransactionManager")
109-
@Scheduled(fixedDelay = 60 * ONE_MINUTE, initialDelay = 48 * ONE_MINUTE)
110-
@SchedulerLock(name = "clearExpiredAcrs", lockAtMostFor = "3590s", lockAtLeastFor = "3590s")
111-
public void clearExpiredAcrs() {
112-
try {
113-
LockAssert.assertLocked();
114-
} catch (IllegalArgumentException e) {
115-
return;
116-
}
117-
long start = System.currentTimeMillis();
118-
int count = this.customClearTasks.clearExpiredAcrs(TimeUnit.MINUTES.toMillis(15));
119-
long execution = System.currentTimeMillis() - start;
120-
log.info("clearExpiredAcrs took {}ms, deleted {} records", execution, count);
121-
}
122-
123-
@Transactional(value = "defaultTransactionManager")
124-
@Scheduled(fixedDelay = 60 * ONE_MINUTE, initialDelay = 48 * ONE_MINUTE)
125-
@SchedulerLock(name = "clearExpiredDeviceAcrs", lockAtMostFor = "3590s", lockAtLeastFor = "3590s")
126-
public void clearExpiredDeviceAcrs() {
127-
try {
128-
LockAssert.assertLocked();
129-
} catch (IllegalArgumentException e) {
130-
return;
131-
}
132-
long start = System.currentTimeMillis();
133-
int count = this.customClearTasks.clearExpiredAcrs(TimeUnit.MINUTES.toMillis(15));
134-
long execution = System.currentTimeMillis() - start;
135-
log.info("clearExpiredDeviceAcrs took {}ms, deleted {} records", execution, count);
136-
}
137-
138108
}

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

Lines changed: 0 additions & 81 deletions
This file was deleted.

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

Lines changed: 0 additions & 91 deletions
This file was deleted.

perun-oidc-server/src/main/java/cz/muni/ics/oidc/web/controllers/ApproveDeviceController.java

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@
44
import cz.muni.ics.oauth2.model.DeviceCode;
55
import cz.muni.ics.oauth2.service.SystemScopeService;
66
import cz.muni.ics.oauth2.web.DeviceEndpoint;
7-
import cz.muni.ics.oidc.server.PerunDeviceCodeAcrRepository;
87
import cz.muni.ics.oidc.server.PerunScopeClaimTranslationService;
98
import cz.muni.ics.oidc.server.configurations.PerunOidcConfig;
109
import cz.muni.ics.oidc.server.filters.PerunFilterConstants;
1110
import cz.muni.ics.oidc.server.userInfo.PerunUserInfo;
1211
import cz.muni.ics.oidc.web.WebHtmlClasses;
1312
import cz.muni.ics.oidc.web.langs.Localization;
14-
import cz.muni.ics.openid.connect.models.DeviceCodeAcr;
1513
import cz.muni.ics.openid.connect.service.UserInfoService;
1614
import java.security.Principal;
17-
import java.time.Instant;
1815
import java.util.Map;
1916
import javax.servlet.http.HttpServletRequest;
2017
import javax.servlet.http.HttpSession;
@@ -41,7 +38,6 @@ public class ApproveDeviceController {
4138
public static final String DEVICE_APPROVED = "deviceApproved";
4239
public static final String REQUEST_USER_CODE = "requestUserCode";
4340
public static final String USER_CODE = "user_code";
44-
public static final String DEVICE_CODE = "device_code";
4541
public static final String USER_OAUTH_APPROVAL = "user_oauth_approval";
4642
public static final String URL = "devicecode";
4743
public static final String VERIFICATION_URI = "verification_uri";
@@ -59,7 +55,6 @@ public class ApproveDeviceController {
5955
private final WebHtmlClasses htmlClasses;
6056
private final PerunScopeClaimTranslationService scopeClaimTranslationService;
6157
private final UserInfoService userInfoService;
62-
private final PerunDeviceCodeAcrRepository deviceCodeAcrRepository;
6358

6459
@Autowired
6560
public ApproveDeviceController(SystemScopeService scopeService,
@@ -68,8 +63,7 @@ public ApproveDeviceController(SystemScopeService scopeService,
6863
Localization localization,
6964
WebHtmlClasses htmlClasses,
7065
PerunScopeClaimTranslationService scopeClaimTranslationService,
71-
UserInfoService userInfoService,
72-
PerunDeviceCodeAcrRepository perunDeviceCodeAcrRepository)
66+
UserInfoService userInfoService)
7367
{
7468
this.scopeService = scopeService;
7569
this.deviceEndpoint = deviceEndpoint;
@@ -78,7 +72,6 @@ public ApproveDeviceController(SystemScopeService scopeService,
7872
this.htmlClasses = htmlClasses;
7973
this.scopeClaimTranslationService = scopeClaimTranslationService;
8074
this.userInfoService = userInfoService;
81-
this.deviceCodeAcrRepository = perunDeviceCodeAcrRepository;
8275
}
8376

8477
@RequestMapping(
@@ -96,7 +89,6 @@ public String requestDeviceCodeMFA(@RequestParam(CLIENT_ID) String clientId, @Re
9689
Map<String, Object> response = (Map<String, Object>) model.get(ENTITY);
9790
response.replace(VERIFICATION_URI, response.get(VERIFICATION_URI) + "?" + ACR_VALUES + "=" + acrValues);
9891
response.replace(VERIFICATION_URI_COMPLETE, response.get(VERIFICATION_URI_COMPLETE) + "&" + ACR_VALUES + "=" + acrValues);
99-
storeAcrBase((String) response.get(DEVICE_CODE), (String)response.get(USER_CODE));
10092

10193
return result;
10294
}
@@ -145,10 +137,6 @@ public String readUserCode(@RequestParam(USER_CODE) String userCode,
145137
{
146138
String result = deviceEndpoint.readUserCode(userCode, model, session);
147139
if (result.equals(APPROVE_DEVICE) && !perunOidcConfig.getTheme().equalsIgnoreCase("default")) {
148-
if (StringUtils.hasText(req.getParameter(ACR))) {
149-
storeAcr(req.getParameter(ACR), userCode);
150-
}
151-
152140
return themedApproveDevice(model, p, req);
153141
} else if (result.equals(REQUEST_USER_CODE) && !perunOidcConfig.getTheme().equalsIgnoreCase("default")) {
154142
ControllerUtils.setPageOptions(model, req, localization, htmlClasses, perunOidcConfig);
@@ -189,14 +177,6 @@ public String approveDevice(@RequestParam(USER_CODE) String userCode,
189177
return result;
190178
}
191179

192-
private void storeAcr(String acrValue, String userCode) {
193-
DeviceCodeAcr acr = deviceCodeAcrRepository.getByUserCode(userCode);
194-
acr.setShibAuthnContextClass(acrValue);
195-
long expiresAtEpoch = Instant.now().plusSeconds(600L).toEpochMilli();
196-
acr.setExpiresAt(expiresAtEpoch);
197-
deviceCodeAcrRepository.store(acr);
198-
}
199-
200180
private String themedApproveDevice(ModelMap model, Principal p, HttpServletRequest req) {
201181
model.remove("scopes");
202182
DeviceCode dc = (DeviceCode) model.get("dc");
@@ -210,10 +190,4 @@ private String themedApproveDevice(ModelMap model, Principal p, HttpServletReque
210190
return "themedApproveDevice";
211191
}
212192

213-
private void storeAcrBase(String deviceCode, String userCode) {
214-
DeviceCodeAcr acrBase = new DeviceCodeAcr(deviceCode, userCode);
215-
acrBase.setExpiresAt(Instant.now().plusSeconds(1800).toEpochMilli());
216-
deviceCodeAcrRepository.store(acrBase);
217-
}
218-
219193
}

0 commit comments

Comments
 (0)