Example usage for org.apache.commons.lang3.tuple Pair getKey

List of usage examples for org.apache.commons.lang3.tuple Pair getKey

Introduction

In this page you can find the example usage for org.apache.commons.lang3.tuple Pair getKey.

Prototype

@Override
public final L getKey() 

Source Link

Document

Gets the key from this pair.

This method implements the Map.Entry interface returning the left element as the key.

Usage

From source file:org.apache.syncope.client.console.panels.LoggerCategoryPanel.java

@Override
@SuppressWarnings("unchecked")
public void onEvent(final IEvent<?> event) {
    if (event.getPayload() instanceof ChangeCategoryEvent) {
        // update objects ....
        eventCategoryTO.getEvents().clear();

        final ChangeCategoryEvent change = (ChangeCategoryEvent) event.getPayload();

        final Panel changedPanel = change.getChangedPanel();
        if ("type".equals(changedPanel.getId())) {
            eventCategoryTO.setType(type.getModelObject());
            eventCategoryTO.setCategory(null);
            eventCategoryTO.setSubcategory(null);

            if (type.getModelObject() == EventCategoryType.CUSTOM) {
                category.setChoices(Collections.<String>emptyList());
                subcategory.setChoices(Collections.<String>emptyList());
                category.setEnabled(false);
                subcategory.setEnabled(false);
                custom.setVisible(true);
                custom.setEnabled(true);
                actionPanel.setVisible(true);
                actionPanel.setEnabled(true);

            } else {
                category.setChoices(filter(eventCategoryTOs, type.getModelObject()));
                subcategory.setChoices(Collections.<String>emptyList());
                category.setEnabled(true);
                subcategory.setEnabled(true);
                custom.setVisible(false);
                custom.setEnabled(false);
                actionPanel.setVisible(false);
                actionPanel.setEnabled(false);
            }//ww w . j  av  a2s  .  co  m
            change.getTarget().add(categoryContainer);
        } else if ("category".equals(changedPanel.getId())) {
            subcategory.setChoices(filter(eventCategoryTOs, type.getModelObject(), category.getModelObject()));
            eventCategoryTO.setCategory(category.getModelObject());
            eventCategoryTO.setSubcategory(null);
            change.getTarget().add(categoryContainer);
        } else {
            eventCategoryTO.setSubcategory(subcategory.getModelObject());
        }

        updateEventsContainer(change.getTarget());
    } else if (event.getPayload() instanceof InspectSelectedEvent) {
        // update objects ....
        eventCategoryTO.getEvents().clear();

        InspectSelectedEvent inspectSelectedEvent = (InspectSelectedEvent) event.getPayload();

        Pair<EventCategoryTO, AuditElements.Result> categoryEvent = AuditLoggerName
                .parseEventCategory(inspectSelectedEvent.getEvent());

        eventCategoryTO.setType(categoryEvent.getKey().getType());
        category.setChoices(filter(eventCategoryTOs, type.getModelObject()));

        eventCategoryTO.setCategory(categoryEvent.getKey().getCategory());
        subcategory.setChoices(filter(eventCategoryTOs, type.getModelObject(), category.getModelObject()));

        eventCategoryTO.setSubcategory(categoryEvent.getKey().getSubcategory());

        if (categoryEvent.getKey().getType() == EventCategoryType.CUSTOM) {
            custom.setModelObject(
                    AuditLoggerName.buildEvent(categoryEvent.getKey().getType(),
                            categoryEvent.getKey().getCategory(), categoryEvent.getKey().getSubcategory(),
                            categoryEvent.getKey().getEvents().isEmpty() ? StringUtils.EMPTY
                                    : categoryEvent.getKey().getEvents().iterator().next(),
                            categoryEvent.getValue()));

            category.setEnabled(false);
            subcategory.setEnabled(false);
            custom.setVisible(true);
            custom.setEnabled(true);
            actionPanel.setVisible(true);
            actionPanel.setEnabled(true);
        } else {
            category.setEnabled(true);
            subcategory.setEnabled(true);
            custom.setVisible(false);
            custom.setEnabled(false);
            actionPanel.setVisible(false);
            actionPanel.setEnabled(false);
        }

        inspectSelectedEvent.getTarget().add(categoryContainer);
        updateEventsContainer(inspectSelectedEvent.getTarget());
    }
}

From source file:org.apache.syncope.client.console.panels.RealmChoicePanel.java

