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");
}
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));
}
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");
}
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");
}
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");
}
Aggregations