Search in sources :

Example 1 with SchedulerRestException

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);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) SchedulerRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException) KeyException(java.security.KeyException)

Example 2 with SchedulerRestException

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);
    }
}
Also used : InternalSchedulerException(org.ow2.proactive.scheduler.common.exception.InternalSchedulerException) SchedulerException(org.ow2.proactive.scheduler.common.exception.SchedulerException) CredData(org.ow2.proactive.authentication.crypto.CredData) LoginException(javax.security.auth.login.LoginException) NodeException(org.objectweb.proactive.core.node.NodeException) SchedulerRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException) ActiveObjectCreationException(org.objectweb.proactive.ActiveObjectCreationException) HttpSession(javax.servlet.http.HttpSession) Session(org.ow2.proactive_grid_cloud_portal.common.Session) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 3 with SchedulerRestException

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);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) InternalSchedulerException(org.ow2.proactive.scheduler.common.exception.InternalSchedulerException) SchedulerException(org.ow2.proactive.scheduler.common.exception.SchedulerException) CredData(org.ow2.proactive.authentication.crypto.CredData) LoginException(javax.security.auth.login.LoginException) NodeException(org.objectweb.proactive.core.node.NodeException) IOException(java.io.IOException) SchedulerRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException) Credentials(org.ow2.proactive.authentication.crypto.Credentials) ActiveObjectCreationException(org.objectweb.proactive.ActiveObjectCreationException) HttpSession(javax.servlet.http.HttpSession) Session(org.ow2.proactive_grid_cloud_portal.common.Session) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 4 with SchedulerRestException

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);
    }
}
Also used : PublicKey(java.security.PublicKey) CredData(org.ow2.proactive.authentication.crypto.CredData) SchedulerAuthenticationInterface(org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface) SchedulerRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException) Credentials(org.ow2.proactive.authentication.crypto.Credentials) ConnectionException(org.ow2.proactive.scheduler.common.exception.ConnectionException) KeyException(java.security.KeyException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

SchedulerRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException)4 Consumes (javax.ws.rs.Consumes)3 POST (javax.ws.rs.POST)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 CredData (org.ow2.proactive.authentication.crypto.CredData)3 KeyException (java.security.KeyException)2 LoginException (javax.security.auth.login.LoginException)2 HttpSession (javax.servlet.http.HttpSession)2 ActiveObjectCreationException (org.objectweb.proactive.ActiveObjectCreationException)2 NodeException (org.objectweb.proactive.core.node.NodeException)2 Credentials (org.ow2.proactive.authentication.crypto.Credentials)2 InternalSchedulerException (org.ow2.proactive.scheduler.common.exception.InternalSchedulerException)2 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)2 SchedulerException (org.ow2.proactive.scheduler.common.exception.SchedulerException)2 Session (org.ow2.proactive_grid_cloud_portal.common.Session)2 IOException (java.io.IOException)1 PublicKey (java.security.PublicKey)1 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)1 SchedulerAuthenticationInterface (org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface)1