Search in sources :

Example 11 with Action

use of ddf.action.Action in project ddf by codice.

the class TestMetacardTransformerActionProvider method createMetacardAction.

@Test
public void createMetacardAction() throws MalformedURLException {
    Action action = actionProvider.getAction(metacard);
    assertThat(action.getId(), is(ACTION_PROVIDER_ID));
    assertThat(action.getTitle(), is("Export as " + SAMPLE_TRANSFORMER_ID));
    assertThat(action.getDescription(), is("Provides a URL to the metacard that transforms the return value via the " + SAMPLE_TRANSFORMER_ID + " transformer"));
    assertThat(action.getUrl(), is(actionUrl));
}
Also used : Action(ddf.action.Action) Test(org.junit.Test)

Example 12 with Action

use of ddf.action.Action in project ddf by codice.

the class TestViewMetacardActionProvider method createMetacardAction.

@Test
public void createMetacardAction() throws MalformedURLException {
    Action action = actionProvider.getAction(metacard);
    assertThat(action.getId(), is(ACTION_PROVIDER_ID));
    assertThat(action.getTitle(), is("Export Metacard XML"));
    assertThat(action.getDescription(), is("Provides a URL to the metacard"));
    assertThat(action.getUrl(), is(actionUrl));
}
Also used : Action(ddf.action.Action) Test(org.junit.Test)

Example 13 with Action

use of ddf.action.Action in project ddf by codice.

the class LogoutService method getActionProviders.

@GET
@Path("/actions")
public Response getActionProviders(@Context HttpServletRequest request) throws SecurityServiceException {
    HttpSession session = httpSessionFactory.getOrCreateSession(request);
    Map<String, SecurityToken> realmTokenMap = ((SecurityTokenHolder) session.getAttribute(SecurityConstants.SAML_ASSERTION)).getRealmTokenMap();
    Map<String, Subject> realmSubjectMap = new HashMap<>();
    for (Map.Entry<String, SecurityToken> entry : realmTokenMap.entrySet()) {
        realmSubjectMap.put(entry.getKey(), securityManager.getSubject(entry.getValue()));
    }
    List<Map<String, String>> realmToPropMaps = new ArrayList<>();
    for (ActionProvider actionProvider : logoutActionProviders) {
        Action action = actionProvider.getAction(realmSubjectMap);
        if (action != null) {
            String realm = StringUtils.substringAfterLast(action.getId(), ".");
            //if the user is logged in and isn't a guest, add them
            if (realmTokenMap.get(realm) != null) {
                Map<String, String> actionProperties = new HashMap<>();
                String displayName = SubjectUtils.getName(realmSubjectMap.get(realm), "", true);
                if (displayName != null && !displayName.equals(SubjectUtils.GUEST_DISPLAY_NAME)) {
                    actionProperties.put("title", action.getTitle());
                    actionProperties.put("realm", realm);
                    actionProperties.put("auth", displayName);
                    actionProperties.put("description", action.getDescription());
                    actionProperties.put("url", action.getUrl().toString());
                    realmToPropMaps.add(actionProperties);
                }
            }
        }
    }
    return Response.ok(new ByteArrayInputStream(toJson(realmToPropMaps).getBytes(StandardCharsets.UTF_8))).build();
}
Also used : ActionProvider(ddf.action.ActionProvider) Action(ddf.action.Action) HashMap(java.util.HashMap) HttpSession(javax.servlet.http.HttpSession) ArrayList(java.util.ArrayList) Subject(org.apache.shiro.subject.Subject) SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) SecurityTokenHolder(ddf.security.common.SecurityTokenHolder) ByteArrayInputStream(java.io.ByteArrayInputStream) HashMap(java.util.HashMap) Map(java.util.Map) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 14 with Action

use of ddf.action.Action in project ddf by codice.

the class TestLogoutService method testLogout.

