Search in sources :

Example 81 with Client

use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.

the class SchedulerRestClient method delete.

public boolean delete(String sessionId, String dataspacePath, String path, List<String> includes, List<String> excludes) throws Exception {
    StringBuffer uriTmpl = (new StringBuffer()).append(restEndpointURL).append(addSlashIfMissing(restEndpointURL)).append("data/").append(dataspacePath).append('/');
    ResteasyClient client = buildResteasyClient(providerFactory);
    ResteasyWebTarget target = client.target(uriTmpl.toString()).path(path);
    if (includes != null && !includes.isEmpty()) {
        target = target.queryParam("includes", includes.toArray(new Object[includes.size()]));
    }
    if (excludes != null && !excludes.isEmpty()) {
        target = target.queryParam("excludes", excludes.toArray(new Object[excludes.size()]));
    }
    Response response = null;
    try {
        response = target.request().header("sessionid", sessionId).delete();
        if (response.getStatus() != HttpURLConnection.HTTP_NO_CONTENT) {
            if (response.getStatus() == HttpURLConnection.HTTP_UNAUTHORIZED) {
                throw new NotConnectedRestException("User not authenticated or session timeout.");
            } else {
                throwException(String.format("Cannot delete file(s). Status code: %s", response.getStatus()), response);
            }
        }
        return true;
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
Also used : ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)

Example 82 with Client

use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.

the class SchedulerRestClient method metadata.

public Map<String, Object> metadata(String sessionId, String dataspacePath, String pathname) throws Exception {
    StringBuffer uriTmpl = (new StringBuffer()).append(restEndpointURL).append(addSlashIfMissing(restEndpointURL)).append("data/").append(dataspacePath).append(escapeUrlPathSegment(pathname));
    ResteasyClient client = buildResteasyClient(providerFactory);
    ResteasyWebTarget target = client.target(uriTmpl.toString());
    Response response = null;
    try {
        response = target.request().header("sessionid", sessionId).head();
        if (response.getStatus() != HttpURLConnection.HTTP_OK) {
            if (response.getStatus() == HttpURLConnection.HTTP_UNAUTHORIZED) {
                throw new NotConnectedRestException("User not authenticated or session timeout.");
            } else {
                throwException(String.format("Cannot get metadata from %s in %s.", pathname, dataspacePath), response);
            }
        }
        MultivaluedMap<String, Object> headers = response.getHeaders();
        Map<String, Object> metaMap = Maps.newHashMap();
        if (headers.containsKey(HttpHeaders.LAST_MODIFIED)) {
            metaMap.put(HttpHeaders.LAST_MODIFIED, headers.getFirst(HttpHeaders.LAST_MODIFIED));
        }
        return metaMap;
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
Also used : ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)

Example 83 with Client

use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.

the class SchedulerRestClient method upload.

public boolean upload(String sessionId, File file, List<String> includes, List<String> excludes, String dataspacePath, final String path) throws Exception {
    StringBuffer uriTmpl = (new StringBuffer()).append(restEndpointURL).append(addSlashIfMissing(restEndpointURL)).append("data/").append(dataspacePath).append('/').append(escapeUrlPathSegment(path));
    ResteasyClient client = buildResteasyClient(providerFactory);
    ResteasyWebTarget target = client.target(uriTmpl.toString());
    Response response = null;
    try {
        response = target.request().header("sessionid", sessionId).put(Entity.entity(new CompressedStreamingOutput(file, includes, excludes), new Variant(MediaType.APPLICATION_OCTET_STREAM_TYPE, (Locale) null, encoding(file))));
        if (response.getStatus() != HttpURLConnection.HTTP_CREATED) {
            if (response.getStatus() == HttpURLConnection.HTTP_UNAUTHORIZED) {
                throw new NotConnectedRestException("User not authenticated or session timeout.");
            } else {
                throwException(String.format("File upload failed. Status code: %d", response.getStatus()), response);
            }
        }
        return true;
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
Also used : Locale(java.util.Locale) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)

Example 84 with Client

use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.

the class SchedulerRestClient method download.

public boolean download(String sessionId, String dataspacePath, String path, List<String> includes, List<String> excludes, File outputFile) throws Exception {
    StringBuffer uriTmpl = (new StringBuffer()).append(restEndpointURL).append(addSlashIfMissing(restEndpointURL)).append("data/").append(dataspacePath).append('/');
    ResteasyClient client = buildResteasyClient(providerFactory);
    ResteasyWebTarget target = client.target(uriTmpl.toString()).path(path);
    if (includes != null && !includes.isEmpty()) {
        target = target.queryParam("includes", includes.toArray(new Object[includes.size()]));
    }
    if (excludes != null && !excludes.isEmpty()) {
        target = target.queryParam("excludes", excludes.toArray(new Object[excludes.size()]));
    }
    Response response = null;
    try {
        response = target.request().header("sessionid", sessionId).acceptEncoding("*", "gzip", "zip").get();
        if (response.getStatus() != HttpURLConnection.HTTP_OK) {
            if (response.getStatus() == HttpURLConnection.HTTP_UNAUTHORIZED) {
                throw new NotConnectedRestException("User not authenticated or session timeout.");
            } else {
                throwException(String.format("Cannot retrieve the file. Status code: %d", response.getStatus()), response);
            }
        }
        if (response.hasEntity()) {
            InputStream is = response.readEntity(InputStream.class);
            if (isGZipEncoded(response)) {
                if (outputFile.exists() && outputFile.isDirectory()) {
                    outputFile = new File(outputFile, response.getHeaderString("x-pds-pathname"));
                }
                Zipper.GZIP.unzip(is, outputFile);
            } else if (isZipEncoded(response)) {
                Zipper.ZIP.unzip(is, outputFile);
            } else {
                File container = outputFile.getParentFile();
                if (!container.exists()) {
                    container.mkdirs();
                }
                Files.asByteSink(outputFile).writeFrom(is);
            }
        } else {
            outputFile.createNewFile();
        }
    } finally {
        if (response != null) {
            response.close();
        }
    }
    return true;
}
Also used : ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) FileUtils.copyInputStreamToFile(org.apache.commons.io.FileUtils.copyInputStreamToFile) ListFile(org.ow2.proactive_grid_cloud_portal.dataspace.dto.ListFile)

Example 85 with Client

use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.

the class JMXAuthenticatorImpl method authenticate.

/**
 * This method is automatically called when a JMX client tries to connect to the MBean Server referred
 * by the connector.
 * <p>
 * The only allowed credentials structure provided by the client is Object[] that contains
 * username/password (String/String) or username/{@link org.ow2.proactive.authentication.crypto.Credentials}
 *
 * @return a subject with the username as JMXPrincipal and the role as pubCredentials {@link javax.security.auth.Subject}
 * @param rawCredentials the credentials provided by the client
 */
public Subject authenticate(final Object rawCredentials) {
    // If not an array of object do not give any clues just throw exception
    if (rawCredentials == null || !(rawCredentials instanceof Object[])) {
        throw new SecurityException("Invalid credentials");
    }
    final Object[] arr = (Object[]) rawCredentials;
    if (arr[0] == null || arr[1] == null) {
        throw new SecurityException("Invalid credentials");
    }
    final String username = arr[0].toString();
    Credentials internalCredentials = null;
    // If username/Credentials
    if (arr[1] instanceof Credentials) {
        internalCredentials = (Credentials) arr[1];
    // If username/password (ex: JConsole)
    } else if (arr[1] instanceof String) {
        try {
            internalCredentials = Credentials.createCredentials(new CredData(CredData.parseLogin(username), CredData.parseDomain(username), (String) arr[1]), authentication.getPublicKey());
        } catch (Exception e) {
            throw new SecurityException("Invalid credentials", e);
        }
    } else {
        throw new SecurityException("Invalid credentials");
    }
    try {
        Subject s = this.authentication.authenticate(internalCredentials);
        if (permissionChecker != null) {
            boolean allowed = permissionChecker.checkPermission(internalCredentials);
            if (!allowed) {
                throw new SecurityException("Permission denied");
            }
        }
        return s;
    } catch (LoginException e) {
        throw new SecurityException("Unable to authenticate " + username);
    }
}
Also used : CredData(org.ow2.proactive.authentication.crypto.CredData) LoginException(javax.security.auth.login.LoginException) Credentials(org.ow2.proactive.authentication.crypto.Credentials) LoginException(javax.security.auth.login.LoginException) Subject(javax.security.auth.Subject)

Aggregations

Test (org.junit.Test)69 ISchedulerClient (org.ow2.proactive.scheduler.rest.ISchedulerClient)36 Client (org.ow2.proactive.resourcemanager.authentication.Client)31 JobId (org.ow2.proactive.scheduler.common.job.JobId)30 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)28 NonTerminatingJob (functionaltests.jobs.NonTerminatingJob)25 SimpleJob (functionaltests.jobs.SimpleJob)25 Job (org.ow2.proactive.scheduler.common.job.Job)25 ResteasyClient (org.jboss.resteasy.client.jaxrs.ResteasyClient)18 ResteasyWebTarget (org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)18 ListFile (org.ow2.proactive_grid_cloud_portal.dataspace.dto.ListFile)18 File (java.io.File)17 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)13 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)13 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)11 Node (org.objectweb.proactive.core.node.Node)9 IOException (java.io.IOException)8 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)8 JobInfo (org.ow2.proactive.scheduler.common.job.JobInfo)8 NodeSet (org.ow2.proactive.utils.NodeSet)7