Search in sources :

Example 1 with AcmeNonce

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");
    }
}
Also used : ProblemDetail(de.trustable.ca3s.core.service.dto.acme.problem.ProblemDetail) AcmeNonce(de.trustable.ca3s.core.domain.AcmeNonce) AcmeProblemException(de.trustable.ca3s.core.service.dto.acme.problem.AcmeProblemException)

Example 2 with AcmeNonce

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;
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) AcmeNonce(de.trustable.ca3s.core.domain.AcmeNonce)

Example 3 with AcmeNonce

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);
}
Also used : AcmeNonce(de.trustable.ca3s.core.domain.AcmeNonce) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with AcmeNonce

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);
}
Also used : AcmeNonce(de.trustable.ca3s.core.domain.AcmeNonce) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with AcmeNonce

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;
}
Also used : AcmeNonce(de.trustable.ca3s.core.domain.AcmeNonce) Calendar(java.util.Calendar) Date(java.sql.Date)

Aggregations

AcmeNonce (de.trustable.ca3s.core.domain.AcmeNonce)9 Transactional (org.springframework.transaction.annotation.Transactional)3 BadRequestAlertException (de.trustable.ca3s.core.web.rest.errors.BadRequestAlertException)2 Test (org.junit.jupiter.api.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 AcmeProblemException (de.trustable.ca3s.core.service.dto.acme.problem.AcmeProblemException)1 ProblemDetail (de.trustable.ca3s.core.service.dto.acme.problem.ProblemDetail)1 URI (java.net.URI)1 Date (java.sql.Date)1 Calendar (java.util.Calendar)1 HttpHeaders (org.springframework.http.HttpHeaders)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1