Search in sources :

Example 81 with UnauthorizedException

use of org.opencastproject.security.api.UnauthorizedException in project opencast by opencast.

the class SeriesServiceRemoteImpl method updateAccessControl.

@Override
public boolean updateAccessControl(String seriesID, AccessControlList accessControl) throws NotFoundException, SeriesException, UnauthorizedException {
    HttpPost post = new HttpPost(seriesID + "/accesscontrol");
    try {
        List<BasicNameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("seriesID", seriesID));
        params.add(new BasicNameValuePair("acl", AccessControlParser.toXml(accessControl)));
        post.setEntity(new UrlEncodedFormEntity(params));
    } catch (Exception e) {
        throw new SeriesException("Unable to assemble a remote series request for updating an ACL " + accessControl, e);
    }
    HttpResponse response = getResponse(post, SC_NO_CONTENT, SC_CREATED, SC_NOT_FOUND, SC_UNAUTHORIZED);
    try {
        if (response != null) {
            int status = response.getStatusLine().getStatusCode();
            if (SC_NOT_FOUND == status) {
                throw new NotFoundException("Series not found: " + seriesID);
            } else if (SC_NO_CONTENT == status) {
                logger.info("Successfully updated ACL of {} to the series service", seriesID);
                return true;
            } else if (SC_UNAUTHORIZED == status) {
                throw new UnauthorizedException("Not authorized to update series ACL of " + seriesID);
            } else if (SC_CREATED == status) {
                logger.info("Successfully created ACL of {} to the series service", seriesID);
                return false;
            }
        }
    } finally {
        closeConnection(response);
    }
    throw new SeriesException("Unable to update series ACL " + accessControl + " using the remote series services");
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) HttpResponse(org.apache.http.HttpResponse) NotFoundException(org.opencastproject.util.NotFoundException) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) SeriesException(org.opencastproject.series.api.SeriesException) ParseException(java.text.ParseException) SeriesException(org.opencastproject.series.api.SeriesException) WebApplicationException(javax.ws.rs.WebApplicationException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException)

Example 82 with UnauthorizedException

use of org.opencastproject.security.api.UnauthorizedException in project opencast by opencast.

the class SeriesServiceRemoteImpl method getSeries.

@Override
public DublinCoreCatalogList getSeries(SeriesQuery query) throws SeriesException, UnauthorizedException {
    HttpGet get = new HttpGet(getSeriesUrl(query));
    HttpResponse response = getResponse(get, SC_OK, SC_UNAUTHORIZED);
    try {
        if (response != null) {
            int statusCode = response.getStatusLine().getStatusCode();
            if (SC_OK == statusCode) {
                DublinCoreCatalogList list = DublinCoreCatalogList.parse(EntityUtils.toString(response.getEntity(), "UTF-8"));
                logger.info("Successfully get series dublin core catalog list from the remote series index");
                return list;
            } else if (SC_UNAUTHORIZED == statusCode) {
                throw new UnauthorizedException("Not authorized to get series from query");
            }
        }
    } catch (UnauthorizedException e) {
        throw e;
    } catch (Exception e) {
        throw new SeriesException("Unable to get series from query from remote series index: " + e);
    } finally {
        closeConnection(response);
    }
    throw new SeriesException("Unable to get series from query from remote series index: " + getSeriesUrl(query));
}
Also used : DublinCoreCatalogList(org.opencastproject.metadata.dublincore.DublinCoreCatalogList) HttpGet(org.apache.http.client.methods.HttpGet) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) HttpResponse(org.apache.http.HttpResponse) SeriesException(org.opencastproject.series.api.SeriesException) ParseException(java.text.ParseException) SeriesException(org.opencastproject.series.api.SeriesException) WebApplicationException(javax.ws.rs.WebApplicationException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException)

Example 83 with UnauthorizedException

use of org.opencastproject.security.api.UnauthorizedException in project opencast by opencast.

the class SeriesServiceRemoteImpl method deleteSeriesProperty.

@Override
public void deleteSeriesProperty(String seriesID, String propertyName) throws SeriesException, NotFoundException, UnauthorizedException {
    HttpDelete del = new HttpDelete("/" + seriesID + "/property/" + propertyName);
    HttpResponse response = getResponse(del, SC_OK, SC_NOT_FOUND, SC_UNAUTHORIZED);
    try {
        if (response != null) {
            int statusCode = response.getStatusLine().getStatusCode();
            if (SC_NOT_FOUND == statusCode) {
                throw new NotFoundException("Series not found: " + seriesID);
            } else if (SC_UNAUTHORIZED == statusCode) {
                throw new UnauthorizedException("Not authorized to delete series " + seriesID);
            } else if (SC_OK == statusCode) {
                logger.info("Successfully deleted {} from the remote series index", seriesID);
                return;
            }
        }
    } finally {
        closeConnection(response);
    }
    throw new SeriesException("Unable to remove " + seriesID + " from a remote series index");
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) HttpResponse(org.apache.http.HttpResponse) NotFoundException(org.opencastproject.util.NotFoundException) SeriesException(org.opencastproject.series.api.SeriesException)

Example 84 with UnauthorizedException

use of org.opencastproject.security.api.UnauthorizedException in project opencast by opencast.

the class SeriesServiceRemoteImpl method updateSeriesProperty.

