Skip to content

Commit

Permalink
AUP signature PATCH endpoint accepts signature time as input (#853)
Browse files Browse the repository at this point in the history
Fix issue #852
  • Loading branch information
enricovianello authored Oct 15, 2024
1 parent 3b5dfa5 commit 7be98fa
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -43,6 +45,7 @@
import it.infn.mw.iam.api.aup.error.AupSignatureNotFoundError;
import it.infn.mw.iam.api.aup.model.AupSignatureConverter;
import it.infn.mw.iam.api.aup.model.AupSignatureDTO;
import it.infn.mw.iam.api.aup.model.AupSignaturePatchRequestDTO;
import it.infn.mw.iam.api.common.ErrorDTO;
import it.infn.mw.iam.audit.events.aup.AupSignatureDeletedEvent;
import it.infn.mw.iam.audit.events.aup.AupSignedEvent;
Expand Down Expand Up @@ -71,6 +74,7 @@ public class AupSignatureController {
private final TimeProvider timeProvider;
private final ApplicationEventPublisher eventPublisher;
private final NotificationFactory notificationFactory;

public AupSignatureController(AupSignatureConverter conv, AccountUtils utils,
IamAupSignatureRepository signatureRepo, IamAupRepository aupRepo, TimeProvider timeProvider,
ApplicationEventPublisher publisher, NotificationFactory notificationFactory) {
Expand Down Expand Up @@ -141,16 +145,19 @@ public AupSignatureDTO getSignatureForAccount(@PathVariable String accountId)
@ResponseStatus(value = HttpStatus.CREATED)
@PreAuthorize("#iam.hasScope('iam:admin.write') or #iam.hasDashboardRole('ROLE_ADMIN')")
public AupSignatureDTO updateSignatureForAccount(@PathVariable String accountId,
@RequestBody(required = false) @Validated AupSignaturePatchRequestDTO dto,
Authentication authentication) throws AccountNotFoundException {

Optional<IamAccount> updaterAccount = accountUtils.getAuthenticatedUserAccount();

IamAccount account = accountUtils.getByAccountId(accountId)
.orElseThrow(accountNotFoundException(format(ACCOUNT_NOT_FOUND_FOR_ID_MESSAGE, accountId)));
IamAup aup = aupRepo.findDefaultAup().orElseThrow(aupNotFoundException());
Date now = new Date(timeProvider.currentTimeMillis());

IamAupSignature signature = signatureRepo.createSignatureForAccount(aup, account, now);
Date signatureTime =
dto == null ? new Date(timeProvider.currentTimeMillis()) : dto.getSignatureTime();
IamAupSignature signature =
signatureRepo.createSignatureForAccount(aup, account, signatureTime);

String principal = null;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2016-2021
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package it.infn.mw.iam.api.aup.model;

import java.util.Date;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import it.infn.mw.iam.api.scim.controller.utils.JsonDateSerializer;

public class AupSignaturePatchRequestDTO {

@JsonSerialize(using = JsonDateSerializer.class)
Date signatureTime;

public AupSignaturePatchRequestDTO() {
// empty constructor
}

public void setSignatureTime(Date signatureTime) {
this.signatureTime = signatureTime;
}


public Date getSignatureTime() {
return signatureTime;
}

}
Loading

0 comments on commit 7be98fa

Please sign in to comment.