use of ee.ria.xroad.signer.protocol.dto.KeyInfo in project X-Road by nordic-institute.
the class CertificateAuthoritiesApiController method getSubjectFieldDescriptions.
// see reason below
@SuppressWarnings("squid:S3655")
@Override
@PreAuthorize("(hasAuthority('GENERATE_AUTH_CERT_REQ') and " + " (#keyUsageType == T(org.niis.xroad.securityserver.restapi.openapi.model.KeyUsageType).AUTHENTICATION))" + " or (hasAuthority('GENERATE_SIGN_CERT_REQ') and " + "(#keyUsageType == T(org.niis.xroad.securityserver.restapi.openapi.model.KeyUsageType).SIGNING))")
public ResponseEntity<Set<CsrSubjectFieldDescription>> getSubjectFieldDescriptions(String caName, KeyUsageType keyUsageType, String keyId, String encodedMemberId, Boolean isNewMember) {
// squid:S3655 throwing NoSuchElementException if there is no value present is
// fine since keyUsageInfo is mandatory parameter
KeyUsageInfo keyUsageInfo = KeyUsageTypeMapping.map(keyUsageType).get();
// memberId is mandatory for sign csrs
if (keyUsageInfo == KeyUsageInfo.SIGNING) {
if (StringUtils.isBlank(encodedMemberId)) {
throw new BadRequestException("memberId is mandatory for sign csrs");
}
}
try {
if (!StringUtils.isBlank(keyId)) {
// validate that key.usage matches keyUsageType
KeyInfo keyInfo = keyService.getKey(keyId);
if (keyInfo.getUsage() != null) {
if (keyInfo.getUsage() != keyUsageInfo) {
throw new BadRequestException("key is for different usage", new ErrorDeviation("wrong_key_usage"));
}
}
}
ClientId memberId = null;
if (!StringUtils.isBlank(encodedMemberId)) {
memberId = clientConverter.convertId(encodedMemberId);
}
CertificateProfileInfo profileInfo;
profileInfo = certificateAuthorityService.getCertificateProfile(caName, keyUsageInfo, memberId, isNewMember);
Set<CsrSubjectFieldDescription> converted = subjectConverter.convert(profileInfo.getSubjectFields());
return new ResponseEntity<>(converted, HttpStatus.OK);
} catch (WrongKeyUsageException | KeyNotFoundException | ClientNotFoundException e) {
throw new BadRequestException(e);
} catch (CertificateAuthorityNotFoundException e) {
throw new ResourceNotFoundException(e);
} catch (CertificateProfileInstantiationException e) {
throw new InternalServerErrorException(e);
}
}
use of ee.ria.xroad.signer.protocol.dto.KeyInfo in project X-Road by nordic-institute.
the class KeysApiController method updateKey.
@Override
@PreAuthorize("hasAuthority('EDIT_KEY_FRIENDLY_NAME')")
@AuditEventMethod(event = RestApiAuditEvent.UPDATE_KEY_NAME)
public ResponseEntity<Key> updateKey(String id, KeyName keyName) {
KeyInfo keyInfo = null;
try {
keyInfo = keyService.updateKeyFriendlyName(id, keyName.getName());
} catch (KeyNotFoundException e) {
throw new ResourceNotFoundException(e);
} catch (ActionNotPossibleException e) {
throw new ConflictException(e);
}
Key key = keyConverter.convert(keyInfo);
return new ResponseEntity<>(key, HttpStatus.OK);
}
use of ee.ria.xroad.signer.protocol.dto.KeyInfo in project X-Road by nordic-institute.
the class TokensApiController method addKey.
@PreAuthorize("hasAuthority('GENERATE_KEY')")
@Override
@AuditEventMethod(event = RestApiAuditEvent.GENERATE_KEY)
public ResponseEntity<Key> addKey(String tokenId, KeyLabel keyLabel) {
try {
KeyInfo keyInfo = keyService.addKey(tokenId, keyLabel.getLabel());
Key key = keyConverter.convert(keyInfo);
return ControllerUtil.createCreatedResponse("/api/keys/{keyId}", key, key.getId());
} catch (TokenNotFoundException e) {
throw new ResourceNotFoundException(e);
} catch (ActionNotPossibleException e) {
throw new ConflictException(e);
}
}
use of ee.ria.xroad.signer.protocol.dto.KeyInfo in project X-Road by nordic-institute.
the class RegenerateCertRequestRequestHandler method findTokenAndKeyForCsrId.
private TokenAndKey findTokenAndKeyForCsrId(String certRequestId) {
TokenInfoAndKeyId tokenInfoAndKeyId = TokenManager.findTokenAndKeyIdForCertRequestId(certRequestId);
KeyInfo keyInfo = TokenManager.getKeyInfo(tokenInfoAndKeyId.getKeyId());
return new TokenAndKey(tokenInfoAndKeyId.getTokenInfo().getId(), keyInfo);
}
use of ee.ria.xroad.signer.protocol.dto.KeyInfo in project X-Road by nordic-institute.
the class ClientsApiControllerIntegrationTest method createMockTokenInfos.
/**
* @param certificateInfo one certificate to put inside this tokenInfo
* structure
* @return
*/
private List<TokenInfo> createMockTokenInfos(CertificateInfo certificateInfo) {
List<TokenInfo> mockTokens = new ArrayList<>();
List<CertificateInfo> certificates = new ArrayList<>();
if (certificateInfo != null) {
certificates.add(certificateInfo);
}
KeyInfo keyInfo = new KeyInfo(false, null, "friendlyName", "id", "label", "publicKey", certificates, new ArrayList<CertRequestInfo>(), "signMecchanismName");
TokenInfo tokenInfo = new TokenInfo("type", "friendlyName", "id", false, false, false, "serialNumber", "label", -1, null, Arrays.asList(keyInfo), null);
mockTokens.add(tokenInfo);
return mockTokens;
}
Aggregations