use of com.sun.identity.entitlement.EntitlementListener in project OpenAM by OpenRock.
the class ListenerResource method addListener.
@POST
@Produces("application/json")
public String addListener(@Context HttpHeaders headers, @Context HttpServletRequest request, @FormParam("url") String url, @FormParam("resources") List<String> resources, @FormParam("application") @DefaultValue("iPlanetAMWebAgentService") String application) {
try {
Subject caller = getCaller(request);
EntitlementListener l = new EntitlementListener(url, application, resources);
ListenerManager.getInstance().addListener(caller, l);
return createResponseJSONString(201, headers, "Created");
} catch (RestException e) {
throw getWebApplicationException(headers, e, MimeType.JSON);
} catch (JSONException e) {
throw getWebApplicationException(e, MimeType.JSON);
} catch (EntitlementException e) {
throw getWebApplicationException(headers, e, MimeType.JSON);
}
}
use of com.sun.identity.entitlement.EntitlementListener in project OpenAM by OpenRock.
the class ListenerRestTest method testAddDifferentApp.
@Test(dependsOnMethods = { "testAddMoreResources" })
public void testAddDifferentApp() throws Exception {
Form form = new Form();
form.add("application", "sunBank");
form.add("subject", hashedTokenId);
form.add("url", NOTIFICATION_URL);
String result = listenerClient.header(RestServiceManager.SUBJECT_HEADER_NAME, tokenIdHeader).cookie(cookie).post(String.class, form);
JSONObject jo = new JSONObject(result);
if (!jo.getString("statusCode").equals(IdRepoErrorCode.ILLEGAL_ARGUMENTS)) {
throw new Exception("ListenerRESTTest.testAddDifferentApp failed to add");
}
Set<EntitlementListener> listeners = ListenerManager.getInstance().getListeners(adminSubject);
if ((listeners == null) || listeners.isEmpty()) {
throw new Exception("ListenerTestTest.testAddDifferentApp: no listeners");
}
}
use of com.sun.identity.entitlement.EntitlementListener in project OpenAM by OpenRock.
the class ListenerRestTest method testRemove.
@Test(dependsOnMethods = { "testAddDifferentApp" })
public void testRemove() throws Exception {
String result = listenerClient.path(ENC_NOTIFICATION_URL).queryParam("subject", hashedTokenId).header(RestServiceManager.SUBJECT_HEADER_NAME, tokenIdHeader).cookie(cookie).delete(String.class);
JSONObject jo = new JSONObject(result);
if (!jo.getString("statusCode").equals("200")) {
throw new Exception("ListenerRESTTest.testRemove failed to remove");
}
Set<EntitlementListener> listeners = ListenerManager.getInstance().getListeners(adminSubject);
if ((listeners != null) && !listeners.isEmpty()) {
throw new Exception("ListenerTestTest.testRemove: no listeners");
}
}
use of com.sun.identity.entitlement.EntitlementListener in project OpenAM by OpenRock.
the class OpenSSOEntitlementListener method storeListeners.
private void storeListeners(List<EntitlementListener> listeners) throws EntitlementException {
rwlock.writeLock().lock();
try {
AttributeSchema as = getAttributeSchema();
Set<String> values = new HashSet<String>();
for (EntitlementListener l : listeners) {
values.add(l.toJSON().toString());
}
as.setDefaultValues(values);
} catch (JSONException e) {
throw new EntitlementException(426, e);
} catch (SMSException e) {
throw new EntitlementException(426, e);
} catch (SSOException e) {
throw new EntitlementException(427, e);
} finally {
rwlock.writeLock().unlock();
}
}
use of com.sun.identity.entitlement.EntitlementListener in project OpenAM by OpenRock.
the class OpenSSOEntitlementListener method removeListener.
public boolean removeListener(Subject adminSubject, String url) throws EntitlementException {
if (url == null) {
throw new EntitlementException(436);
}
try {
URL urlObj = new URL(url);
boolean removed = false;
List<EntitlementListener> listeners = getListeners();
for (int i = listeners.size() - 1; i >= 0; --i) {
EntitlementListener l = listeners.get(i);
if (l.getUrl().equals(urlObj)) {
listeners.remove(l);
removed = true;
break;
}
}
storeListeners(listeners);
return removed;
} catch (MalformedURLException e) {
throw new EntitlementException(435);
}
}
Aggregations