Package org.apache.syncope.common.to

Examples of org.apache.syncope.common.to.ConfigurationTO


public class UserRequestTestITCase extends AbstractTest {

    @Test
    public void create() throws InvalidSearchConditionException {
        // 1. set create request not allowed
        ConfigurationTO configurationTO = new ConfigurationTO();
        configurationTO.setKey("createRequest.allowed");
        configurationTO.setValue("false");

        Response response = configurationService.create(configurationTO);
        assertNotNull(response);
        assertEquals(org.apache.http.HttpStatus.SC_CREATED, response.getStatus());
        configurationTO = getObject(response, ConfigurationTO.class, configurationService);
        assertNotNull(configurationTO);

        UserTO userTO = UserTestITCase.getUniqueSampleTO("selfcreate@syncope.apache.org");

        // 2. get unauthorized when trying to request user create
        try {
            createUserRequest(userRequestService, new UserRequestTO(userTO));
            fail();
        } catch (SyncopeClientCompositeErrorException e) {
            assertNotNull(e.getException(SyncopeClientExceptionType.UnauthorizedRole));
        }

        // 3. set create request allowed
        configurationTO.setValue("true");

        response = configurationService.create(configurationTO);
        assertNotNull(response);
        assertEquals(org.apache.http.HttpStatus.SC_CREATED, response.getStatus());
        configurationTO = getObject(response, ConfigurationTO.class, configurationService);
View Full Code Here


            @Override
            public void populateItem(final Item<ICellPopulator<ConfigurationTO>> cellItem, final String componentId,
                    final IModel<ConfigurationTO> model) {

                final ConfigurationTO configurationTO = model.getObject();

                final ActionLinksPanel panel = new ActionLinksPanel(componentId, model, getPageReference());

                panel.add(new ActionLink() {

                    private static final long serialVersionUID = -3722207913631435501L;

                    @Override
                    public void onClick(final AjaxRequestTarget target) {

                        editConfigWin.setPageCreator(new ModalWindow.PageCreator() {

                            private static final long serialVersionUID = -7834632442532690940L;

                            @Override
                            public Page createPage() {
                                return new ConfigurationModalPage(Configuration.this.getPageReference(), editConfigWin,
                                        configurationTO, false);
                            }
                        });

                        editConfigWin.show(target);
                    }
                }, ActionLink.ActionType.EDIT, "Configuration");

                panel.add(new ActionLink() {

                    private static final long serialVersionUID = -3722207913631435501L;

                    @Override
                    public void onClick(final AjaxRequestTarget target) {
                        try {
                            confRestClient.deleteConfiguration(configurationTO.getKey());
                        } catch (SyncopeClientCompositeErrorException e) {
                            LOG.error("While deleting a conf key", e);
                            error(e.getMessage());
                            return;
                        }

                        info(getString("operation_succeeded"));
                        target.add(feedbackPanel);

                        target.add(confContainer);
                    }
                }, ActionLink.ActionType.DELETE, "Configuration");

                cellItem.add(panel);
            }
        });

        final AjaxFallbackDefaultDataTable confTable = new AjaxFallbackDefaultDataTable("syncopeconf", confColumns,
                new SyncopeConfProvider(), confPaginatorRows);

        confContainer = new WebMarkupContainer("confContainer");
        confContainer.add(confTable);
        confContainer.setOutputMarkupId(true);

        add(confContainer);

        createConfigWin.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
        createConfigWin.setInitialHeight(CONFIG_WIN_HEIGHT);
        createConfigWin.setInitialWidth(CONFIG_WIN_WIDTH);
        createConfigWin.setCookieName("create-configuration-modal");

        editConfigWin.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
        editConfigWin.setInitialHeight(CONFIG_WIN_HEIGHT);
        editConfigWin.setInitialWidth(CONFIG_WIN_WIDTH);
        editConfigWin.setCookieName("edit-configuration-modal");

        setWindowClosedCallback(createConfigWin, confContainer);
        setWindowClosedCallback(editConfigWin, confContainer);

        AjaxLink createConfigurationLink = new AjaxLink("createConfigurationLink") {

            private static final long serialVersionUID = -7978723352517770644L;

            @Override
            public void onClick(final AjaxRequestTarget target) {

                createConfigWin.setPageCreator(new ModalWindow.PageCreator() {

                    private static final long serialVersionUID = -7834632442532690940L;

                    @Override
                    public Page createPage() {
                        return new ConfigurationModalPage(Configuration.this.getPageReference(), createConfigWin,
                                new ConfigurationTO(), true);
                    }
                });

                createConfigWin.show(target);
            }
View Full Code Here

    private UriInfo uriInfo;

    @Override
    public Response create(final ConfigurationTO configurationTO) {
        ConfigurationTO created = configurationController.create(new DummyHTTPServletResponse(), configurationTO);
        URI location = uriInfo.getAbsolutePathBuilder().path(created.getKey()).build();
        return Response.created(location).
                header(SyncopeConstants.REST_HEADER_ID, created.getKey()).
                build();
    }
View Full Code Here

        }
    }

    @Test()
    public void issueSYNCOPE51() {
        ConfigurationTO defaultConfigurationTO = configurationService.read("password.cipher.algorithm");

        ConfigurationTO configurationTO = new ConfigurationTO();
        configurationTO.setKey("password.cipher.algorithm");
        configurationTO.setValue("MD5");

        configurationService.update(configurationTO.getKey(), configurationTO);
        ConfigurationTO newConfTO = configurationService.read(configurationTO.getKey());

        assertEquals(configurationTO, newConfTO);

        UserTO userTO = getSampleTO("syncope51@syncope.apache.org");
        userTO.setPassword("password");

        try {
            createUser(userTO);
            fail("Create user should not succeed");
        } catch (SyncopeClientCompositeErrorException e) {
            assertTrue(e.getException(SyncopeClientExceptionType.NotFound).getElements().iterator().next()
                    .contains("MD5"));
        }

        configurationService.update(defaultConfigurationTO.getKey(), defaultConfigurationTO);
        ConfigurationTO oldConfTO = configurationService.read(defaultConfigurationTO.getKey());

        assertEquals(defaultConfigurationTO, oldConfTO);
    }
