use of ee.ria.xroad.signer.model.Token in project X-Road by nordic-institute.
the class MergeOntoFileTokenStrategyTest method mergeShouldMergeTokensInLists.
/**
* @see MergeOntoFileTokensStrategy#merge(List, List)
*/
@Test
public void mergeShouldMergeTokensInLists() {
final String tokenId = "1124";
Token fileToken = new Token(SoftwareModuleType.TYPE, tokenId, CryptoUtils.CKM_RSA_PKCS_NAME);
fileToken.setActive(false);
Token memoryToken = new Token(SoftwareModuleType.TYPE, tokenId, CryptoUtils.CKM_RSA_PKCS_NAME);
memoryToken.setActive(true);
MergeResult result = testedStrategy.merge(Collections.singletonList(fileToken), Collections.singletonList(memoryToken));
assertTrue("Token was not merged, isActive was not changed", result.getResultTokens().get(0).isActive());
}
use of ee.ria.xroad.signer.model.Token in project X-Road by nordic-institute.
the class MergeOntoFileTokenStrategyTest method mergeTokenShouldMergeKeysInTokens.
/**
* @see MergeOntoFileTokensStrategy#mergeToken(Token, Token)
*/
@Test
public void mergeTokenShouldMergeKeysInTokens() {
final String tokenId = "1123";
Token fileToken = new Token(SoftwareModuleType.TYPE, tokenId, CryptoUtils.CKM_RSA_PKCS_NAME);
Token memoryToken = new Token(SoftwareModuleType.TYPE, tokenId, CryptoUtils.CKM_RSA_PKCS_NAME);
final String keyId = "1551";
Key memoryKey = createKey(keyId, 2);
memoryKey.setAvailable(true);
memoryToken.addKey(memoryKey);
Key fileKey = createKey(keyId, 3);
fileKey.setAvailable(false);
fileToken.addKey(fileKey);
testedStrategy.mergeToken(fileToken, memoryToken);
assertTrue("key availability in token was not merged", fileKey.isAvailable());
}
use of ee.ria.xroad.signer.model.Token in project X-Road by nordic-institute.
the class TokenManager method setTokenAvailable.
/**
* Sets the token available.
*
* @param tokenType the token type
* @param available availability flag
*/
public static synchronized void setTokenAvailable(TokenType tokenType, boolean available) {
String tokenId = tokenType.getId();
log.trace("setTokenAvailable({}, {})", tokenId, available);
Token token = findToken(tokenId);
token.setAvailable(available);
token.setModuleId(tokenType.getModuleType());
}
use of ee.ria.xroad.signer.model.Token in project X-Road by nordic-institute.
the class TokenManager method merge.
/**
* Merge the in-memory configuration and the on-disk configuration if the configuration on
* disk has changed.
* @param listener
*/
public static void merge(TokenMergeAddedCertificatesListener listener) {
if (TokenConf.getInstance().hasChanged()) {
log.debug("The key configuration on disk has changed, merging changes.");
List<Token> fileTokens;
try {
fileTokens = TokenConf.getInstance().retrieveTokensFromConf();
} catch (TokenConf.TokenConfException e) {
log.error("Failed to load the new key configuration from disk.", e);
return;
}
MergeResult result;
synchronized (TokenManager.class) {
result = mergeStrategy.merge(fileTokens, currentTokens);
currentTokens = result.getResultTokens();
}
if (listener != null) {
listener.mergeDone(result.getAddedCertificates());
}
log.info("Merged new key configuration.");
} else {
log.debug("The key configuration on disk has not changed, skipping merge.");
}
}
use of ee.ria.xroad.signer.model.Token in project X-Road by nordic-institute.
the class MergeOntoFileTokenStrategyTest method mergeShouldAddMissingTokens.
/**
* @see MergeOntoFileTokensStrategy#merge(List, List)
*/
@Test
public void mergeShouldAddMissingTokens() {
Token fileToken1 = new Token(SoftwareModuleType.TYPE, "1", CryptoUtils.CKM_RSA_PKCS_NAME);
Token fileToken2 = new Token(SoftwareModuleType.TYPE, "2", CryptoUtils.CKM_RSA_PKCS_NAME);
Token memoryToken1 = new Token(SoftwareModuleType.TYPE, "1", CryptoUtils.CKM_RSA_PKCS_NAME);
Token memoryToken2 = new Token(SoftwareModuleType.TYPE, "2", CryptoUtils.CKM_RSA_PKCS_NAME);
Token memoryToken3 = new Token(SoftwareModuleType.TYPE, "3", CryptoUtils.CKM_RSA_PKCS_NAME);
List<Token> fileList = Arrays.asList(fileToken1, fileToken2);
List<Token> memoryList = Arrays.asList(memoryToken1, memoryToken2, memoryToken3);
final int memListSize = memoryList.size();
MergeResult result = testedStrategy.merge(fileList, memoryList);
List<Token> mergedList = result.getResultTokens();
assertThat("Missing tokens were not added", mergedList.size(), is(memListSize));
assertThat("Missing tokens were not added", mergedList, hasItems(fileToken1, fileToken2, memoryToken3));
}
Aggregations