use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException in project scheduling by ow2-proactive.
the class SchedulerStateRest method putThirdPartyCredential.
@Override
public void putThirdPartyCredential(String sessionId, String key, String value) throws NotConnectedRestException, PermissionRestException, SchedulerRestException {
try {
Scheduler s = checkAccess(sessionId);
s.putThirdPartyCredential(key, value);
} catch (PermissionException e) {
throw new PermissionRestException(e);
} catch (NotConnectedException e) {
throw new NotConnectedRestException(e);
} catch (KeyException e) {
throw new SchedulerRestException(e);
}
}
use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException in project scheduling by ow2-proactive.
the class SchedulerStateRest method login.
/**
* Login to the scheduler using a form containing 2 fields (username and
* password).
*
* @param username
* username
* @param password
* password
* @return the session id associated to the login.
* @throws LoginException
*/
@Override
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("login")
@Produces("application/json")
public String login(@FormParam("username") String username, @FormParam("password") String password) throws LoginException, SchedulerRestException {
try {
if ((username == null) || (password == null)) {
throw new LoginException("Empty login/password");
}
Session session = sessionStore.create(username);
session.connectToScheduler(new CredData(username, password));
logger.info("Binding user " + username + " to session " + session.getSessionId());
return session.getSessionId();
} catch (ActiveObjectCreationException e) {
throw new SchedulerRestException(e);
} catch (SchedulerException e) {
throw new SchedulerRestException(e);
} catch (NodeException e) {
throw new SchedulerRestException(e);
}
}
use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException in project scheduling by ow2-proactive.
the class SchedulerStateRest method loginWithCredential.
/**
* Login to the scheduler using a multipart form can be used either by
* submitting 2 fields ({@code username} and {@code password}) or by sending
* a credential file with field name {@code credential}.
*
* @return the session id associated to this new connection.
* @throws KeyException
* @throws LoginException
* @throws SchedulerRestException
*/
@Override
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("login")
@Produces("application/json")
public String loginWithCredential(@MultipartForm LoginForm multipart) throws LoginException, KeyException, SchedulerRestException {
try {
Session session;
if (multipart.getCredential() != null) {
Credentials credentials;
try {
session = sessionStore.createUnnamedSession();
credentials = Credentials.getCredentials(multipart.getCredential());
session.connectToScheduler(credentials);
} catch (IOException e) {
throw new LoginException(e.getMessage());
}
} else {
if ((multipart.getUsername() == null) || (multipart.getPassword() == null)) {
throw new LoginException("empty login/password");
}
session = sessionStore.create(multipart.getUsername());
CredData credData = new CredData(CredData.parseLogin(multipart.getUsername()), CredData.parseDomain(multipart.getUsername()), multipart.getPassword(), multipart.getSshKey());
session.connectToScheduler(credData);
}
return session.getSessionId();
} catch (PermissionException e) {
throw new SchedulerRestException(e);
} catch (ActiveObjectCreationException e) {
throw new SchedulerRestException(e);
} catch (SchedulerException e) {
throw new SchedulerRestException(e);
} catch (NodeException e) {
throw new SchedulerRestException(e);
}
}
use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException in project scheduling by ow2-proactive.
the class SchedulerStateRest method getCreateCredential.
/**
* generates a credential file from user provided credentials
*
* @return the credential file generated by the scheduler
* @throws LoginException
* @throws SchedulerRestException
*/
@Override
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("createcredential")
@Produces("*/*")
public byte[] getCreateCredential(@MultipartForm LoginForm multipart) throws LoginException, SchedulerRestException {
String username = multipart.getUsername();
String password = multipart.getPassword();
byte[] privKey = multipart.getSshKey();
try {
String url = PortalConfiguration.SCHEDULER_URL.getValueAsString();
SchedulerAuthenticationInterface auth = SchedulerConnection.join(url);
PublicKey pubKey = auth.getPublicKey();
sessionStore.create(username);
Credentials cred = Credentials.createCredentials(new CredData(CredData.parseLogin(username), CredData.parseDomain(username), password, privKey), pubKey);
return cred.getBase64();
} catch (ConnectionException | KeyException e) {
throw new SchedulerRestException(e);
}
}
Aggregations