Search in sources :

Example 6 with EntitlementListener

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);
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) JSONException(org.json.JSONException) EntitlementListener(com.sun.identity.entitlement.EntitlementListener) Subject(javax.security.auth.Subject) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 7 with EntitlementListener

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
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) HashSet(java.util.HashSet) Set(java.util.Set) JSONObject(org.json.JSONObject) EntitlementListener(com.sun.identity.entitlement.EntitlementListener) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) EncodingException(org.owasp.esapi.errors.EncodingException) MalformedURLException(java.net.MalformedURLException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) URL(java.net.URL) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 8 with EntitlementListener

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
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) JSONObject(org.json.JSONObject) Form(com.sun.jersey.api.representation.Form) EntitlementListener(com.sun.identity.entitlement.EntitlementListener) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) EncodingException(org.owasp.esapi.errors.EncodingException) MalformedURLException(java.net.MalformedURLException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) URL(java.net.URL) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 9 with EntitlementListener

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
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) JSONObject(org.json.JSONObject) Form(com.sun.jersey.api.representation.Form) EntitlementListener(com.sun.identity.entitlement.EntitlementListener) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) EncodingException(org.owasp.esapi.errors.EncodingException) MalformedURLException(java.net.MalformedURLException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) URL(java.net.URL) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 10 with EntitlementListener

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);
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) EntitlementListener(com.sun.identity.entitlement.EntitlementListener)

Aggregations

EntitlementListener (com.sun.identity.entitlement.EntitlementListener)11 EntitlementException (com.sun.identity.entitlement.EntitlementException)6 MalformedURLException (java.net.MalformedURLException)6 JSONObject (org.json.JSONObject)6 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 EncodingException (org.owasp.esapi.errors.EncodingException)5 Test (org.testng.annotations.Test)5 URL (java.net.URL)4 HashSet (java.util.HashSet)4 JSONException (org.json.JSONException)4 Form (com.sun.jersey.api.representation.Form)3 SSOException (com.iplanet.sso.SSOException)2 AttributeSchema (com.sun.identity.sm.AttributeSchema)2 SMSException (com.sun.identity.sm.SMSException)2 Subject (javax.security.auth.Subject)2 Produces (javax.ws.rs.Produces)2 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 GET (javax.ws.rs.GET)1