@Test
public void testLogout() throws IOException, ParseException, SecurityServiceException {
    KarafLogoutAction karafLogoutActionProvider = new KarafLogoutAction();
    LdapLogoutAction ldapLogoutActionProvider = new LdapLogoutAction();
    Action karafLogoutAction = karafLogoutActionProvider.getAction(null);
    Action ldapLogoutAction = ldapLogoutActionProvider.getAction(null);
    LogoutService logoutService = new LogoutService();
    logoutService.setHttpSessionFactory(sessionFactory);
    logoutService.setSecurityManager(sm);
    logoutService.setLogoutActionProviders(Arrays.asList(karafLogoutActionProvider, ldapLogoutActionProvider));
    String responseMessage = IOUtils.toString((ByteArrayInputStream) logoutService.getActionProviders(null).getEntity());
    JSONArray actionProperties = (JSONArray) new JSONParser().parse(responseMessage);
    assertEquals(2, actionProperties.size());
    JSONObject karafActionProperty = ((JSONObject) actionProperties.get(0));
    assertEquals(karafActionProperty.get("description"), karafLogoutAction.getDescription());
    assertEquals(karafActionProperty.get("realm"), karafLogoutAction.getId().substring(karafLogoutAction.getId().lastIndexOf(".") + 1));
    assertEquals(karafActionProperty.get("title"), karafLogoutAction.getTitle());
    assertEquals(karafActionProperty.get("url"), karafLogoutAction.getUrl().toString());
    JSONObject ldapActionProperty = ((JSONObject) actionProperties.get(1));
    assertEquals(ldapActionProperty.get("description"), ldapLogoutAction.getDescription());
    assertEquals(ldapActionProperty.get("realm"), ldapLogoutAction.getId().substring(ldapLogoutAction.getId().lastIndexOf(".") + 1));
    assertEquals(ldapActionProperty.get("title"), ldapLogoutAction.getTitle());
    assertEquals(ldapActionProperty.get("url"), ldapLogoutAction.getUrl().toString());
}
Also used : Action(ddf.action.Action) JSONObject(net.minidev.json.JSONObject) JSONArray(net.minidev.json.JSONArray) JSONParser(net.minidev.json.parser.JSONParser) Test(org.junit.Test)

Example 15 with Action

use of ddf.action.Action in project ddf by codice.

the class AdminPollerTest method testAllSourceInfo.

@Test
public void testAllSourceInfo() {
    Action operatorActionOne = getTestAction("operationIdOne", "operationTitle1", "operationDescription1", "https://localhost:8993/provider/someAction");
    Action operatorActionTwo = getTestAction("operationIdTwo", "operationTitleTwo", "operationDescriptionTwo", "https://localhost:8993/provider/someAction");
    ImmutableList<MultiActionProvider> operationActions = ImmutableList.of(getHandleableTestActionProvider(operatorActionOne), getNotHandleableTestActionProvider(), getHandleableTestActionProvider(operatorActionTwo));
    poller.setOperationActionProviders(operationActions);
    Action reportActionOne = getTestAction("reportId", "reportTitle", "reportDescription", "https://localhost:8993/provider/someAction");
    ImmutableList<MultiActionProvider> reportActions = ImmutableList.of(getHandleableTestActionProvider(reportActionOne), getNotHandleableTestActionProvider(), getNotHandleableTestActionProvider());
    poller.setReportActionProviders(reportActions);
    List<Map<String, Object>> sources = poller.allSourceInfo();
    assertThat(sources, notNullValue());
    assertThat(sources.size(), is(2));
    assertThat(sources.get(0), not(hasKey("configurations")));
    assertThat(sources.get(1), hasKey("configurations"));
    List<Map<String, Object>> configurations = (List) sources.get(1).get("configurations");
    assertThat(configurations, hasSize(1));
    Map<String, Object> configurationMap = configurations.get(0);
    assertThat(configurationMap, hasKey("operation_actions"));
    assertThat(configurationMap, hasKey("report_actions"));
    List<Map<String, Object>> operationActionsList = (List) configurationMap.get("operation_actions");
    Map<String, String> operatorActionOneMap = getMapFromAction(operatorActionOne);
    Map<String, String> operatorActionTwoMap = getMapFromAction(operatorActionTwo);
    assertThat(operationActionsList, contains(operatorActionOneMap, operatorActionTwoMap));
    List<Map<String, Object>> reportActionsList = (List) configurationMap.get("report_actions");
    Map<String, String> reportActionMap = getMapFromAction(reportActionOne);
    assertThat(reportActionsList, contains(reportActionMap));
}
Also used : Action(ddf.action.Action) MultiActionProvider(ddf.action.MultiActionProvider) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) Test(org.junit.Test)

Aggregations

Action (ddf.action.Action)44 Test (org.junit.Test)33 URL (java.net.URL)9 HashMap (java.util.HashMap)8 Metacard (ddf.catalog.data.Metacard)7 ActionProvider (ddf.action.ActionProvider)6 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 ActionImpl (ddf.action.impl.ActionImpl)3 MultiActionProvider (ddf.action.MultiActionProvider)2 BinaryContent (ddf.catalog.data.BinaryContent)2 Result (ddf.catalog.data.Result)2 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)2 ResultImpl (ddf.catalog.data.impl.ResultImpl)2 SourceResponse (ddf.catalog.operation.SourceResponse)2 MetacardTransformer (ddf.catalog.transform.MetacardTransformer)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Date (java.util.Date)2