View Full Code Here

    }

    @Test
    public void isseSYNCOPE136AES() {
        // 1. read configured cipher algorithm in order to be able to restore it at the end of test
        ConfigurationTO pwdCipherAlgo = configurationService.read("password.cipher.algorithm");
        final String origpwdCipherAlgo = pwdCipherAlgo.getValue();

        // 2. set AES password cipher algorithm
        pwdCipherAlgo.setValue("AES");
        configurationService.update(pwdCipherAlgo.getKey(), pwdCipherAlgo);

        try {
            // 3. create user with no resources
            UserTO userTO = getUniqueSampleTO("syncope136_AES@apache.org");
            userTO.getResources().clear();

            userTO = userService.create(userTO).readEntity(UserTO.class);
            assertNotNull(userTO);

            // 4. update user, assign a propagation primary resource but don't provide any password
            UserMod userMod = new UserMod();
            userMod.setId(userTO.getId());
            userMod.addResourceToBeAdded("ws-target-resource-1");

            userTO = userService.update(userMod.getId(), userMod);
            assertNotNull(userTO);

            // 5. verify that propagation was successful
            List<PropagationStatusTO> props = userTO.getPropagationStatusTOs();
            assertNotNull(props);
            assertEquals(1, props.size());
            PropagationStatusTO prop = props.iterator().next();
            assertNotNull(prop);
            assertEquals("ws-target-resource-1", prop.getResource());
            assertEquals(PropagationTaskExecStatus.SUCCESS, prop.getStatus());
        } catch (Exception e) {
            LOG.error("Unexpected exception", e);
        } finally {
            // 6. restore initial cipher algorithm
            pwdCipherAlgo.setValue(origpwdCipherAlgo);
            configurationService.update(pwdCipherAlgo.getKey(), pwdCipherAlgo);
        }
    }
View Full Code Here

        }
    }

    @Test()
    public void issueSYNCOPE51() {
        ConfigurationTO defaultConfigurationTO = configurationService.read("password.cipher.algorithm");

        ConfigurationTO configurationTO = new ConfigurationTO();
        configurationTO.setKey("password.cipher.algorithm");
        configurationTO.setValue("MD5");

        configurationService.update(configurationTO.getKey(), configurationTO);
        ConfigurationTO newConfTO = configurationService.read(configurationTO.getKey());

        assertEquals(configurationTO, newConfTO);

        UserTO userTO = getSampleTO("syncope51@syncope.apache.org");
        userTO.setPassword("password");

        try {
            createUser(userTO);
            fail("Create user should not succeed");
        } catch (SyncopeClientCompositeErrorException e) {
            assertTrue(e.getException(SyncopeClientExceptionType.NotFound).getElements().iterator().next()
                    .contains("MD5"));
        }

        configurationService.update(defaultConfigurationTO.getKey(), defaultConfigurationTO);
        ConfigurationTO oldConfTO = configurationService.read(defaultConfigurationTO.getKey());

        assertEquals(defaultConfigurationTO, oldConfTO);
    }
