use of ee.ria.xroad.common.CodedException in project X-Road by nordic-institute.
the class AbstractTimestampRequest method getTimestampDer.
protected byte[] getTimestampDer(TimeStampResponse tsResponse) throws Exception {
X509Certificate signerCertificate = TimestampVerifier.getSignerCertificate(tsResponse.getTimeStampToken(), GlobalConf.getTspCertificates());
if (signerCertificate == null) {
throw new CodedException(X_INTERNAL_ERROR, "Could not find signer certificate");
}
TimeStampToken token = addSignerCertificate(tsResponse, signerCertificate);
return token.getEncoded();
}
use of ee.ria.xroad.common.CodedException in project X-Road by nordic-institute.
the class GenerateSelfSignedCertRequestHandler method handle.
@Override
protected Object handle(GenerateSelfSignedCert message) throws Exception {
TokenAndKey tokenAndKey = TokenManager.findTokenAndKey(message.getKeyId());
if (!TokenManager.isKeyAvailable(tokenAndKey.getKeyId())) {
throw keyNotAvailable(tokenAndKey.getKeyId());
}
if (tokenAndKey.getKey().getPublicKey() == null) {
throw new CodedException(X_INTERNAL_ERROR, "Key '%s' has no public key", message.getKeyId());
}
PublicKey pk = readX509PublicKey(decodeBase64(tokenAndKey.getKey().getPublicKey()));
String signAlgoId = CryptoUtils.getSignatureAlgorithmId(SIGNATURE_DIGEST_ALGORITHM, tokenAndKey.getSignMechanism());
X509Certificate cert = new DummyCertBuilder().build(tokenAndKey, message, pk, signAlgoId);
byte[] certData = cert.getEncoded();
importCert(new ImportCert(certData, CertificateInfo.STATUS_REGISTERED, message.getMemberId()));
return new GenerateSelfSignedCertResponse(certData);
}
use of ee.ria.xroad.common.CodedException in project X-Road by nordic-institute.
the class AbstractGenerateCertRequest method buildSignedCertRequest.
PKCS10CertificationRequest buildSignedCertRequest(TokenAndKey tokenAndKey, String subjectName) throws Exception {
if (tokenAndKey.getKey().getPublicKey() == null) {
throw new CodedException(X_INTERNAL_ERROR, "Key '%s' has no public key", tokenAndKey.getKeyId());
}
PublicKey publicKey = readPublicKey(tokenAndKey.getKey().getPublicKey());
JcaPKCS10CertificationRequestBuilder certRequestBuilder = new JcaPKCS10CertificationRequestBuilder(new X500Name(subjectName), publicKey);
ContentSigner signer = new TokenContentSigner(tokenAndKey, this);
PKCS10CertificationRequest request = certRequestBuilder.build(signer);
return request;
}
use of ee.ria.xroad.common.CodedException in project X-Road by nordic-institute.
the class ExceptionTranslator method toResponseEntity.
/**
* Create ResponseEntity<ErrorInfo> from an Exception.
* Use provided status or override it with value from
* Exception's ResponseStatus annotation if one exists
* @param e
* @param defaultStatus
* @return
*/
public ResponseEntity<ErrorInfo> toResponseEntity(Exception e, HttpStatus defaultStatus) {
HttpStatus status = getAnnotatedResponseStatus(e, defaultStatus);
ErrorInfo errorDto = new ErrorInfo();
errorDto.setStatus(status.value());
if (e instanceof DeviationAware) {
// add information about errors and warnings
DeviationAware errorCodedException = (DeviationAware) e;
if (errorCodedException.getErrorDeviation() != null) {
errorDto.setError(convert(errorCodedException.getErrorDeviation()));
}
if (errorCodedException.getWarningDeviations() != null) {
for (Deviation warning : errorCodedException.getWarningDeviations()) {
errorDto.addWarningsItem(convert(warning));
}
}
} else if (e instanceof CodedException) {
// map fault code and string from core CodedException
CodedException c = (CodedException) e;
Deviation deviation = new Deviation(CORE_CODED_EXCEPTION_PREFIX + c.getFaultCode(), c.getFaultString());
errorDto.setError(convert(deviation));
} else if (e instanceof MethodArgumentNotValidException) {
errorDto.setError(validationErrorHelper.createError((MethodArgumentNotValidException) e));
}
return new ResponseEntity<>(errorDto, status);
}
use of ee.ria.xroad.common.CodedException in project X-Road by nordic-institute.
the class HibernateUtil method getSessionFactory.
/**
* Returns the session factory for the given session factory name.
* If the session factory has not been already created, it is created and stored in the cache.
*
* @param name the name of the session factory
* @param interceptor the interceptor to use on sessions created with this factory
* @return the session factory
*/
public static synchronized SessionFactory getSessionFactory(String name, Interceptor interceptor) {
if (sessionFactoryCache.containsKey(name)) {
return sessionFactoryCache.get(name).getSessionFactory();
} else {
try {
SessionFactoryCtx ctx = createSessionFactoryCtx(name, interceptor);
sessionFactoryCache.put(name, ctx);
return ctx.getSessionFactory();
} catch (Exception e) {
log.error("Failed to create session factory", e);
throw new CodedException(X_DATABASE_ERROR, e);
}
}
}
Aggregations