use of org.eclipse.che.multiuser.machine.authentication.server.signature.model.impl.SignatureKeyPairImpl in project devspaces-images by redhat-developer.
the class SignatureKeyManager method generateKeyPair.
@VisibleForTesting
SignatureKeyPair generateKeyPair(String workspaceId) throws NoSuchAlgorithmException, ServerException, ConflictException {
try {
KeyPairGenerator kpg = KeyPairGenerator.getInstance(algorithm);
kpg.initialize(keySize);
final KeyPair pair = kpg.generateKeyPair();
final SignatureKeyPairImpl kp = new SignatureKeyPairImpl(workspaceId, pair.getPublic(), pair.getPrivate());
LOG.debug("Generated signature key pair with ws id {} and algorithm {}.", kp.getWorkspaceId(), algorithm);
return signatureKeyDao.create(kp);
} catch (NoSuchAlgorithmException | ConflictException | ServerException ex) {
LOG.error("Unable to generate signature keypair for ws {}. Cause: {}", workspaceId, ex.getMessage());
throw ex;
}
}
use of org.eclipse.che.multiuser.machine.authentication.server.signature.model.impl.SignatureKeyPairImpl in project che-server by eclipse-che.
the class JpaSignatureKeyDao method doRemove.
@Transactional
protected void doRemove(String workspaceId) {
final EntityManager manager = managerProvider.get();
final SignatureKeyPairImpl keyPair = manager.find(SignatureKeyPairImpl.class, workspaceId);
if (keyPair != null) {
manager.remove(keyPair);
manager.flush();
}
}
use of org.eclipse.che.multiuser.machine.authentication.server.signature.model.impl.SignatureKeyPairImpl in project che-server by eclipse-che.
the class SignatureKeyManagerTest method shouldReturnSignatureKeys.
@Test
public void shouldReturnSignatureKeys() throws Exception {
String wsId = "WS_id_1";
final SignatureKeyPairImpl kp = newKeyPair(wsId);
when(signatureKeyDao.get(anyString())).thenReturn(kp);
final KeyPair cachedPair = signatureKeyManager.getOrCreateKeyPair(wsId);
assertNotNull(cachedPair);
assertKeys(cachedPair.getPublic(), kp.getPublicKey());
assertKeys(cachedPair.getPrivate(), kp.getPrivateKey());
}
use of org.eclipse.che.multiuser.machine.authentication.server.signature.model.impl.SignatureKeyPairImpl in project che-server by eclipse-che.
the class SignatureKeyManagerTest method shouldThrowsExceptionWhenAlgorithmIsNotSupported.
@Test(expectedExceptions = SignatureKeyManagerException.class)
public void shouldThrowsExceptionWhenAlgorithmIsNotSupported() throws Exception {
final SignatureKeyImpl publicKey = new SignatureKeyImpl(new byte[] {}, "ECDH", "PKCS#15");
final SignatureKeyImpl privateKey = new SignatureKeyImpl(new byte[] {}, "ECDH", "PKCS#3");
final SignatureKeyPairImpl kp = new SignatureKeyPairImpl("id_" + 1, publicKey, privateKey);
doReturn(kp).when(signatureKeyDao).get(anyString());
signatureKeyManager.getOrCreateKeyPair("ws1");
verify(signatureKeyDao).get(anyString());
}
use of org.eclipse.che.multiuser.machine.authentication.server.signature.model.impl.SignatureKeyPairImpl in project che-server by eclipse-che.
the class SignatureKeyDaoTest method testGetsAllKeys.
@Test
public void testGetsAllKeys() throws Exception {
List<SignatureKeyPairImpl> foundKeys = new ArrayList<>();
for (SignatureKeyPairImpl expected : storedKeyPairs) {
foundKeys.add(dao.get(expected.getWorkspaceId()));
}
assertEquals(new HashSet<>(foundKeys), new HashSet<>(asList(storedKeyPairs)));
assertEquals(foundKeys.size(), COUNT_KEY_PAIRS);
}
Aggregations