public final void reloadRealmTree() {
    final Label realmLabel = new Label("realmLabel", new Model<>());
    realmLabel.setOutputMarkupId(true);/*  www.  j  av  a 2 s .c  o  m*/

    container.addOrReplace(realmLabel);

    if (model.getObject().getFullPath().startsWith(SyncopeConstants.ROOT_REALM)) {
        realmLabel.setDefaultModel(new ResourceModel("realmLabel", "Realm"));
    } else {
        realmLabel.setDefaultModel(new ResourceModel("dynRealmLabel", "Dynamic Realm"));
    }

    final Label label = new Label("realm", model.getObject().getFullPath());
    label.setOutputMarkupId(true);
    container.addOrReplace(label);

    final DropDownButton realms = new DropDownButton("realms", new ResourceModel("select", ""),
            new Model<IconType>(GlyphIconType.folderopen)) {

        private static final long serialVersionUID = -5560086780455361131L;

        @Override
        protected List<AbstractLink> newSubMenuButtons(final String buttonMarkupId) {
            RealmChoicePanel.this.links.clear();

            RealmChoicePanel.this.links.add(new BootstrapAjaxLink<RealmTO>(ButtonList.getButtonMarkupId(),
                    new Model<RealmTO>(), Buttons.Type.Link, new ResourceModel("realms", "Realms")) {

                private static final long serialVersionUID = -7978723352517770744L;

                @Override
                public void onClick(final AjaxRequestTarget target) {
                }

                @Override
                public boolean isEnabled() {
                    return false;
                }

                @Override
                protected void onComponentTag(final ComponentTag tag) {
                    tag.put("class", "panel box box-primary box-header with-border");
                    tag.put("style", "margin: 20px 5px 0px 5px; width: 90%");
                }
            });

            for (Pair<String, RealmTO> link : realmTree.getObject()) {
                final RealmTO realmTO = link.getValue();
                RealmChoicePanel.this.links.add(new BootstrapAjaxLink<RealmTO>(ButtonList.getButtonMarkupId(),
                        Model.of(realmTO), Buttons.Type.Link, new Model<>(link.getKey())) {

                    private static final long serialVersionUID = -7978723352517770644L;

                    @Override
                    public void onClick(final AjaxRequestTarget target) {
                        model.setObject(realmTO);
                        label.setDefaultModelObject(model.getObject().getFullPath());
                        realmLabel.setDefaultModel(new ResourceModel("realmLabel", "Realm"));
                        target.add(label);
                        send(pageRef.getPage(), Broadcast.EXACT, new ChosenRealm<>(realmTO, target));
                    }

                    @Override
                    public boolean isEnabled() {
                        return availableRealms.stream()
                                .anyMatch(availableRealm -> realmTO.getFullPath().startsWith(availableRealm));
                    }
                });
            }

            if (!dynRealmTree.getObject().isEmpty()) {
                RealmChoicePanel.this.links.add(
                        new BootstrapAjaxLink<RealmTO>(ButtonList.getButtonMarkupId(), new Model<RealmTO>(),
                                Buttons.Type.Link, new ResourceModel("dynrealms", "Dynamic Realms")) {

                            private static final long serialVersionUID = -7978723352517770744L;

                            @Override
                            public void onClick(final AjaxRequestTarget target) {

                            }

                            @Override
                            public boolean isEnabled() {
                                return false;
                            }

                            @Override
                            protected void onComponentTag(final ComponentTag tag) {
                                tag.put("class", "panel box box-primary box-header with-border");
                                tag.put("style", "margin: 20px 5px 0px 5px; width: 90%");
                            }
                        });

                for (DynRealmTO dynRealmTO : dynRealmTree.getObject()) {
                    final RealmTO realmTO = new RealmTO();
                    realmTO.setKey(dynRealmTO.getKey());
                    realmTO.setName(dynRealmTO.getKey());
                    realmTO.setFullPath(dynRealmTO.getKey());

                    RealmChoicePanel.this.links
                            .add(new BootstrapAjaxLink<RealmTO>(ButtonList.getButtonMarkupId(),
                                    new Model<RealmTO>(), Buttons.Type.Link, new Model<>(realmTO.getKey())) {

                                private static final long serialVersionUID = -7978723352517770644L;

                                @Override
                                public void onClick(final AjaxRequestTarget target) {
                                    model.setObject(realmTO);
                                    label.setDefaultModelObject(realmTO.getKey());
                                    realmLabel.setDefaultModel(
                                            new ResourceModel("dynRealmLabel", "Dynamic Realm"));
                                    target.add(label);
                                    send(pageRef.getPage(), Broadcast.EXACT,
                                            new ChosenRealm<>(realmTO, target));
                                }

                                @Override
                                public boolean isEnabled() {
                                    return availableRealms.stream().anyMatch(availableRealm -> {
                                        return SyncopeConstants.ROOT_REALM.equals(availableRealm)
                                                || realmTO.getKey().equals(availableRealm);
                                    });
                                }
                            });
                }
            }

            return RealmChoicePanel.this.links;
        }
    };
    realms.setOutputMarkupId(true);
    realms.setAlignment(AlignmentBehavior.Alignment.RIGHT);
    realms.setType(Buttons.Type.Menu);

    MetaDataRoleAuthorizationStrategy.authorize(realms, ENABLE, StandardEntitlement.REALM_LIST);

    container.addOrReplace(realms);
}