@Override
public void updateSeriesProperty(String seriesID, String propertyName, String propertyValue) throws SeriesException, NotFoundException, UnauthorizedException {
    HttpPost post = new HttpPost("/" + seriesID + "/property");
    try {
        List<BasicNameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("name", propertyName));
        params.add(new BasicNameValuePair("value", propertyValue));
        post.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
    } catch (Exception e) {
        throw new SeriesException("Unable to assemble a remote series request for updating series " + seriesID + " series property " + propertyName + ":" + propertyValue, e);
    }
    HttpResponse response = getResponse(post, SC_NO_CONTENT, SC_CREATED, SC_UNAUTHORIZED);
    try {
        if (response != null) {
            int statusCode = response.getStatusLine().getStatusCode();
            if (SC_NO_CONTENT == statusCode) {
                logger.info("Successfully updated series {} with property name {} and value {} in the series service", seriesID, propertyName, propertyValue);
                return;
            } else if (SC_UNAUTHORIZED == statusCode) {
                throw new UnauthorizedException("Not authorized to update series " + seriesID);
            }
        }
    } catch (UnauthorizedException e) {
        throw e;
    } catch (Exception e) {
        throw new SeriesException("Unable to update series " + seriesID + " with property " + propertyName + ":" + propertyValue + " using the remote series services: ", e);
    } finally {
        closeConnection(response);
    }
    throw new SeriesException("Unable to update series " + seriesID + " using the remote series services");
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) SeriesException(org.opencastproject.series.api.SeriesException) ParseException(java.text.ParseException) SeriesException(org.opencastproject.series.api.SeriesException) WebApplicationException(javax.ws.rs.WebApplicationException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException)

Example 85 with UnauthorizedException

use of org.opencastproject.security.api.UnauthorizedException in project opencast by opencast.

the class SeriesServiceRemoteImpl method getSeriesProperties.

@Override
public Map<String, String> getSeriesProperties(String seriesID) throws SeriesException, NotFoundException, UnauthorizedException {
    HttpGet get = new HttpGet(seriesID + "/properties.json");
    HttpResponse response = getResponse(get, SC_OK, SC_NOT_FOUND, SC_UNAUTHORIZED);
    JSONParser parser = new JSONParser();
    try {
        if (response != null) {
            if (SC_NOT_FOUND == response.getStatusLine().getStatusCode()) {
                throw new NotFoundException("Series " + seriesID + " not found in remote series index!");
            } else if (SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
                throw new UnauthorizedException("Not authorized to get series " + seriesID);
            } else {
                logger.debug("Successfully received series {} properties from the remote series index", seriesID);
                StringWriter writer = new StringWriter();
                IOUtils.copy(response.getEntity().getContent(), writer, "UTF-8");
                JSONArray jsonProperties = (JSONArray) parser.parse(writer.toString());
                Map<String, String> properties = new TreeMap<>();
                for (int i = 0; i < jsonProperties.length(); i++) {
                    JSONObject property = (JSONObject) jsonProperties.get(i);
                    JSONArray names = property.names();
                    for (int j = 0; j < names.length(); j++) {
                        properties.put(names.get(j).toString(), property.get(names.get(j).toString()).toString());
                    }
                }
                return properties;
            }
        }
    } catch (UnauthorizedException e) {
        throw e;
    } catch (NotFoundException e) {
        throw e;
    } catch (Exception e) {
        throw new SeriesException("Unable to parse series properties from remote series index: " + e);
    } finally {
        closeConnection(response);
    }
    throw new SeriesException("Unable to get series from remote series index");
}
Also used : StringWriter(java.io.StringWriter) JSONObject(org.codehaus.jettison.json.JSONObject) HttpGet(org.apache.http.client.methods.HttpGet) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) JSONArray(org.codehaus.jettison.json.JSONArray) HttpResponse(org.apache.http.HttpResponse) NotFoundException(org.opencastproject.util.NotFoundException) JSONParser(org.json.simple.parser.JSONParser) SeriesException(org.opencastproject.series.api.SeriesException) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) ParseException(java.text.ParseException) SeriesException(org.opencastproject.series.api.SeriesException) WebApplicationException(javax.ws.rs.WebApplicationException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException)

Aggregations

UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)133 NotFoundException (org.opencastproject.util.NotFoundException)109 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)52 IOException (java.io.IOException)42 SchedulerConflictException (org.opencastproject.scheduler.api.SchedulerConflictException)39 SchedulerTransactionLockException (org.opencastproject.scheduler.api.SchedulerTransactionLockException)38 HttpResponse (org.apache.http.HttpResponse)37 SeriesException (org.opencastproject.series.api.SeriesException)36 WebApplicationException (javax.ws.rs.WebApplicationException)33 Path (javax.ws.rs.Path)29 RestQuery (org.opencastproject.util.doc.rest.RestQuery)29 ParseException (java.text.ParseException)28 MediaPackage (org.opencastproject.mediapackage.MediaPackage)27 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)26 AccessControlList (org.opencastproject.security.api.AccessControlList)22 ArrayList (java.util.ArrayList)21 User (org.opencastproject.security.api.User)21 WorkflowDatabaseException (org.opencastproject.workflow.api.WorkflowDatabaseException)21 HttpGet (org.apache.http.client.methods.HttpGet)19 Date (java.util.Date)18