use of de.trustable.ca3s.core.domain.AcmeNonce in project ca3sCore by kuehne-trustable-de.
the class ACMEController method checkNonce.
/**
* @param webStruct
* @throws JoseException
* @throws AcmeProblemException
*/
protected void checkNonce(JsonWebStructure webStruct) throws JoseException, AcmeProblemException {
String reqNonce = jwtUtil.getNonce(webStruct);
List<AcmeNonce> nonceList = nonceRepository.findByNonceValue(reqNonce);
if (nonceList.isEmpty()) {
LOG.debug("Nonce {} not found in database", reqNonce);
final ProblemDetail problem = new ProblemDetail(ACMEUtil.BAD_NONCE, "Nonce not known.", BAD_REQUEST, NO_DETAIL, NO_INSTANCE);
throw new AcmeProblemException(problem);
} else {
nonceRepository.deleteAll(nonceList);
LOG.debug("Nonce found ... and deleted");
}
}
use of de.trustable.ca3s.core.domain.AcmeNonce in project ca3sCore by kuehne-trustable-de.
the class ACMEController method buildNonceHeader.
protected HttpHeaders buildNonceHeader() {
final HttpHeaders additionalHeaders = new HttpHeaders();
AcmeNonce nonce = getNewNonce();
additionalHeaders.set(REPLAY_NONCE_HEADER, nonce.getNonceValue());
return additionalHeaders;
}
use of de.trustable.ca3s.core.domain.AcmeNonce in project ca3sCore by kuehne-trustable-de.
the class AcmeNonceResourceIT method updateAcmeNonce.
@Test
@Transactional
public void updateAcmeNonce() throws Exception {
// Initialize the database
acmeNonceService.save(acmeNonce);
int databaseSizeBeforeUpdate = acmeNonceRepository.findAll().size();
// Update the acmeNonce
AcmeNonce updatedAcmeNonce = acmeNonceRepository.findById(acmeNonce.getId()).get();
// Disconnect from session so that the updates on updatedAcmeNonce are not directly saved in db
em.detach(updatedAcmeNonce);
updatedAcmeNonce.nonceValue(UPDATED_NONCE_VALUE).expiresAt(UPDATED_EXPIRES_AT);
restAcmeNonceMockMvc.perform(put("/api/acme-nonces").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(updatedAcmeNonce))).andExpect(status().isOk());
// Validate the AcmeNonce in the database
List<AcmeNonce> acmeNonceList = acmeNonceRepository.findAll();
assertThat(acmeNonceList).hasSize(databaseSizeBeforeUpdate);
AcmeNonce testAcmeNonce = acmeNonceList.get(acmeNonceList.size() - 1);
assertThat(testAcmeNonce.getNonceValue()).isEqualTo(UPDATED_NONCE_VALUE);
assertThat(testAcmeNonce.getExpiresAt()).isEqualTo(UPDATED_EXPIRES_AT);
}
use of de.trustable.ca3s.core.domain.AcmeNonce in project ca3sCore by kuehne-trustable-de.
the class AcmeNonceResourceIT method createAcmeNonce.
@Test
@Transactional
public void createAcmeNonce() throws Exception {
int databaseSizeBeforeCreate = acmeNonceRepository.findAll().size();
// Create the AcmeNonce
restAcmeNonceMockMvc.perform(post("/api/acme-nonces").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(acmeNonce))).andExpect(status().isCreated());
// Validate the AcmeNonce in the database
List<AcmeNonce> acmeNonceList = acmeNonceRepository.findAll();
assertThat(acmeNonceList).hasSize(databaseSizeBeforeCreate + 1);
AcmeNonce testAcmeNonce = acmeNonceList.get(acmeNonceList.size() - 1);
assertThat(testAcmeNonce.getNonceValue()).isEqualTo(DEFAULT_NONCE_VALUE);
assertThat(testAcmeNonce.getExpiresAt()).isEqualTo(DEFAULT_EXPIRES_AT);
}
use of de.trustable.ca3s.core.domain.AcmeNonce in project ca3sCore by kuehne-trustable-de.
the class ACMEController method getNewNonce.
protected AcmeNonce getNewNonce() {
AcmeNonce nonce = new AcmeNonce();
String nonceRaw = getBase64UrlEncodedRandom(16);
nonce.setNonceValue(nonceRaw.split("=")[0]);
Calendar cal = Calendar.getInstance();
// minus number would decrement the days
cal.add(Calendar.DATE, DEFAULT_NONCE_VALID_DAYS);
nonce.setExpiresAt(DateUtil.asInstant(new Date(cal.getTimeInMillis())));
nonceRepository.save(nonce);
LOG.debug("New Nonce {} created", nonce.getNonceValue());
return nonce;
}
Aggregations