Search in sources :

Example 46 with TokenInfo

use of ee.ria.xroad.signer.protocol.dto.TokenInfo in project X-Road by nordic-institute.

the class PossibleActionsRuleEngineTest method getPossibleCertificateActionUnregister.

@Test
public void getPossibleCertificateActionUnregister() {
    TokenInfo tokenInfo = new TokenTestUtils.TokenInfoBuilder().build();
    assertTrue(possibleActionsRuleEngine.getPossibleCertificateActions(tokenInfo, new TokenTestUtils.KeyInfoBuilder().keyUsageInfo(KeyUsageInfo.AUTHENTICATION).build(), new CertificateTestUtils.CertificateInfoBuilder().certificateStatus(CertificateInfo.STATUS_REGINPROG).build()).contains(PossibleActionEnum.UNREGISTER));
    assertFalse(possibleActionsRuleEngine.getPossibleCertificateActions(tokenInfo, new TokenTestUtils.KeyInfoBuilder().keyUsageInfo(KeyUsageInfo.AUTHENTICATION).build(), new CertificateTestUtils.CertificateInfoBuilder().certificateStatus(CertificateInfo.STATUS_SAVED).build()).contains(PossibleActionEnum.UNREGISTER));
    assertFalse(possibleActionsRuleEngine.getPossibleCertificateActions(tokenInfo, new TokenTestUtils.KeyInfoBuilder().keyUsageInfo(KeyUsageInfo.SIGNING).build(), new CertificateTestUtils.CertificateInfoBuilder().certificateStatus(CertificateInfo.STATUS_REGINPROG).build()).contains(PossibleActionEnum.UNREGISTER));
}
Also used : CertificateTestUtils(org.niis.xroad.securityserver.restapi.util.CertificateTestUtils) TokenInfo(ee.ria.xroad.signer.protocol.dto.TokenInfo) TokenTestUtils(org.niis.xroad.securityserver.restapi.util.TokenTestUtils) Test(org.junit.Test)

Example 47 with TokenInfo

use of ee.ria.xroad.signer.protocol.dto.TokenInfo in project X-Road by nordic-institute.

the class TokenCertificateServiceTest method setup.

@Before
public void setup() throws Exception {
    when(clientService.getLocalClientMemberIds()).thenReturn(new HashSet<>(Collections.singletonList(client)));
    DnFieldDescription editableField = new DnFieldDescriptionImpl("O", "x", "default").setReadOnly(false);
    when(certificateAuthorityService.getCertificateProfile(any(), any(), any(), anyBoolean())).thenReturn(new DnFieldTestCertificateProfileInfo(editableField, true));
    // need lots of mocking
    // construct some test keys, with csrs and certs
    // make used finders return data from these items:
    // keyService.getKey, signerProxyFacade.getKeyIdForCertHash,
    // signerProxyFacade.getCertForHash
    // mock delete-operations (deleteCertificate, deleteCsr)
    CertRequestInfo goodCsr = new CertRequestInfo(GOOD_CSR_ID, null, null);
    CertRequestInfo authCsr = new CertRequestInfo(GOOD_AUTH_CSR_ID, null, null);
    CertRequestInfo signCsr = new CertRequestInfo(GOOD_SIGN_CSR_ID, null, null);
    CertRequestInfo signerExceptionCsr = new CertRequestInfo(SIGNER_EXCEPTION_CSR_ID, null, null);
    KeyInfo authKey = new TokenTestUtils.KeyInfoBuilder().id(AUTH_KEY_ID).keyUsageInfo(KeyUsageInfo.AUTHENTICATION).csr(authCsr).cert(authCert).build();
    KeyInfo goodKey = new TokenTestUtils.KeyInfoBuilder().id(GOOD_KEY_ID).csr(goodCsr).csr(signerExceptionCsr).build();
    KeyInfo signKey = new TokenTestUtils.KeyInfoBuilder().id(SIGN_KEY_ID).keyUsageInfo(KeyUsageInfo.SIGNING).csr(signCsr).cert(signCert).build();
    TokenInfo tokenInfo = new TokenTestUtils.TokenInfoBuilder().friendlyName("fubar").build();
    tokenInfo.getKeyInfo().add(authKey);
    tokenInfo.getKeyInfo().add(signKey);
    tokenInfo.getKeyInfo().add(goodKey);
    mockGetTokenAndKeyIdForCertificateHash(authKey, goodKey, signKey, tokenInfo);
    mockGetTokenAndKeyIdForCertificateRequestId(authKey, goodKey, signKey, tokenInfo);
    mockGetKey(authKey, goodKey, signKey);
    mockGetKeyIdForCertHash();
    mockGetCertForHash();
    mockDeleteCert();
    mockDeleteCertRequest();
    mockGetTokenForKeyId(tokenInfo);
    // activate / deactivate
    doAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        String hash = (String) args[0];
        if (MISSING_CERTIFICATE_HASH.equals(hash)) {
            throw new CodedException(TokenCertificateService.CERT_NOT_FOUND_FAULT_CODE);
        }
        return null;
    }).when(signerProxyFacade).deactivateCert(any());
    doAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        String hash = (String) args[0];
        if (MISSING_CERTIFICATE_HASH.equals(hash)) {
            throw new CodedException(TokenCertificateService.CERT_NOT_FOUND_FAULT_CODE);
        }
        return null;
    }).when(signerProxyFacade).activateCert(eq("certID"));
    // by default all actions are possible
    doReturn(EnumSet.allOf(PossibleActionEnum.class)).when(possibleActionsRuleEngine).getPossibleTokenActions(any());
    doReturn(EnumSet.allOf(PossibleActionEnum.class)).when(possibleActionsRuleEngine).getPossibleKeyActions(any(), any());
    doReturn(EnumSet.allOf(PossibleActionEnum.class)).when(possibleActionsRuleEngine).getPossibleCertificateActions(any(), any(), any());
    doReturn(EnumSet.allOf(PossibleActionEnum.class)).when(possibleActionsRuleEngine).getPossibleCsrActions(any());
}
Also used : DnFieldDescription(ee.ria.xroad.common.certificateprofile.DnFieldDescription) DnFieldDescriptionImpl(ee.ria.xroad.common.certificateprofile.impl.DnFieldDescriptionImpl) TokenTestUtils(org.niis.xroad.securityserver.restapi.util.TokenTestUtils) CertRequestInfo(ee.ria.xroad.signer.protocol.dto.CertRequestInfo) CodedException(ee.ria.xroad.common.CodedException) KeyInfo(ee.ria.xroad.signer.protocol.dto.KeyInfo) TokenInfo(ee.ria.xroad.signer.protocol.dto.TokenInfo) Before(org.junit.Before)

