DefaultAuthorizableActionProvider implements AuthorizableActionProvider { @NotNull @Override public List<? extends AuthorizableAction> getAuthorizableActions(@NotNull SecurityProvider securityProvider) { List<AuthorizableAction> actions = Lists.newArrayListWithExpectedSize(enabledActions.length); for (String className : enabledActions) { try { Class<? extends AuthorizableAction> cl = SUPPORTED_ACTIONS.get(className); if (cl != null) { AuthorizableAction action = cl.newInstance(); action.init(securityProvider, config); actions.add(action); } } catch (Exception e) { log.debug("Unable to create authorizable action", e); } } return actions; } @SuppressWarnings("UnusedDeclaration")  DefaultAuthorizableActionProvider();  DefaultAuthorizableActionProvider(ConfigurationParameters config); @NotNull @Override List<? extends AuthorizableAction> getAuthorizableActions(@NotNull SecurityProvider securityProvider);  }
@Test public void testNoConfig() { AuthorizableActionProvider[] providers = new AuthorizableActionProvider[] { new DefaultAuthorizableActionProvider(), new DefaultAuthorizableActionProvider(null) }; for (AuthorizableActionProvider actionProvider : providers) { List<? extends AuthorizableAction> actions = actionProvider.getAuthorizableActions(getSecurityProvider()); assertNotNull(actions); assertEquals(1, actions.size()); assertTrue(actions.get(0) instanceof AccessControlAction); } }
@Test public void testEmptyConfig() { AuthorizableActionProvider actionProvider = new DefaultAuthorizableActionProvider(ConfigurationParameters.EMPTY); List<? extends AuthorizableAction> actions = actionProvider.getAuthorizableActions(getSecurityProvider()); assertEquals(1, actions.size()); assertTrue(actions.get(0) instanceof AccessControlAction); }
@Test public void testNullActionConfig() { Map<String, String[]> m = new HashMap<>(); m.put(DefaultAuthorizableActionProvider.ENABLED_ACTIONS, null); AuthorizableActionProvider actionProvider = new DefaultAuthorizableActionProvider(ConfigurationParameters.of(m)); List<? extends AuthorizableAction> actions = actionProvider.getAuthorizableActions(getSecurityProvider()); assertEquals(1, actions.size()); assertTrue(actions.get(0) instanceof AccessControlAction); }
@Test public void testEmtpyActionConfig() { AuthorizableActionProvider actionProvider = new DefaultAuthorizableActionProvider( ConfigurationParameters.of(DefaultAuthorizableActionProvider.ENABLED_ACTIONS, new String[0])); List<? extends AuthorizableAction> actions = actionProvider.getAuthorizableActions(getSecurityProvider()); assertNotNull(actions); assertEquals(0, actions.size()); }
@Test public void testNonExistingClassName() { String[] classNames = new String[] { "org.apache.jackrabbit.oak.spi.security.user.action.NonExistingAction", "" }; AuthorizableActionProvider actionProvider = new DefaultAuthorizableActionProvider( ConfigurationParameters.of(DefaultAuthorizableActionProvider.ENABLED_ACTIONS, classNames)); List<? extends AuthorizableAction> actions = actionProvider.getAuthorizableActions(getSecurityProvider()); assertNotNull(actions); assertEquals(0, actions.size()); }
@Test public void testValidConfig() { String[] classNames = new String[] { PasswordChangeAction.class.getName(), PasswordValidationAction.class.getName() }; AuthorizableActionProvider actionProvider = new DefaultAuthorizableActionProvider( ConfigurationParameters.of(DefaultAuthorizableActionProvider.ENABLED_ACTIONS, classNames)); List<? extends AuthorizableAction> actions = actionProvider.getAuthorizableActions(getSecurityProvider()); assertNotNull(actions); assertEquals(2, actions.size()); assertTrue(actions.get(0) instanceof PasswordChangeAction); assertTrue(actions.get(1) instanceof PasswordValidationAction); }