List of usage examples for org.apache.commons.lang3 SerializationUtils clone
public static <T extends Serializable> T clone(final T object)
Deep clone an Object using serialization.
This is many times slower than writing clone methods by hand on all objects in your object graph.
From source file:org.apache.syncope.common.lib.AnyOperations.java
public static UserTO patch(final UserTO userTO, final UserPatch userPatch) { UserTO result = SerializationUtils.clone(userTO); patch(userTO, userPatch, result);/*from w ww.j av a2 s. c o m*/ // 1. password if (userPatch.getPassword() != null) { result.setPassword(userPatch.getPassword().getValue()); } // 2. username if (userPatch.getUsername() != null) { result.setUsername(userPatch.getUsername().getValue()); } // 3. relationships userPatch.getRelationships().forEach(relPatch -> { if (relPatch.getRelationshipTO() == null) { LOG.warn("Invalid {} specified: {}", RelationshipPatch.class.getName(), relPatch); } else { result.getRelationships().remove(relPatch.getRelationshipTO()); if (relPatch.getOperation() == PatchOperation.ADD_REPLACE) { result.getRelationships().add(relPatch.getRelationshipTO()); } } }); // 4. memberships userPatch.getMemberships().forEach(membPatch -> { if (membPatch.getGroup() == null) { LOG.warn("Invalid {} specified: {}", MembershipPatch.class.getName(), membPatch); } else { Optional<MembershipTO> memb = result.getMemberships().stream() .filter(membership -> membPatch.getGroup().equals(membership.getGroupKey())).findFirst(); if (memb.isPresent()) { result.getMemberships().remove(memb.get()); } if (membPatch.getOperation() == PatchOperation.ADD_REPLACE) { MembershipTO newMembershipTO = new MembershipTO.Builder().group(membPatch.getGroup()).build(); // 3. plain attributes newMembershipTO.getPlainAttrs().addAll(membPatch.getPlainAttrs()); // 4. virtual attributes newMembershipTO.getVirAttrs().addAll(membPatch.getVirAttrs()); result.getMemberships().add(newMembershipTO); } } }); // 5. roles for (StringPatchItem rolePatch : userPatch.getRoles()) { switch (rolePatch.getOperation()) { case ADD_REPLACE: result.getRoles().add(rolePatch.getValue()); break; case DELETE: default: result.getRoles().remove(rolePatch.getValue()); } } return result; }
From source file:org.apache.syncope.common.lib.AttributableOperations.java
public static UserTO apply(final UserTO userTO, final UserMod userMod) { // 1. check same id if (userTO.getKey() != userMod.getKey()) { throw new IllegalArgumentException("UserTO and UserMod ids must be the same"); }/* www .j a v a 2 s. c o m*/ UserTO result = SerializationUtils.clone(userTO); apply(userTO, userMod, result); // 1. password result.setPassword(userMod.getPassword()); // 2. username if (userMod.getUsername() != null) { result.setUsername(userMod.getUsername()); } // 3. memberships Map<Long, MembershipTO> membs = result.getMembershipMap(); for (Long membId : userMod.getMembershipsToRemove()) { result.getMemberships().remove(membs.get(membId)); } for (MembershipMod membMod : userMod.getMembershipsToAdd()) { MembershipTO membTO = new MembershipTO(); membTO.setRoleId(membMod.getRole()); apply(membTO, membMod, membTO); } return result; }
From source file:org.apache.syncope.common.util.AttributableOperations.java
public static UserTO apply(final UserTO userTO, final UserMod userMod) { // 1. check same id if (userTO.getId() != userMod.getId()) { throw new IllegalArgumentException("UserTO and UserMod ids must be the same"); }//from w w w .j ava2s . co m UserTO result = SerializationUtils.clone(userTO); apply(userTO, userMod, result); // 1. password result.setPassword(userMod.getPassword()); // 2. username if (userMod.getUsername() != null) { result.setUsername(userMod.getUsername()); } // 3. memberships Map<Long, MembershipTO> membs = result.getMembershipMap(); for (Long membId : userMod.getMembershipsToRemove()) { result.getMemberships().remove(membs.get(membId)); } for (MembershipMod membMod : userMod.getMembershipsToAdd()) { MembershipTO membTO = new MembershipTO(); membTO.setRoleId(membMod.getRole()); apply(membTO, membMod, membTO); } return result; }
From source file:org.apache.syncope.console.pages.EditUserModalPage.java
public EditUserModalPage(final PageReference pageRef, final ModalWindow window, final UserTO userTO) { super(pageRef, window, userTO, Mode.ADMIN, true); this.initialUserTO = SerializationUtils.clone(userTO); form = setupEditPanel();// w ww . j av a 2s . c o m // add resource assignment details in case of update if (userTO.getId() != 0) { form.addOrReplace(new Label("pwdChangeInfo", new ResourceModel("pwdChangeInfo"))); statusPanel = new StatusPanel("statuspanel", userTO, new ArrayList<StatusBean>(), getPageReference()); statusPanel.setOutputMarkupId(true); MetaDataRoleAuthorizationStrategy.authorize(statusPanel, RENDER, xmlRolesReader.getAllAllowedRoles("Resources", "getConnectorObject")); form.addOrReplace(statusPanel); form.addOrReplace(new AccountInformationPanel("accountinformation", userTO)); form.addOrReplace(new ResourcesPanel.Builder("resources").attributableTO(userTO) .statusPanel(statusPanel).build()); form.addOrReplace(new MembershipsPanel("memberships", userTO, false, statusPanel, getPageReference())); } }
From source file:org.apache.syncope.console.pages.RoleModalPage.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public RoleModalPage(final PageReference pageRef, final ModalWindow window, final RoleTO roleTO, final Mode mode) { super();/*from w w w . j a v a2s .c om*/ this.pageRef = pageRef; this.window = window; this.mode = mode; this.createFlag = roleTO.getId() == 0; if (!createFlag) { originalRoleTO = SerializationUtils.clone(roleTO); } final Form<RoleTO> form = new Form<RoleTO>("RoleForm"); form.setMultiPart(true); add(new Label("displayName", roleTO.getId() == 0 ? "" : roleTO.getDisplayName())); form.setModel(new CompoundPropertyModel<RoleTO>(roleTO)); this.rolePanel = new RolePanel.Builder("rolePanel").form(form).roleTO(roleTO).roleModalPageMode(mode) .pageRef(getPageReference()).build(); form.add(rolePanel); final AjaxButton submit = new IndicatingAjaxButton(SUBMIT, new ResourceModel(SUBMIT)) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { try { submitAction(target, form); if (pageRef.getPage() instanceof BasePage) { ((BasePage) pageRef.getPage()).setModalResult(true); } closeAction(target, form); } catch (Exception e) { error(getString(Constants.ERROR) + ": " + e.getMessage()); feedbackPanel.refresh(target); } } @Override protected void onError(final AjaxRequestTarget target, final Form<?> form) { feedbackPanel.refresh(target); } }; final AjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { closeAction(target, form); } }; cancel.setDefaultFormProcessing(false); MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE, xmlRolesReader.getAllAllowedRoles("Roles", createFlag ? "create" : "update")); form.add(submit); form.setDefaultButton(submit); form.add(cancel); add(form); }
From source file:org.apache.syncope.console.pages.UserSelfModalPage.java
public UserSelfModalPage(final PageReference callerPageRef, final ModalWindow window, final UserTO userTO) { super(callerPageRef, window, userTO, Mode.SELF, userTO.getId() != 0); this.initialUserTO = SerializationUtils.clone(userTO); setupEditPanel();/* ww w.j av a2 s.co m*/ }
From source file:org.apache.syncope.console.wicket.markup.html.form.FieldPanel.java
@Override @SuppressWarnings("unchecked") public FieldPanel<T> clone() { final FieldPanel<T> panel = SerializationUtils.clone(this); panel.setModelObject(null);/*from w ww.j a v a 2 s. c o m*/ return panel; }
From source file:org.apache.syncope.core.init.ConnectorManager.java
@Override public Connector createConnector(final ConnInstance connInstance, final Set<ConnConfProperty> configuration) { final ConnInstance connInstanceClone = (ConnInstance) SerializationUtils.clone(connInstance); connInstanceClone.setConfiguration(configuration); Connector connector = new ConnectorFacadeProxy(connInstanceClone); ApplicationContextProvider.getBeanFactory().autowireBean(connector); return connector; }
From source file:org.apache.syncope.core.logic.saml2.SAML2UserManager.java
@Transactional(propagation = Propagation.REQUIRES_NEW) public String update(final String username, final SAML2IdPEntity idp, final SAML2LoginResponseTO responseTO) { UserTO userTO = binder.getUserTO(userDAO.findKey(username)); UserTO original = SerializationUtils.clone(userTO); fill(idp.getKey(), responseTO, userTO); UserPatch userPatch = AnyOperations.diff(userTO, original, true); List<SAML2IdPActions> actions = getActions(idp); for (SAML2IdPActions action : actions) { userPatch = action.beforeUpdate(userPatch, responseTO); }/*from www.j av a 2 s.c o m*/ Pair<UserPatch, List<PropagationStatus>> updated = provisioningManager.update(userPatch, false); userTO = binder.getUserTO(updated.getLeft().getKey()); for (SAML2IdPActions action : actions) { userTO = action.afterUpdate(userTO, responseTO); } return userTO.getUsername(); }
From source file:org.apache.syncope.core.misc.utils.MappingUtils.java
/** * Get attribute values for the given {@link MappingItem} and any objects. * * @param provision provision information * @param mappingItem mapping item//from w w w .j av a 2s .co m * @param anys any objects * @return attribute values. */ @Transactional(readOnly = true) public List<PlainAttrValue> getIntValues(final Provision provision, final MappingItem mappingItem, final List<Any<?>> anys) { LOG.debug("Get attributes for '{}' and mapping type '{}'", anys, mappingItem.getIntMappingType()); boolean transform = true; List<PlainAttrValue> values = new ArrayList<>(); switch (mappingItem.getIntMappingType()) { case UserPlainSchema: case GroupPlainSchema: case AnyObjectPlainSchema: for (Any<?> any : anys) { PlainAttr<?> attr = any.getPlainAttr(mappingItem.getIntAttrName()); if (attr != null) { if (attr.getUniqueValue() != null) { PlainAttrUniqueValue value = SerializationUtils.clone(attr.getUniqueValue()); value.setAttr(null); values.add(value); } else if (attr.getValues() != null) { for (PlainAttrValue value : attr.getValues()) { PlainAttrValue shadow = SerializationUtils.clone(value); shadow.setAttr(null); values.add(shadow); } } } LOG.debug( "Retrieved attribute {}" + "\n* IntAttrName {}" + "\n* IntMappingType {}" + "\n* Attribute values {}", attr, mappingItem.getIntAttrName(), mappingItem.getIntMappingType(), values); } break; case UserDerivedSchema: case GroupDerivedSchema: case AnyObjectDerivedSchema: DerSchema derSchema = derSchemaDAO.find(mappingItem.getIntAttrName()); if (derSchema != null) { for (Any<?> any : anys) { String value = derAttrHandler.getValue(any, derSchema); if (value != null) { AnyUtils anyUtils = anyUtilsFactory.getInstance(any); PlainAttrValue attrValue = anyUtils.newPlainAttrValue(); attrValue.setStringValue(value); values.add(attrValue); LOG.debug( "Retrieved values for {}" + "\n* IntAttrName {}" + "\n* IntMappingType {}" + "\n* Attribute values {}", derSchema.getKey(), mappingItem.getIntAttrName(), mappingItem.getIntMappingType(), values); } } } break; case UserVirtualSchema: case GroupVirtualSchema: case AnyObjectVirtualSchema: // virtual attributes don't get transformed transform = false; VirSchema virSchema = virSchemaDAO.find(mappingItem.getIntAttrName()); if (virSchema != null) { for (Any<?> any : anys) { LOG.debug("Expire entry cache {}-{}", any.getKey(), mappingItem.getIntAttrName()); virAttrCache.expire(any.getType().getKey(), any.getKey(), mappingItem.getIntAttrName()); AnyUtils anyUtils = anyUtilsFactory.getInstance(any); for (String value : virAttrHandler.getValues(any, virSchema)) { PlainAttrValue attrValue = anyUtils.newPlainAttrValue(); attrValue.setStringValue(value); values.add(attrValue); } LOG.debug( "Retrieved values for {}" + "\n* IntAttrName {}" + "\n* IntMappingType {}" + "\n* Attribute values {}", virSchema.getKey(), mappingItem.getIntAttrName(), mappingItem.getIntMappingType(), values); } } break; case UserKey: case GroupKey: case AnyObjectKey: for (Any<?> any : anys) { AnyUtils anyUtils = anyUtilsFactory.getInstance(any); PlainAttrValue attrValue = anyUtils.newPlainAttrValue(); attrValue.setStringValue(any.getKey().toString()); values.add(attrValue); } break; case Username: for (Any<?> any : anys) { if (any instanceof User) { UPlainAttrValue attrValue = entityFactory.newEntity(UPlainAttrValue.class); attrValue.setStringValue(((User) any).getUsername()); values.add(attrValue); } } break; case GroupName: for (Any<?> any : anys) { if (any instanceof Group) { GPlainAttrValue attrValue = entityFactory.newEntity(GPlainAttrValue.class); attrValue.setStringValue(((Group) any).getName()); values.add(attrValue); } } break; case GroupOwnerSchema: Mapping uMapping = provision.getAnyType().equals(anyTypeDAO.findUser()) ? null : provision.getMapping(); Mapping gMapping = provision.getAnyType().equals(anyTypeDAO.findGroup()) ? null : provision.getMapping(); for (Any<?> any : anys) { if (any instanceof Group) { Group group = (Group) any; String groupOwnerValue = null; if (group.getUserOwner() != null && uMapping != null) { groupOwnerValue = getGroupOwnerValue(provision, group.getUserOwner()); } if (group.getGroupOwner() != null && gMapping != null) { groupOwnerValue = getGroupOwnerValue(provision, group.getGroupOwner()); } if (StringUtils.isNotBlank(groupOwnerValue)) { GPlainAttrValue attrValue = entityFactory.newEntity(GPlainAttrValue.class); attrValue.setStringValue(groupOwnerValue); values.add(attrValue); } } } break; default: } LOG.debug("Values for propagation: {}", values); List<PlainAttrValue> transformed = values; if (transform) { for (MappingItemTransformer transformer : getMappingItemTransformers(mappingItem)) { transformed = transformer.beforePropagation(transformed); } LOG.debug("Transformed values for propagation: {}", values); } else { LOG.debug("No transformation occurred"); } return transformed; }