Example 48 with TokenInfo

use of ee.ria.xroad.signer.protocol.dto.TokenInfo in project X-Road by nordic-institute.

the class TokenServiceTest method updateTokenFriendlyName.

@Test
public void updateTokenFriendlyName() throws Exception {
    TokenInfo tokenInfo = tokenService.getToken(GOOD_TOKEN_ID);
    assertEquals(GOOD_TOKEN_NAME, tokenInfo.getFriendlyName());
    tokenInfo = tokenService.updateTokenFriendlyName(GOOD_TOKEN_ID, "friendly-neighborhood");
    assertEquals("friendly-neighborhood", tokenInfo.getFriendlyName());
}
Also used : TokenInfo(ee.ria.xroad.signer.protocol.dto.TokenInfo) Test(org.junit.Test)

Example 49 with TokenInfo

use of ee.ria.xroad.signer.protocol.dto.TokenInfo in project X-Road by nordic-institute.

the class TokenServiceTest method getToken.

@Test
public void getToken() throws Exception {
    try {
        tokenService.getToken(TOKEN_NOT_FOUND_TOKEN_ID);
    } catch (TokenNotFoundException expected) {
    }
    TokenInfo tokenInfo = tokenService.getToken(GOOD_TOKEN_ID);
    assertEquals(GOOD_TOKEN_NAME, tokenInfo.getFriendlyName());
}
Also used : TokenInfo(ee.ria.xroad.signer.protocol.dto.TokenInfo) Test(org.junit.Test)

Example 50 with TokenInfo

use of ee.ria.xroad.signer.protocol.dto.TokenInfo in project X-Road by nordic-institute.

the class TokensApiController method updateToken.

@PreAuthorize("hasAuthority('EDIT_TOKEN_FRIENDLY_NAME')")
@Override
@AuditEventMethod(event = RestApiAuditEvent.UPDATE_TOKEN_NAME)
public ResponseEntity<Token> updateToken(String id, TokenName tokenName) {
    try {
        TokenInfo tokenInfo = tokenService.updateTokenFriendlyName(id, tokenName.getName());
        Token token = tokenConverter.convert(tokenInfo);
        return new ResponseEntity<>(token, HttpStatus.OK);
    } catch (TokenNotFoundException e) {
        throw new ResourceNotFoundException(e);
    } catch (ActionNotPossibleException e) {
        throw new ConflictException(e);
    }
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ActionNotPossibleException(org.niis.xroad.securityserver.restapi.service.ActionNotPossibleException) Token(org.niis.xroad.securityserver.restapi.openapi.model.Token) TokenInfo(ee.ria.xroad.signer.protocol.dto.TokenInfo) ResourceNotFoundException(org.niis.xroad.restapi.openapi.ResourceNotFoundException) TokenNotFoundException(org.niis.xroad.securityserver.restapi.service.TokenNotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) AuditEventMethod(org.niis.xroad.restapi.config.audit.AuditEventMethod)

Aggregations

TokenInfo (ee.ria.xroad.signer.protocol.dto.TokenInfo)52 KeyInfo (ee.ria.xroad.signer.protocol.dto.KeyInfo)33 Test (org.junit.Test)19 TokenTestUtils (org.niis.xroad.securityserver.restapi.util.TokenTestUtils)16 CodedException (ee.ria.xroad.common.CodedException)14 CertificateInfo (ee.ria.xroad.signer.protocol.dto.CertificateInfo)13 SignerNotReachableException (org.niis.xroad.restapi.service.SignerNotReachableException)11 TokenInfoAndKeyId (ee.ria.xroad.signer.protocol.dto.TokenInfoAndKeyId)9 ServiceException (org.niis.xroad.restapi.service.ServiceException)8 Before (org.junit.Before)7 CertRequestInfo (ee.ria.xroad.signer.protocol.dto.CertRequestInfo)6 CertificateTestUtils (org.niis.xroad.securityserver.restapi.util.CertificateTestUtils)6 ClientId (ee.ria.xroad.common.identifier.ClientId)5 HashMap (java.util.HashMap)5 DeviationAwareRuntimeException (org.niis.xroad.restapi.exceptions.DeviationAwareRuntimeException)5 Command (asg.cliche.Command)4 Utils.printTokenInfo (ee.ria.xroad.signer.console.Utils.printTokenInfo)4 KeyUsageInfo (ee.ria.xroad.signer.protocol.dto.KeyUsageInfo)4 ListTokens (ee.ria.xroad.signer.protocol.message.ListTokens)4 ArrayList (java.util.ArrayList)4