use of ee.ria.xroad.common.CodedException in project X-Road by nordic-institute.
the class TokenService method activateToken.
/**
* Activate a token
*
* @param id id of token
* @param password password for token
* @throws TokenNotFoundException if token was not found
* @throws PinIncorrectException if token login failed due to wrong ping
* @throws ActionNotPossibleException if token activation was not possible
*/
public void activateToken(String id, char[] password) throws TokenNotFoundException, PinIncorrectException, ActionNotPossibleException {
// check that action is possible
TokenInfo tokenInfo = getToken(id);
auditDataHelper.put(tokenInfo);
possibleActionsRuleEngine.requirePossibleTokenAction(PossibleActionEnum.TOKEN_ACTIVATE, tokenInfo);
try {
signerProxyFacade.activateToken(id, password);
} catch (CodedException e) {
if (isCausedByTokenNotFound(e)) {
throw new TokenNotFoundException(e);
} else if (isCausedByIncorrectPin(e)) {
throw new PinIncorrectException(e);
} else {
throw e;
}
} catch (Exception other) {
throw new SignerNotReachableException("token activation failed", other);
}
}
use of ee.ria.xroad.common.CodedException in project X-Road by nordic-institute.
the class ConfigurationDownloader method verifyContent.
void verifyContent(byte[] content, ConfigurationFile file) throws Exception {
String algoId = getAlgorithmId(file.getHashAlgorithmId());
log.trace("verifyContent({}, {})", file.getHash(), algoId);
DigestCalculator dc = createDigestCalculator(algoId);
dc.getOutputStream().write(content);
byte[] hash = dc.getDigest();
if (!Arrays.equals(hash, decodeBase64(file.getHash()))) {
log.trace("Content {} hash {} does not match expected hash {}", new Object[] { file, encodeBase64(hash), file.getHash() });
throw new CodedException(X_IO_ERROR, "Failed to verify content integrity (%s)", file);
}
}
use of ee.ria.xroad.common.CodedException in project X-Road by nordic-institute.
the class CachingServerConfImpl method isSslAuthentication.
@Override
public boolean isSslAuthentication(ServiceId service) {
Optional<ServiceType> serviceTypeOptional = getService(service);
if (!serviceTypeOptional.isPresent()) {
throw new CodedException(X_UNKNOWN_SERVICE, "Service '%s' not found", service);
}
ServiceType serviceType = serviceTypeOptional.get();
return (boolean) ObjectUtils.defaultIfNull(serviceType.getSslAuthentication(), true);
}
use of ee.ria.xroad.common.CodedException in project X-Road by nordic-institute.
the class ManagementRequestSender method getResponse.
private static SoapMessageImpl getResponse(HttpSender sender, String expectedContentType) throws Exception {
String baseContentType = getBaseContentType(sender.getResponseContentType());
if (baseContentType == null || !baseContentType.equalsIgnoreCase(expectedContentType)) {
throw new CodedException(X_HTTP_ERROR, "Unexpected or no content type (%s) in response", baseContentType);
}
Soap response = new SoapParserImpl().parse(baseContentType, sender.getResponseContent());
if (response instanceof SoapFault) {
// Server responded with fault
throw ((SoapFault) response).toCodedException();
}
if (!(response instanceof SoapMessageImpl)) {
throw new CodedException(X_INTERNAL_ERROR, "Got unexpected response message " + response);
}
SoapMessageImpl responseMessage = (SoapMessageImpl) response;
if (!responseMessage.isResponse()) {
throw new CodedException(X_INTERNAL_ERROR, "Expected response message");
}
return responseMessage;
}
use of ee.ria.xroad.common.CodedException in project X-Road by nordic-institute.
the class KeyService method unregisterAuthCert.
/**
* Unregister one auth cert
*/
private void unregisterAuthCert(CertificateInfo certificateInfo) throws GlobalConfOutdatedException {
// this permission is not checked by unregisterCertificate()
securityHelper.verifyAuthority("SEND_AUTH_CERT_DEL_REQ");
try {
// management request to unregister / delete
managementRequestSenderService.sendAuthCertDeletionRequest(certificateInfo.getCertificateBytes());
// update status
signerProxyFacade.setCertStatus(certificateInfo.getId(), CertificateInfo.STATUS_DELINPROG);
} catch (GlobalConfOutdatedException | CodedException e) {
throw e;
} catch (Exception e) {
throw new SignerNotReachableException("Could not unregister auth cert", e);
}
}
Aggregations