use of org.eclipse.che.api.ssh.server.model.impl.SshPairImpl in project che by eclipse.
the class SshDaoTest method shouldGetSshPairByNameOwnerAndService.
@Test
public void shouldGetSshPairByNameOwnerAndService() throws Exception {
SshPairImpl sshPair = pairs[0];
sshDao.get(sshPair.getOwner(), sshPair.getService(), sshPair.getName());
}
use of org.eclipse.che.api.ssh.server.model.impl.SshPairImpl in project che by eclipse.
the class SshDaoTest method shouldGetSshPairListByNameAndService.
@Test
public void shouldGetSshPairListByNameAndService() throws Exception {
SshPairImpl sshPair1 = pairs[0];
SshPairImpl sshPair2 = pairs[1];
assertEquals(sshPair1.getOwner(), sshPair2.getOwner(), "Owner must be the same");
assertEquals(sshPair1.getService(), sshPair2.getService(), "Service must be the same");
final List<SshPairImpl> found = sshDao.get(sshPair1.getOwner(), sshPair1.getService());
assertEquals(new HashSet<>(found), new HashSet<>(asList(sshPair1, sshPair2)));
}
use of org.eclipse.che.api.ssh.server.model.impl.SshPairImpl in project che by eclipse.
the class SshDaoTest method shouldRemoveSshKeyPair.
@Test(expectedExceptions = NotFoundException.class, dependsOnMethods = "shouldThrowNotFoundExceptionIfPairWithSuchNameOwnerAndServiceDoesNotExist")
public void shouldRemoveSshKeyPair() throws Exception {
final SshPairImpl pair = pairs[4];
try {
sshDao.remove(pair.getOwner(), pair.getService(), pair.getName());
} catch (NotFoundException x) {
fail("SshKeyPair should be removed");
}
sshDao.get(pair.getOwner(), pair.getService(), pair.getName());
}
use of org.eclipse.che.api.ssh.server.model.impl.SshPairImpl in project che by eclipse.
the class SshManager method generatePair.
/**
* Generates and stores ssh pair for specified user.
*
* @param owner
* the id of the user who will be the owner of the ssh pair
* @param service
* service name pf ssh pair
* @param name
* name of pair
* @return instance of generated ssh pair
* @throws ConflictException
* when given ssh pair cannot be generated or created
* @throws ServerException
* when any other error occurs during ssh pair generating or creating
*/
public SshPairImpl generatePair(String owner, String service, String name) throws ServerException, ConflictException {
KeyPair keyPair;
try {
keyPair = KeyPair.genKeyPair(genJSch, 2, 2048);
} catch (JSchException e) {
throw new ServerException("Failed to generate ssh pair.", e);
}
ByteArrayOutputStream privateBuff = new ByteArrayOutputStream();
keyPair.writePrivateKey(privateBuff);
ByteArrayOutputStream publicBuff = new ByteArrayOutputStream();
keyPair.writePublicKey(publicBuff, null);
final SshPairImpl generatedSshPair = new SshPairImpl(owner, service, name, publicBuff.toString(), privateBuff.toString());
sshDao.create(generatedSshPair);
return generatedSshPair;
}
use of org.eclipse.che.api.ssh.server.model.impl.SshPairImpl in project che by eclipse.
the class SshService method createPair.
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_HTML)
@GenerateLink(rel = Constants.LINK_REL_CREATE_PAIR)
public Response createPair(Iterator<FileItem> formData) throws BadRequestException, ServerException, ConflictException {
String service = null;
String name = null;
String privateKey = null;
String publicKey = null;
while (formData.hasNext()) {
FileItem item = formData.next();
String fieldName = item.getFieldName();
switch(fieldName) {
case "service":
service = item.getString();
break;
case "name":
name = item.getString();
break;
case "privateKey":
privateKey = item.getString();
break;
case "publicKey":
publicKey = item.getString();
break;
default:
}
}
requiredNotNull(service, "Service name required");
requiredNotNull(name, "Name required");
if (privateKey == null && publicKey == null) {
throw new BadRequestException("Key content was not provided.");
}
sshManager.createPair(new SshPairImpl(getCurrentUserId(), service, name, publicKey, privateKey));
// through specific of html form that doesn't invoke complete submit handler
return Response.ok("", MediaType.TEXT_HTML).build();
}
Aggregations