From source file:org.apache.syncope.core.logic.AnyObjectLogic.java

public ProvisioningResult<AnyObjectTO> create(final AnyObjectTO anyObjectTO, final boolean nullPriorityAsync) {
    Pair<AnyObjectTO, List<LogicActions>> before = beforeCreate(anyObjectTO);

    if (before.getLeft().getRealm() == null) {
        throw SyncopeClientException.build(ClientExceptionType.InvalidRealm);
    }/*from  w ww .j  a  va 2 s .  c  om*/
    if (before.getLeft().getType() == null) {
        throw SyncopeClientException.build(ClientExceptionType.InvalidAnyType);
    }

    Set<String> effectiveRealms = RealmUtils.getEffective(
            AuthContextUtils.getAuthorizations().get(AnyEntitlement.CREATE.getFor(before.getLeft().getType())),
            before.getLeft().getRealm());
    securityChecks(effectiveRealms, before.getLeft().getRealm(), null);

    Pair<String, List<PropagationStatus>> created = provisioningManager.create(before.getLeft(),
            nullPriorityAsync);

    return afterCreate(binder.getAnyObjectTO(created.getKey()), created.getRight(), before.getRight());
}

From source file:org.apache.syncope.core.logic.GroupLogic.java

@PreAuthorize("hasRole('" + StandardEntitlement.GROUP_CREATE + "')")
public ProvisioningResult<GroupTO> create(final GroupTO groupTO, final boolean nullPriorityAsync) {
    Pair<GroupTO, List<LogicActions>> before = beforeCreate(groupTO);

    if (before.getLeft().getRealm() == null) {
        throw SyncopeClientException.build(ClientExceptionType.InvalidRealm);
    }//from  ww w. java2s .  c o  m

    Set<String> effectiveRealms = RealmUtils.getEffective(
            AuthContextUtils.getAuthorizations().get(StandardEntitlement.GROUP_CREATE),
            before.getLeft().getRealm());
    securityChecks(effectiveRealms, before.getLeft().getRealm(), null);

    Pair<String, List<PropagationStatus>> created = provisioningManager.create(before.getLeft(),
            nullPriorityAsync);

    return afterCreate(binder.getGroupTO(created.getKey()), created.getRight(), before.getRight());
}

From source file:org.apache.syncope.core.logic.saml2.SAML2UserManager.java

@Transactional(propagation = Propagation.REQUIRES_NEW)
public String create(final SAML2IdPEntity idp, final SAML2LoginResponseTO responseTO, final String nameID) {
    UserTO userTO = new UserTO();

    if (idp.getUserTemplate() != null) {
        templateUtils.apply(userTO, idp.getUserTemplate());
    }/* ww w . java2 s  . c o  m*/

    List<SAML2IdPActions> actions = getActions(idp);
    for (SAML2IdPActions action : actions) {
        userTO = action.beforeCreate(userTO, responseTO);
    }

    fill(idp.getKey(), responseTO, userTO);

    if (userTO.getRealm() == null) {
        userTO.setRealm(SyncopeConstants.ROOT_REALM);
    }
    if (userTO.getUsername() == null) {
        userTO.setUsername(nameID);
    }

    Pair<String, List<PropagationStatus>> created = provisioningManager.create(userTO, false, false);
    userTO = binder.getUserTO(created.getKey());

    for (SAML2IdPActions action : actions) {
        userTO = action.afterCreate(userTO, responseTO);
    }

    return userTO.getUsername();
}

From source file:org.apache.syncope.core.logic.UserLogic.java

