Search in sources :

Example 1 with EntitlementListener

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

Example 2 with EntitlementListener

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");
    }
}
Also used : 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) Test(org.testng.annotations.Test)

Example 3 with EntitlementListener

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");
    }
}
Also used : 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) Test(org.testng.annotations.Test)

Example 4 with EntitlementListener

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();
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) SMSException(com.sun.identity.sm.SMSException) AttributeSchema(com.sun.identity.sm.AttributeSchema) JSONException(org.json.JSONException) SSOException(com.iplanet.sso.SSOException) EntitlementListener(com.sun.identity.entitlement.EntitlementListener) HashSet(java.util.HashSet)

Example 5 with EntitlementListener

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

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