use of ee.ria.xroad.signer.protocol.dto.TokenInfo in project X-Road by nordic-institute.
the class TokenService method updateTokenFriendlyName.
/**
* update token friendly name
*
* @param tokenId
* @param friendlyName
* @throws TokenNotFoundException if token was not found
*/
public TokenInfo updateTokenFriendlyName(String tokenId, String friendlyName) throws TokenNotFoundException, ActionNotPossibleException {
// check that updating friendly name is possible
TokenInfo tokenInfo = getToken(tokenId);
auditDataHelper.put(tokenInfo);
// Override old value with the new
auditDataHelper.put(RestApiAuditProperty.TOKEN_FRIENDLY_NAME, friendlyName);
possibleActionsRuleEngine.requirePossibleTokenAction(PossibleActionEnum.EDIT_FRIENDLY_NAME, tokenInfo);
try {
signerProxyFacade.setTokenFriendlyName(tokenId, friendlyName);
tokenInfo = signerProxyFacade.getToken(tokenId);
} catch (CodedException e) {
if (isCausedByTokenNotFound(e)) {
throw new TokenNotFoundException(e);
} else {
throw e;
}
} catch (Exception other) {
throw new SignerNotReachableException("update token friendly name failed", other);
}
return tokenInfo;
}
use of ee.ria.xroad.signer.protocol.dto.TokenInfo in project X-Road by nordic-institute.
the class TokenService method updateSoftwareTokenPin.
/**
* Update the pin code for a token and it's keys
*
* @param tokenId ID of the token
* @param oldPin the old (current) passing pin
* @param newPin the new pin
* @throws TokenNotFoundException token not found
* @throws PinIncorrectException incorrect pin
*/
public void updateSoftwareTokenPin(String tokenId, String oldPin, String newPin) throws TokenNotFoundException, PinIncorrectException, ActionNotPossibleException, InvalidCharactersException, WeakPinException {
TokenInfo tokenInfo = getToken(tokenId);
auditDataHelper.put(tokenInfo);
possibleActionsRuleEngine.requirePossibleTokenAction(PossibleActionEnum.TOKEN_CHANGE_PIN, tokenInfo);
char[] newPinCharArray = newPin.toCharArray();
tokenPinValidator.validateSoftwareTokenPin(newPinCharArray);
try {
signerProxyFacade.updateSoftwareTokenPin(tokenId, oldPin.toCharArray(), newPinCharArray);
} catch (CodedException ce) {
if (isCausedByTokenNotFound(ce)) {
throw new TokenNotFoundException(ce);
} else if (isCausedByIncorrectPin(ce)) {
throw new PinIncorrectException(ce);
} else {
throw ce;
}
} catch (Exception other) {
throw new SignerNotReachableException("updateSoftwareTokenPin failed", other);
}
}
use of ee.ria.xroad.signer.protocol.dto.TokenInfo in project X-Road by nordic-institute.
the class TokenService method deactivateToken.
/**
* Deactivate a token
*
* @param id id of token
* @throws TokenNotFoundException if token was not found
* @throws ActionNotPossibleException if deactivation was not possible
*/
public void deactivateToken(String id) throws TokenNotFoundException, ActionNotPossibleException {
// check that action is possible
TokenInfo tokenInfo = getToken(id);
auditDataHelper.put(tokenInfo);
possibleActionsRuleEngine.requirePossibleTokenAction(PossibleActionEnum.TOKEN_DEACTIVATE, tokenInfo);
try {
signerProxyFacade.deactivateToken(id);
} catch (CodedException e) {
if (isCausedByTokenNotFound(e)) {
throw new TokenNotFoundException(e);
} else {
throw e;
}
} catch (Exception other) {
throw new SignerNotReachableException("token deactivation failed", other);
}
}
use of ee.ria.xroad.signer.protocol.dto.TokenInfo in project X-Road by nordic-institute.
the class TokenCertificatesApiControllerIntegrationTest method setup.
@Before
public void setup() throws Exception {
doAnswer(answer -> "key-id").when(signerProxyFacade).importCert(any(), any(), any());
doAnswer(answer -> null).when(globalConfFacade).verifyValidity();
doAnswer(answer -> TestUtils.INSTANCE_FI).when(globalConfFacade).getInstanceIdentifier();
doAnswer(answer -> TestUtils.getM1Ss1ClientId()).when(globalConfFacade).getSubjectName(any(), any());
CertificateInfo signCertificateInfo = new CertificateInfoBuilder().certificate(getMockCertificate()).certificateStatus("SAVED").build();
CertificateInfo authCertificateInfo = new CertificateInfoBuilder().certificate(getMockAuthCertificate()).certificateStatus("SAVED").build();
CertificateInfo unknownCertificateInfo = new CertificateInfoBuilder().certificate(getMockCertificateWithoutExtensions()).certificateStatus("SAVED").build();
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
String certId = (String) args[0];
if (AUTH_CERT_HASH.equals(certId)) {
return authCertificateInfo;
} else if (UNKNOWN_CERT_HASH.equals(certId)) {
return unknownCertificateInfo;
} else {
return signCertificateInfo;
}
}).when(signerProxyFacade).getCertForHash(any());
doAnswer(answer -> "key-id").when(signerProxyFacade).getKeyIdForCertHash(any());
TokenInfo tokenInfo = new TokenTestUtils.TokenInfoBuilder().build();
KeyInfo keyInfo = new TokenTestUtils.KeyInfoBuilder().id("key-id").build();
tokenInfo.getKeyInfo().add(keyInfo);
doAnswer(answer -> Collections.singletonList(tokenInfo)).when(signerProxyFacade).getTokens();
TokenInfoAndKeyId tokenInfoAndKeyId = new TokenInfoAndKeyId(tokenInfo, keyInfo.getId());
doAnswer(answer -> tokenInfoAndKeyId).when(signerProxyFacade).getTokenAndKeyIdForCertRequestId(any());
doAnswer(answer -> tokenInfoAndKeyId).when(signerProxyFacade).getTokenAndKeyIdForCertHash(any());
// by default all actions are possible
doReturn(EnumSet.allOf(PossibleActionEnum.class)).when(possibleActionsRuleEngine).getPossibleCertificateActions(any(), any(), any());
}
use of ee.ria.xroad.signer.protocol.dto.TokenInfo in project X-Road by nordic-institute.
the class TokenCertificateSigningRequestConverterTest method convertWithPossibleActions.
@Test
public void convertWithPossibleActions() throws Exception {
CertRequestInfo certRequestInfo = new CertificateTestUtils.CertRequestInfoBuilder().build();
KeyInfo keyInfo = new TokenTestUtils.KeyInfoBuilder().csr(certRequestInfo).build();
TokenInfo tokenInfo = new TokenTestUtils.TokenInfoBuilder().key(keyInfo).build();
TokenCertificateSigningRequest csr = csrConverter.convert(certRequestInfo, keyInfo, tokenInfo);
Collection<PossibleAction> actions = csr.getPossibleActions();
assertTrue(actions.contains(PossibleAction.DELETE));
assertEquals(1, actions.size());
}
Aggregations