protected ProvisioningResult<UserTO> doCreate(final UserTO userTO, final boolean storePassword,
        final boolean self, final boolean nullPriorityAsync) {

    Pair<UserTO, List<LogicActions>> before = beforeCreate(userTO);

    if (before.getLeft().getRealm() == null) {
        throw SyncopeClientException.build(ClientExceptionType.InvalidRealm);
    }//from  w w  w  . j  av  a 2 s  . c om

    if (!self) {
        Set<String> effectiveRealms = RealmUtils.getEffective(
                AuthContextUtils.getAuthorizations().get(StandardEntitlement.USER_CREATE),
                before.getLeft().getRealm());
        securityChecks(effectiveRealms, before.getLeft().getRealm(), null);
    }

    Pair<String, List<PropagationStatus>> created = provisioningManager.create(before.getLeft(), storePassword,
            nullPriorityAsync);

    return afterCreate(binder.returnUserTO(binder.getUserTO(created.getKey())), created.getRight(),
            before.getRight());
}

From source file:org.apache.syncope.core.logic.UserLogic.java

@PreAuthorize("hasRole('" + StandardEntitlement.USER_UPDATE + "')")
public ProvisioningResult<UserTO> status(final StatusPatch statusPatch, final boolean nullPriorityAsync) {
    // security checks
    UserTO toUpdate = binder.getUserTO(statusPatch.getKey());
    Set<String> effectiveRealms = RealmUtils.getEffective(
            AuthContextUtils.getAuthorizations().get(StandardEntitlement.USER_UPDATE), toUpdate.getRealm());
    securityChecks(effectiveRealms, toUpdate.getRealm(), toUpdate.getKey());

    // ensures the actual user key is effectively on the patch - as the binder.getUserTO(statusPatch.getKey())
    // call above works with username as well
    statusPatch.setKey(toUpdate.getKey());
    Pair<String, List<PropagationStatus>> updated = setStatusOnWfAdapter(statusPatch, nullPriorityAsync);

    return afterUpdate(binder.returnUserTO(binder.getUserTO(updated.getKey())), updated.getRight(),
            Collections.<LogicActions>emptyList(), false, Collections.<String>emptySet());
}

From source file:org.apache.syncope.core.misc.MappingUtils.java

/**
 * Prepare attributes for sending to a connector instance.
 *
 * @param any given any object/*from  w  w  w. j  a  va  2s . c om*/
 * @param password clear-text password
 * @param changePwd whether password should be included for propagation attributes or not
 * @param vAttrsToBeRemoved virtual attributes to be removed
 * @param vAttrsToBeUpdated virtual attributes to be added
 * @param enable whether any object must be enabled or not
 * @param provision provision information
 * @return connObjectLink + prepared attributes
 */
public static Pair<String, Set<Attribute>> prepareAttrs(final Any<?, ?, ?> any, final String password,
        final boolean changePwd, final Set<String> vAttrsToBeRemoved,
        final Map<String, AttrMod> vAttrsToBeUpdated, final Boolean enable, final Provision provision) {

    LOG.debug("Preparing resource attributes for {} with provision {} for attributes {}", any, provision,
            any.getPlainAttrs());

    ConfigurableApplicationContext context = ApplicationContextProvider.getApplicationContext();
    VirAttrCache virAttrCache = context.getBean(VirAttrCache.class);
    PasswordGenerator passwordGenerator = context.getBean(PasswordGenerator.class);

    Set<Attribute> attributes = new HashSet<>();
    String connObjectKey = null;

    for (MappingItem mapping : getMappingItems(provision, MappingPurpose.PROPAGATION)) {
        LOG.debug("Processing schema {}", mapping.getIntAttrName());

        try {
            if (mapping.getIntMappingType() == IntMappingType.UserVirtualSchema
                    || mapping.getIntMappingType() == IntMappingType.GroupVirtualSchema
                    || mapping.getIntMappingType() == IntMappingType.AnyObjectVirtualSchema) {

                LOG.debug("Expire entry cache {}-{}", any.getKey(), mapping.getIntAttrName());
                virAttrCache.expire(any.getType().getKey(), any.getKey(), mapping.getIntAttrName());
            }

            Pair<String, Attribute> preparedAttr = prepareAttr(provision, mapping, any, password,
                    passwordGenerator, vAttrsToBeRemoved, vAttrsToBeUpdated);

            if (preparedAttr != null && preparedAttr.getKey() != null) {
                connObjectKey = preparedAttr.getKey();
            }

            if (preparedAttr != null && preparedAttr.getValue() != null) {
                Attribute alreadyAdded = AttributeUtil.find(preparedAttr.getValue().getName(), attributes);

                if (alreadyAdded == null) {
                    attributes.add(preparedAttr.getValue());
                } else {
                    attributes.remove(alreadyAdded);

                    Set<Object> values = new HashSet<>(alreadyAdded.getValue());
                    values.addAll(preparedAttr.getValue().getValue());

                    attributes.add(AttributeBuilder.build(preparedAttr.getValue().getName(), values));
                }
            }
        } catch (Exception e) {
            LOG.debug("Attribute '{}' processing failed", mapping.getIntAttrName(), e);
        }
    }

    Attribute connObjectKeyExtAttr = AttributeUtil.find(getConnObjectKeyItem(provision).getExtAttrName(),
            attributes);
    if (connObjectKeyExtAttr != null) {
        attributes.remove(connObjectKeyExtAttr);
        attributes.add(AttributeBuilder.build(getConnObjectKeyItem(provision).getExtAttrName(), connObjectKey));
    }
    attributes.add(evaluateNAME(any, provision, connObjectKey));

    if (enable != null) {
        attributes.add(AttributeBuilder.buildEnabled(enable));
    }
    if (!changePwd) {
        Attribute pwdAttr = AttributeUtil.find(OperationalAttributes.PASSWORD_NAME, attributes);
        if (pwdAttr != null) {
            attributes.remove(pwdAttr);
        }
    }

    return new ImmutablePair<>(connObjectKey, attributes);
}

