
io.getlime.security.powerauth.rest.api.spring.controller.RecoveryController Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of powerauth-restful-security-spring Show documentation
Show all versions of powerauth-restful-security-spring Show documentation
PowerAuth 2.0 RESTful API Security Additions for Spring
The newest version!
/*
* PowerAuth integration libraries for RESTful API applications, examples and
* related software components
*
* Copyright (C) 2019 Wultra s.r.o.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
package io.getlime.security.powerauth.rest.api.spring.controller;
import io.getlime.security.powerauth.crypto.lib.enums.PowerAuthSignatureTypes;
import io.getlime.security.powerauth.rest.api.model.request.EciesEncryptedRequest;
import io.getlime.security.powerauth.rest.api.model.response.EciesEncryptedResponse;
import io.getlime.security.powerauth.rest.api.spring.annotation.PowerAuth;
import io.getlime.security.powerauth.rest.api.spring.authentication.PowerAuthApiAuthentication;
import io.getlime.security.powerauth.rest.api.spring.exception.PowerAuthAuthenticationException;
import io.getlime.security.powerauth.rest.api.spring.exception.authentication.PowerAuthInvalidRequestException;
import io.getlime.security.powerauth.rest.api.spring.service.RecoveryService;
import io.getlime.security.powerauth.rest.api.spring.util.PowerAuthAuthenticationUtil;
import io.getlime.security.powerauth.rest.api.spring.util.PowerAuthVersionUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Controller implementing recovery related end-points from the PowerAuth
* Standard API.
*
* PowerAuth protocol versions:
*
* - 3.0
* - 3.1
* - 3.2
* - 3.3
*
*
* @author Roman Strobl, [email protected]
*
*/
@RestController
@RequestMapping("/pa/v3/recovery")
public class RecoveryController {
private static final Logger logger = LoggerFactory.getLogger(RecoveryController.class);
private final RecoveryService recoveryService;
/**
* Service constructor.
* @param recoveryService Recovery service.
*/
public RecoveryController(RecoveryService recoveryService) {
this.recoveryService = recoveryService;
}
/**
* Confirm recovery code.
* @param request ECIES encrypted request.
* @param auth PowerAuth API authentication object.
* @return ECIES encrypted response.
* @throws PowerAuthAuthenticationException In case confirm recovery fails.
*/
@PostMapping("confirm")
@PowerAuth(resourceId = "/pa/recovery/confirm", signatureType = {
PowerAuthSignatureTypes.POSSESSION_KNOWLEDGE
})
public EciesEncryptedResponse confirmRecoveryCode(@RequestBody EciesEncryptedRequest request,
PowerAuthApiAuthentication auth) throws PowerAuthAuthenticationException {
if (request == null) {
logger.warn("Invalid request object in confirm recovery");
throw new PowerAuthInvalidRequestException();
}
PowerAuthAuthenticationUtil.checkAuthentication(auth);
PowerAuthVersionUtil.checkUnsupportedVersion(auth.getVersion());
PowerAuthVersionUtil.checkEciesParameters(auth.getVersion(), request);
return recoveryService.confirmRecoveryCode(request, auth);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy