Package org.apache.syncope.common.to

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


     * @param policy bean.
     * @return policy TO.
     */
    @SuppressWarnings("unchecked")
    public <T extends PolicyTO> T getPolicyTO(final Policy policy) {
        final PolicyTO policyTO;

        final boolean isGlobal = isGlobalPolicy(policy.getType());

        switch (policy.getType()) {
            case GLOBAL_PASSWORD:
            case PASSWORD:
                if (!(policy.getSpecification() instanceof PasswordPolicySpec)) {
                    throw new ClassCastException("Expected " + PasswordPolicySpec.class.getName()
                            + ", found " + policy.getSpecification().getClass().getName());
                }
                policyTO = new PasswordPolicyTO(isGlobal);
                ((PasswordPolicyTO) policyTO).setSpecification((PasswordPolicySpec) policy.getSpecification());
                break;

            case GLOBAL_ACCOUNT:
            case ACCOUNT:
                if (!(policy.getSpecification() instanceof AccountPolicySpec)) {
                    throw new ClassCastException("Expected " + AccountPolicySpec.class.getName()
                            + ", found " + policy.getSpecification().getClass().getName());
                }
                policyTO = new AccountPolicyTO(isGlobal);
                ((AccountPolicyTO) policyTO).setSpecification((AccountPolicySpec) policy.getSpecification());
                break;

            case GLOBAL_SYNC:
            case SYNC:
            default:
                if (!(policy.getSpecification() instanceof SyncPolicySpec)) {
                    throw new ClassCastException("Expected " + SyncPolicySpec.class.getName()
                            + ", found " + policy.getSpecification().getClass().getName());

                }
                policyTO = new SyncPolicyTO(isGlobal);
                ((SyncPolicyTO) policyTO).setSpecification((SyncPolicySpec) policy.getSpecification());
        }

        policyTO.setId(policy.getId());
        policyTO.setDescription(policy.getDescription());

        for (ExternalResource resource : resourceDAO.findByPolicy(policy)) {
            policyTO.getUsedByResources().add(resource.getName());
        }
        if (isGlobal) {
            for (ExternalResource resource : resourceDAO.findWithoutPolicy(policy.getType())) {
                policyTO.getUsedByResources().add(resource.getName());
            }
        }
        for (SyncopeRole role : roleDAO.findByPolicy(policy)) {
            policyTO.getUsedByRoles().add(role.getId());
        }
        if (isGlobal) {
            for (SyncopeRole role : roleDAO.findWithoutPolicy(policy.getType())) {
                policyTO.getUsedByRoles().add(role.getId());
            }
        }

        return (T) policyTO;
    }
View Full Code Here


            LOG.debug("No policy found", ignore);
        }

        if (includeGlobal) {
            try {
                PolicyTO globalPolicy = getGlobalPolicy(type);
                if (globalPolicy != null) {
                    res.add(0, (T) globalPolicy);
                }
            } catch (Exception ignore) {
                LOG.warn("No global policy found", ignore);
View Full Code Here

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

                final PolicyTO accountPolicyTO = model.getObject();

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

                panel.add(new ActionLink() {

                    private static final long serialVersionUID = -3722207913631435501L;

                    @Override
                    public void onClick(final AjaxRequestTarget target) {

                        mwindow.setPageCreator(new ModalWindow.PageCreator() {

                            private static final long serialVersionUID = -7834632442532690940L;

                            @Override
                            public Page createPage() {
                                return new PolicyModalPage(mwindow, accountPolicyTO);
                            }
                        });

                        mwindow.show(target);
                    }
                }, ActionLink.ActionType.EDIT, "Policies");

                panel.add(new ActionLink() {

                    private static final long serialVersionUID = -3722207913631435501L;

                    @Override
                    public void onClick(final AjaxRequestTarget target) {
                        try {
                            policyRestClient.delete(accountPolicyTO.getId(), accountPolicyTO.getClass());
                            info(getString(Constants.OPERATION_SUCCEEDED));
                        } catch (SyncopeClientCompositeErrorException e) {
                            error(getString(Constants.OPERATION_ERROR));

                            LOG.error("While deleting resource {}({})",
                                    accountPolicyTO.getId(), accountPolicyTO.getDescription(), e);
                        }

                        target.add(container);
                        target.add(getPage().get(Constants.FEEDBACK));
                    }
View Full Code Here

            return new CompoundPropertyModel<PolicyTO>(object);
        }
    }

    private PolicyTO getPolicyTOInstance(final PolicyType policyType) {
        PolicyTO policyTO;
        switch (policyType) {
            case GLOBAL_ACCOUNT:
                policyTO = new AccountPolicyTO(true);
                break;
View Full Code Here

            UserTO userTO = getUniqueSampleTO("issue172@syncope.apache.org");
            createUser(userTO);
        } finally {
            for (PasswordPolicyTO policyTO : policies) {
                Response response = policyService.create(PolicyType.GLOBAL_PASSWORD, policyTO);
                PolicyTO cPolicyTO = getObject(response, PasswordPolicyTO.class, policyService);
                assertNotNull(cPolicyTO);
            }
        }
    }
View Full Code Here

            UserTO userTO = getUniqueSampleTO("issue172@syncope.apache.org");
            createUser(userTO);
        } finally {
            for (PasswordPolicyTO policyTO : policies) {
                Response response = policyService.create(PolicyType.GLOBAL_PASSWORD, policyTO);
                PolicyTO cPolicyTO = getObject(response, PasswordPolicyTO.class, policyService);
                assertNotNull(cPolicyTO);
            }
        }
    }
View Full Code Here

TOP

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

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.