Skip to content

Commit

Permalink
Combine CERN HR logic with internal life-cycle
Browse files Browse the repository at this point in the history
Update end-time with CERN HR voPerson participation endDate value
  • Loading branch information
enricovianello committed Sep 16, 2024
1 parent ada2c24 commit 21ee0c1
Show file tree
Hide file tree
Showing 11 changed files with 439 additions and 422 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
@Profile("cern")
public interface CernHrDBApiService {

boolean hasValidExperimentParticipation(String personId);

VOPersonDTO getHrDbPersonRecord(String personId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
Expand Down Expand Up @@ -48,7 +47,6 @@ public class DefaultCernHrDBApiService implements CernHrDBApiService {
final RestTemplateFactory rtFactory;
final CernProperties properties;

@Autowired
public DefaultCernHrDBApiService(RestTemplateFactory rtFactory, CernProperties properties) {
this.rtFactory = rtFactory;
this.properties = properties;
Expand All @@ -64,26 +62,6 @@ private HttpHeaders buildAuthHeaders() {
return headers;
}

@Override
public boolean hasValidExperimentParticipation(String personId) {
RestTemplate rt = rtFactory.newRestTemplate();

String personValidUrl = String.format("%s%s", properties.getHrApi().getUrl(),
format(PARTICIPATION_API_PATH_TEMPLATE, properties.getExperimentName(), personId));

LOG.debug("Querying HR db participation API for person {} at URL {}", personId, personValidUrl);

try {

ResponseEntity<Boolean> response = rt.exchange(personValidUrl, HttpMethod.GET,
new HttpEntity<>(buildAuthHeaders()), Boolean.class);
return response.getBody();
} catch (RestClientException e) {
final String errorMsg = "HR db api error: " + e.getMessage();
throw new CernHrDbApiError(errorMsg, e);
}
}

@Override
public VOPersonDTO getHrDbPersonRecord(String personId) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import static it.infn.mw.iam.authn.ExternalAuthenticationHandlerSupport.EXT_AUTHN_UNREGISTERED_USER_AUTH;
import static org.springframework.security.web.context.HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY;
import static org.springframework.web.bind.annotation.RequestMethod.GET;

import java.time.Instant;
import java.util.Date;
Expand All @@ -30,7 +29,7 @@
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.GetMapping;

import it.infn.mw.iam.api.registration.cern.CernHrDBApiService;
import it.infn.mw.iam.api.registration.cern.dto.InstituteDTO;
Expand All @@ -47,7 +46,7 @@ public class MockCernAuthController implements CernHrDBApiService {
@Autowired
CernProperties properties;

@RequestMapping(method = GET, path = "/mock-cern-auth")
@GetMapping("/mock-cern-auth")
public String mockCernAuthentication(HttpSession session) {

OidcSecurityContextBuilder builder = new OidcSecurityContextBuilder();
Expand All @@ -69,11 +68,6 @@ public String mockCernAuthentication(HttpSession session) {
return "redirect:/start-registration";
}

@Override
public boolean hasValidExperimentParticipation(String personId) {
return false;
}

@Override
public VOPersonDTO getHrDbPersonRecord(String personId) {
VOPersonDTO dto = new VOPersonDTO();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
public class ExpiredAccountsHandler implements Runnable {

public enum AccountLifecycleStatus {
OK, PENDING_SUSPENSION, PENDING_REMOVAL, SUSPENDED
PENDING_SUSPENSION, PENDING_REMOVAL, SUSPENDED
}

public static final String LIFECYCLE_TIMESTAMP_LABEL = "lifecycle.timestamp";
Expand Down
Loading

0 comments on commit 21ee0c1

Please sign in to comment.