use of com.sun.identity.entitlement.EntitlementListener in project OpenAM by OpenRock.
the class ListenerResource method getListener.
@GET
@Produces("application/json")
@Path("/{url}")
public String getListener(@Context HttpHeaders headers, @Context HttpServletRequest request, @PathParam("url") String url) {
try {
Subject caller = getCaller(request);
EntitlementListener listener = ListenerManager.getInstance().getListener(caller, url);
if (listener == null) {
String[] param = { url.toString() };
throw new EntitlementException(427, param);
}
return createResponseJSONString(200, headers, listener.toJSON());
} catch (JSONException e) {
throw getWebApplicationException(e, MimeType.JSON);
} catch (RestException e) {
throw getWebApplicationException(headers, 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 testGetListener.
@Test(dependsOnMethods = { "testAddDifferentApp" })
public void testGetListener() throws Exception {
try {
String result = getListener(NOTIFICATION_URL);
JSONObject jo = new JSONObject(result);
if (jo.optInt("statusCode") != 200) {
throw new Exception("ListenerRESTTest.postDecisionsTest() failed," + " status code not 200");
}
JSONObject jbody = jo.optJSONObject("body");
if (jbody == null) {
throw new Exception("ListenerRESTTest.postDecisionsTest() failed," + " body element is null");
}
EntitlementListener retrieved = new EntitlementListener(jbody);
Set<String> res = new HashSet<String>();
res.add(RESOURCE_NAME + "/*");
res.add(RESOURCE_NAME + "/a/*");
EntitlementListener listener = new EntitlementListener(new URL(NOTIFICATION_URL), ApplicationTypeManager.URL_APPLICATION_TYPE_NAME, res);
Map<String, Set<String>> mapAppToRes = listener.getMapAppToRes();
mapAppToRes.put("sunBank", new HashSet());
if (!listener.equals(retrieved)) {
throw new Exception("ListenerTestTest.testGetListener: listener not found");
}
} catch (MalformedURLException e) {
//ignore
}
}
use of com.sun.identity.entitlement.EntitlementListener in project OpenAM by OpenRock.
the class ListenerRestTest method testAddMoreResources.
@Test(dependsOnMethods = { "test" })
public void testAddMoreResources() throws Exception {
Form form = new Form();
form.add("resources", RESOURCE_NAME + "/a/*");
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.testAddMoreResources failed to add");
}
Set<EntitlementListener> listeners = ListenerManager.getInstance().getListeners(adminSubject);
if ((listeners == null) || listeners.isEmpty()) {
throw new Exception("ListenerTestTest.testAddMoreResources: no listeners");
}
try {
Set<String> res = new HashSet<String>();
res.add(RESOURCE_NAME + "/*");
res.add(RESOURCE_NAME + "/a/*");
EntitlementListener listener = new EntitlementListener(new URL(NOTIFICATION_URL), ApplicationTypeManager.URL_APPLICATION_TYPE_NAME, res);
boolean found = false;
for (EntitlementListener l : listeners) {
if (l.equals(listener)) {
found = true;
break;
}
}
if (!found) {
throw new Exception("ListenerTestTest.testAddMoreResources: listener not found");
}
} catch (MalformedURLException e) {
//ignore
}
}
use of com.sun.identity.entitlement.EntitlementListener in project OpenAM by OpenRock.
the class ListenerRestTest method test.
@Test(dependsOnMethods = { "negativeTest" })
public void test() throws Exception {
Form form = new Form();
form.add("resources", RESOURCE_NAME + "/*");
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.test failed to add");
}
Set<EntitlementListener> listeners = ListenerManager.getInstance().getListeners(adminSubject);
if ((listeners == null) || listeners.isEmpty()) {
throw new Exception("ListenerTestTest.test: no listeners");
}
try {
Set<String> res = new HashSet<String>();
res.add(RESOURCE_NAME + "/*");
EntitlementListener listener = new EntitlementListener(new URL(NOTIFICATION_URL), ApplicationTypeManager.URL_APPLICATION_TYPE_NAME, res);
boolean found = false;
for (EntitlementListener l : listeners) {
if (l.equals(listener)) {
found = true;
break;
}
}
if (!found) {
throw new Exception("ListenerTestTest.test: listener not found");
}
} catch (MalformedURLException e) {
//ignore
}
}
use of com.sun.identity.entitlement.EntitlementListener in project OpenAM by OpenRock.
the class OpenSSOEntitlementListener method addListener.
public void addListener(Subject adminSubject, EntitlementListener l) throws EntitlementException {
for (String applName : l.getMapAppToRes().keySet()) {
if (!doesApplicationExist(applName)) {
String[] params = { applName };
throw new EntitlementException(431, params);
}
}
List<EntitlementListener> listeners = getListeners();
boolean combined = false;
for (EntitlementListener listener : listeners) {
if (listener.combine(l)) {
combined = true;
break;
}
}
if (!combined) {
listeners.add(l);
}
storeListeners(listeners);
}
Aggregations