Search in sources :

Example 1 with AcmeAuthorization

use of de.trustable.ca3s.core.domain.AcmeAuthorization in project ca3sCore by kuehne-trustable-de.

the class AuthorizationController method getAuthorization.

@RequestMapping(value = "/{authorizationId}", method = GET, produces = APPLICATION_JSON_VALUE)
public ResponseEntity<?> getAuthorization(@PathVariable final long authorizationId) {
    LOG.info("Received Authorization request 'get' ");
    Enumeration<String> headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String key = (String) headerNames.nextElement();
        String value = request.getHeader(key);
        LOG.debug("header {} : {} ", key, value);
    }
    final HttpHeaders additionalHeaders = buildNonceHeader();
    if (rejectGet) {
        return ResponseEntity.status(HttpStatus.METHOD_NOT_ALLOWED).headers(additionalHeaders).build();
    }
    List<AcmeAuthorization> authList = authorizationRepository.findByAcmeAuthorizationId(authorizationId);
    if (authList.isEmpty()) {
        return ResponseEntity.notFound().headers(additionalHeaders).build();
    } else {
        AcmeAuthorization authDao = authList.get(0);
        // No authentication and check against an account!!!
        AuthorizationResponse authResp = buildAuthResponse(authDao);
        return ResponseEntity.ok().headers(additionalHeaders).body(authResp);
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) AcmeAuthorization(de.trustable.ca3s.core.domain.AcmeAuthorization) AuthorizationResponse(de.trustable.ca3s.core.service.dto.acme.AuthorizationResponse) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with AcmeAuthorization

use of de.trustable.ca3s.core.domain.AcmeAuthorization in project ca3sCore by kuehne-trustable-de.

the class ChallengeController method alignOrderState.

void alignOrderState(AcmeOrder orderDao) {
    if (orderDao.getStatus().equals(AcmeOrderStatus.READY)) {
        LOG.info("order status already '{}', no re-check after challenge state change required", orderDao.getStatus());
        return;
    }
    if (orderDao.getStatus() != AcmeOrderStatus.PENDING) {
        LOG.warn("unexpected order status '{}' (!= Pending), no re-check after challenge state change required", orderDao.getStatus());
        return;
    }
    boolean orderReady = true;
    /*
        * check all authorizations having at least one successfully validated challenge
        */
    for (AcmeAuthorization authDao : orderDao.getAcmeAuthorizations()) {
        boolean authReady = false;
        for (AcmeChallenge challDao : authDao.getChallenges()) {
            if (challDao.getStatus() == ChallengeStatus.VALID) {
                LOG.debug("challenge {} of type {} is valid ", challDao.getChallengeId(), challDao.getType());
                authReady = true;
                break;
            }
        }
        if (authReady) {
            LOG.debug("found valid challenge, authorization id {} is valid ", authDao.getAcmeAuthorizationId());
        } else {
            LOG.debug("no valid challange, authorization id {} and order {} fails ", authDao.getAcmeAuthorizationId(), orderDao.getOrderId());
            orderReady = false;
            break;
        }
    }
    if (orderReady) {
        LOG.debug("order status set to READY");
        orderDao.setStatus(AcmeOrderStatus.READY);
        orderRepository.save(orderDao);
    }
}
Also used : AcmeChallenge(de.trustable.ca3s.core.domain.AcmeChallenge) AcmeAuthorization(de.trustable.ca3s.core.domain.AcmeAuthorization)

Example 3 with AcmeAuthorization

use of de.trustable.ca3s.core.domain.AcmeAuthorization in project ca3sCore by kuehne-trustable-de.

the class ACMEOrderUtil method challengeListfrom.

public List<ACMEChallengeView> challengeListfrom(AcmeOrder acmeOrder) {
    List<ACMEChallengeView> acmeChallengeViewList = new ArrayList<>();
    for (AcmeAuthorization acmeAuthorization : acmeOrder.getAcmeAuthorizations()) {
        for (AcmeChallenge acmeChallenge : acmeAuthorization.getChallenges()) {
            ACMEChallengeView acmeChallengeView = getAcmeChallengeView(acmeAuthorization, acmeChallenge);
            acmeChallengeViewList.add(acmeChallengeView);
        }
    }
    return acmeChallengeViewList;
}
Also used : ACMEChallengeView(de.trustable.ca3s.core.service.dto.ACMEChallengeView) AcmeChallenge(de.trustable.ca3s.core.domain.AcmeChallenge) ArrayList(java.util.ArrayList) AcmeAuthorization(de.trustable.ca3s.core.domain.AcmeAuthorization)

Example 4 with AcmeAuthorization