View Full Code Here

    }

    @Test
    public void isseSYNCOPE136AES() {
        // 1. read configured cipher algorithm in order to be able to restore it at the end of test
        ConfigurationTO pwdCipherAlgo = configurationService.read("password.cipher.algorithm");
        final String origpwdCipherAlgo = pwdCipherAlgo.getValue();

        // 2. set AES password cipher algorithm
        pwdCipherAlgo.setValue("AES");
        configurationService.update(pwdCipherAlgo.getKey(), pwdCipherAlgo);

        try {
            // 3. create user with no resources
            UserTO userTO = getUniqueSampleTO("syncope136_AES@apache.org");
            userTO.getResources().clear();

            userTO = userService.create(userTO).readEntity(UserTO.class);
            assertNotNull(userTO);

            // 4. update user, assign a propagation primary resource but don't provide any password
            UserMod userMod = new UserMod();
            userMod.setId(userTO.getId());
            userMod.addResourceToBeAdded("ws-target-resource-1");

            userTO = userService.update(userMod.getId(), userMod);
            assertNotNull(userTO);

            // 5. verify that propagation was successful
            List<PropagationStatusTO> props = userTO.getPropagationStatusTOs();
            assertNotNull(props);
            assertEquals(1, props.size());
            PropagationStatusTO prop = props.iterator().next();
            assertNotNull(prop);
            assertEquals("ws-target-resource-1", prop.getResource());
            assertEquals(PropagationTaskExecStatus.SUCCESS, prop.getStatus());
        } catch (Exception e) {
            LOG.error("Unexpected exception", e);
        } finally {
            // 6. restore initial cipher algorithm
            pwdCipherAlgo.setValue(origpwdCipherAlgo);
            configurationService.update(pwdCipherAlgo.getKey(), pwdCipherAlgo);
        }
    }
View Full Code Here

    @PreAuthorize("hasRole('CONFIGURATION_DELETE')")
    @RequestMapping(method = RequestMethod.GET, value = "/delete/{key}")
    public ConfigurationTO delete(@PathVariable("key") final String key) {
        SyncopeConf conf = confDAO.find(key);
        ConfigurationTO confToDelete = binder.getConfigurationTO(conf);
        confDAO.delete(key);

        auditManager.audit(Category.configuration, ConfigurationSubCategory.delete, Result.success,
                "Successfully deleted conf: " + key);
        return confToDelete;
View Full Code Here

    }

    @PreAuthorize("hasRole('CONFIGURATION_READ')")
    @RequestMapping(method = RequestMethod.GET, value = "/read/{key}")
    public ConfigurationTO read(final HttpServletResponse response, @PathVariable("key") final String key) {
        ConfigurationTO result;
        try {
            SyncopeConf conf = confDAO.find(key);
            result = binder.getConfigurationTO(conf);

            auditManager.audit(Category.configuration, ConfigurationSubCategory.read, Result.success,
                    "Successfully read conf: " + key);
        } catch (MissingConfKeyException e) {
            LOG.error("Could not find configuration key '" + key + "', returning null");

            result = new ConfigurationTO();
            result.setKey(key);

            auditManager.audit(Category.configuration, ConfigurationSubCategory.read, Result.failure,
                    "Could not find conf: " + key);
        }
View Full Code Here

        return syncopeConfiguration;
    }

    public ConfigurationTO getConfigurationTO(final SyncopeConf syncopeConfiguration) {
        ConfigurationTO configurationTO = new ConfigurationTO();
        configurationTO.setKey(syncopeConfiguration.getKey());
        configurationTO.setValue(syncopeConfiguration.getValue());

        return configurationTO;
    }
View Full Code Here

TOP

Related Classes of org.apache.syncope.common.to.ConfigurationTO

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.