Search in sources :

Example 11 with SignatureKeyPairImpl

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;
    }
}
Also used : KeyPair(java.security.KeyPair) ServerException(org.eclipse.che.api.core.ServerException) ConflictException(org.eclipse.che.api.core.ConflictException) KeyPairGenerator(java.security.KeyPairGenerator) SignatureKeyPairImpl(org.eclipse.che.multiuser.machine.authentication.server.signature.model.impl.SignatureKeyPairImpl) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 12 with SignatureKeyPairImpl

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();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) SignatureKeyPairImpl(org.eclipse.che.multiuser.machine.authentication.server.signature.model.impl.SignatureKeyPairImpl) Transactional(com.google.inject.persist.Transactional)

Example 13 with SignatureKeyPairImpl

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());
}
Also used : KeyPair(java.security.KeyPair) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SignatureKeyPairImpl(org.eclipse.che.multiuser.machine.authentication.server.signature.model.impl.SignatureKeyPairImpl) Test(org.testng.annotations.Test)

Example 14 with SignatureKeyPairImpl

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());
}
Also used : SignatureKeyImpl(org.eclipse.che.multiuser.machine.authentication.server.signature.model.impl.SignatureKeyImpl) SignatureKeyPairImpl(org.eclipse.che.multiuser.machine.authentication.server.signature.model.impl.SignatureKeyPairImpl) Test(org.testng.annotations.Test)

Example 15 with SignatureKeyPairImpl

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);
}
Also used : ArrayList(java.util.ArrayList) SignatureKeyPairImpl(org.eclipse.che.multiuser.machine.authentication.server.signature.model.impl.SignatureKeyPairImpl) Test(org.testng.annotations.Test)

Aggregations

SignatureKeyPairImpl (org.eclipse.che.multiuser.machine.authentication.server.signature.model.impl.SignatureKeyPairImpl)28 Test (org.testng.annotations.Test)12 AccountImpl (org.eclipse.che.account.spi.AccountImpl)10 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)10 TypeLiteral (com.google.inject.TypeLiteral)8 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)8 TckResourcesCleaner (org.eclipse.che.commons.test.tck.TckResourcesCleaner)8 DBInitializer (org.eclipse.che.core.db.DBInitializer)8 SchemaInitializer (org.eclipse.che.core.db.schema.SchemaInitializer)8 FlywaySchemaInitializer (org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer)8 SignatureKeyDao (org.eclipse.che.multiuser.machine.authentication.server.signature.spi.SignatureKeyDao)8 KeyPair (java.security.KeyPair)6 UserDevfileImpl (org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl)5 JpaSignatureKeyDao (org.eclipse.che.multiuser.machine.authentication.server.signature.jpa.JpaSignatureKeyDao)5 SHA512PasswordEncryptor (org.eclipse.che.security.SHA512PasswordEncryptor)5 JpaPersistModule (com.google.inject.persist.jpa.JpaPersistModule)4 KeyPairGenerator (java.security.KeyPairGenerator)4 HashMap (java.util.HashMap)4 SystemPermissionsImpl (org.eclipse.che.multiuser.api.permission.server.model.impl.SystemPermissionsImpl)4 SystemPermissionsDaoTest (org.eclipse.che.multiuser.api.permission.server.spi.tck.SystemPermissionsDaoTest)4