use of de.trustable.ca3s.core.domain.AcmeAuthorization in project ca3sCore by kuehne-trustable-de.

the class AcmeAuthorizationResourceIT method updateAcmeAuthorization.

@Test
@Transactional
public void updateAcmeAuthorization() throws Exception {
    // Initialize the database
    acmeAuthorizationService.save(acmeAuthorization);
    int databaseSizeBeforeUpdate = acmeAuthorizationRepository.findAll().size();
    // Update the acmeAuthorization
    AcmeAuthorization updatedAcmeAuthorization = acmeAuthorizationRepository.findById(acmeAuthorization.getId()).get();
    // Disconnect from session so that the updates on updatedAcmeAuthorization are not directly saved in db
    em.detach(updatedAcmeAuthorization);
    updatedAcmeAuthorization.acmeAuthorizationId(UPDATED_ACME_AUTHORIZATION_ID).type(UPDATED_TYPE).value(UPDATED_VALUE);
    restAcmeAuthorizationMockMvc.perform(put("/api/acme-authorizations").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(updatedAcmeAuthorization))).andExpect(status().isOk());
    // Validate the AcmeAuthorization in the database
    List<AcmeAuthorization> acmeAuthorizationList = acmeAuthorizationRepository.findAll();
    assertThat(acmeAuthorizationList).hasSize(databaseSizeBeforeUpdate);
    AcmeAuthorization testAcmeAuthorization = acmeAuthorizationList.get(acmeAuthorizationList.size() - 1);
    assertThat(testAcmeAuthorization.getAcmeAuthorizationId()).isEqualTo(UPDATED_ACME_AUTHORIZATION_ID);
    assertThat(testAcmeAuthorization.getType()).isEqualTo(UPDATED_TYPE);
    assertThat(testAcmeAuthorization.getValue()).isEqualTo(UPDATED_VALUE);
}
Also used : AcmeAuthorization(de.trustable.ca3s.core.domain.AcmeAuthorization) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with AcmeAuthorization

use of de.trustable.ca3s.core.domain.AcmeAuthorization in project ca3sCore by kuehne-trustable-de.

the class AcmeAuthorizationResourceIT method createAcmeAuthorization.

@Test
@Transactional
public void createAcmeAuthorization() throws Exception {
    int databaseSizeBeforeCreate = acmeAuthorizationRepository.findAll().size();
    // Create the AcmeAuthorization
    restAcmeAuthorizationMockMvc.perform(post("/api/acme-authorizations").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(acmeAuthorization))).andExpect(status().isCreated());
    // Validate the AcmeAuthorization in the database
    List<AcmeAuthorization> acmeAuthorizationList = acmeAuthorizationRepository.findAll();
    assertThat(acmeAuthorizationList).hasSize(databaseSizeBeforeCreate + 1);
    AcmeAuthorization testAcmeAuthorization = acmeAuthorizationList.get(acmeAuthorizationList.size() - 1);
    assertThat(testAcmeAuthorization.getAcmeAuthorizationId()).isEqualTo(DEFAULT_ACME_AUTHORIZATION_ID);
    assertThat(testAcmeAuthorization.getType()).isEqualTo(DEFAULT_TYPE);
    assertThat(testAcmeAuthorization.getValue()).isEqualTo(DEFAULT_VALUE);
}
Also used : AcmeAuthorization(de.trustable.ca3s.core.domain.AcmeAuthorization) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

AcmeAuthorization (de.trustable.ca3s.core.domain.AcmeAuthorization)11 AcmeChallenge (de.trustable.ca3s.core.domain.AcmeChallenge)3 HttpHeaders (org.springframework.http.HttpHeaders)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ACMEAccount (de.trustable.ca3s.core.domain.ACMEAccount)2 AuthorizationResponse (de.trustable.ca3s.core.service.dto.acme.AuthorizationResponse)2 AcmeProblemException (de.trustable.ca3s.core.service.dto.acme.problem.AcmeProblemException)2 ProblemDetail (de.trustable.ca3s.core.service.dto.acme.problem.ProblemDetail)2 BadRequestAlertException (de.trustable.ca3s.core.web.rest.errors.BadRequestAlertException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 JwtContext (org.jose4j.jwt.consumer.JwtContext)2 Test (org.junit.jupiter.api.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 Transactional (org.springframework.transaction.annotation.Transactional)2 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)2 AcmeOrder (de.trustable.ca3s.core.domain.AcmeOrder)1 Pipeline (de.trustable.ca3s.core.domain.Pipeline)1 ACMEChallengeView (de.trustable.ca3s.core.service.dto.ACMEChallengeView)1 ACMEOrderView (de.trustable.ca3s.core.service.dto.ACMEOrderView)1