From source file:org.apache.syncope.core.misc.MappingUtils.java

private static String getGroupOwnerValue(final Provision provision, final Any<?, ?, ?> any) {
    Pair<String, Attribute> preparedAttr = prepareAttr(provision, getConnObjectKeyItem(provision), any, null,
            null, Collections.<String>emptySet(), Collections.<String, AttrMod>emptyMap());
    String connObjectKey = preparedAttr.getKey();

    final Name groupOwnerName = evaluateNAME(any, provision, connObjectKey);
    return groupOwnerName.getNameValue();
}

From source file:org.apache.syncope.core.misc.utils.MappingUtils.java

/**
 * Prepare attributes for sending to a connector instance.
 *
 * @param any given any object/*from  w  ww  .  j a va 2s  .c o  m*/
 * @param password clear-text password
 * @param changePwd whether password should be included for propagation attributes or not
 * @param enable whether any object must be enabled or not
 * @param provision provision information
 * @return connObjectLink + prepared attributes
 */
@Transactional(readOnly = true)
public Pair<String, Set<Attribute>> prepareAttrs(final Any<?> any, final String password,
        final boolean changePwd, final Boolean enable, final Provision provision) {

    LOG.debug("Preparing resource attributes for {} with provision {} for attributes {}", any, provision,
            any.getPlainAttrs());

    Set<Attribute> attributes = new HashSet<>();
    String connObjectKey = null;

    for (MappingItem mappingItem : getMappingItems(provision, MappingPurpose.PROPAGATION)) {
        LOG.debug("Processing schema {}", mappingItem.getIntAttrName());

        try {
            Pair<String, Attribute> preparedAttr = prepareAttr(provision, mappingItem, any, password);

            if (preparedAttr != null && preparedAttr.getKey() != null) {
                connObjectKey = preparedAttr.getKey();
            }

            if (preparedAttr != null && preparedAttr.getValue() != null) {
                Attribute alreadyAdded = AttributeUtil.find(preparedAttr.getValue().getName(), attributes);

                if (alreadyAdded == null) {
                    attributes.add(preparedAttr.getValue());
                } else {
                    attributes.remove(alreadyAdded);

                    Set<Object> values = new HashSet<>(alreadyAdded.getValue());
                    values.addAll(preparedAttr.getValue().getValue());

                    attributes.add(AttributeBuilder.build(preparedAttr.getValue().getName(), values));
                }
            }
        } catch (Exception e) {
            LOG.debug("Attribute '{}' processing failed", mappingItem.getIntAttrName(), e);
        }
    }

    Attribute connObjectKeyExtAttr = AttributeUtil.find(getConnObjectKeyItem(provision).getExtAttrName(),
            attributes);
    if (connObjectKeyExtAttr != null) {
        attributes.remove(connObjectKeyExtAttr);
        attributes.add(AttributeBuilder.build(getConnObjectKeyItem(provision).getExtAttrName(), connObjectKey));
    }
    attributes.add(evaluateNAME(any, provision, connObjectKey));

    if (enable != null) {
        attributes.add(AttributeBuilder.buildEnabled(enable));
    }
    if (!changePwd) {
        Attribute pwdAttr = AttributeUtil.find(OperationalAttributes.PASSWORD_NAME, attributes);
        if (pwdAttr != null) {
            attributes.remove(pwdAttr);
        }
    }

    return new ImmutablePair<>(connObjectKey, attributes);
}