You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@syncope.apache.org by Bob Lannoy <bo...@gmail.com> on 2012/06/28 16:18:15 UTC
Deleting user
Hi guys,
in my activation workflow I want to delete users that present an expired token.
As I remember, I cannot delete a user in a workflow step.
Following Francesco's suggestion, I have a "sink" in my workflow where
I put those users.
I wanted to rename them & change the email-address (both unique in my
schema) so they are free for other (or maybe the same) users.
So what I did in my workflow step:
------------
SyncopeUser user = (SyncopeUser)
execution.getVariable(ActivitiUserWorkflowAdapter.SYNCOPE_USER);
UserMod userMod=new UserMod();
userMod.setUsername("delete_"+user.getUsername());
AttributeMod attMod=new AttributeMod();
attMod.setSchema("email");
String email=user.getAttribute("email").getUniqueValue().getValueAsString();
attMod.addValueToBeRemoved(email);
attMod.addValueToBeAdded("deleted_"+email);
userMod.addAttributeToBeUpdated(attMod);
PropagationByResource propByRes = dataBinder.update(user, userMod);
execution.setVariable(ActivitiUserWorkflowAdapter.SYNCOPE_USER, user);
execution.setVariable(ActivitiUserWorkflowAdapter.PROP_BY_RESOURCE,
propByRes);
-----------
The user ends up in the "toberemoved" state in the workflow, which I
see in console.
However when I press "delete" in the console I get strange errors
Cannot delete or update a parent row: a foreign key constraint fails
(`syncope`.`uattruniquevalue`, CONSTRAINT `uattruniquevalue_ibfk_1`
FOREIGN KEY (`ATTRIBUTE_ID`) REFERENCES `UAttr` (`id`)) {prepstmnt
667215072 DELETE FROM UAttr WHERE id = ? [params=?]} [code=1451,
state=23000]
I noticed that the UAttrUniqueValue table holds the old emailaddress
and new emailaddress, both attached to the same attribute which of
course poses a uniqueness problem. When I delete the row with the old
address, I can delete the user through console.
Any ideas on what I did wrong? or is there another way to delete a
user from inside the workflow?
best regards
Bob
Re: Deleting user
Posted by Francesco Chicchiriccò <il...@apache.org>.
On 28/06/2012 16:44, Bob Lannoy wrote:
>
> Ok, looks like a stupid mistake :)
> I'll give it a go.
>
> Can you give me pointers on how I could use a scheduled task to remove
> users in the "toberemoved" state?
>
I guess you've already given a look at [1]; basically, you need to add
the class extending AbstractJob to your overlay and implement the actual
business logic (i.e. remove users) in doExecute() method.
About your business logic, you will need to
1. search from all users in the "toberemoved" state
2. delete such users
Depending on your needs, it would be wiser to use "low-level" objects
like as UserDAO or instead interact via REST calls.
Once done, you will be able to schedule the execution of this task from
the admin console.
Hope this helps.
Regards.
[1]
https://cwiki.apache.org/confluence/display/SYNCOPE/ScheduledTaskJobClass
--
Francesco Chicchiriccò
ASF Member, Apache Cocoon PMC and Apache Syncope PPMC Member
http://people.apache.org/~ilgrosso/
Re: Deleting user
Posted by Bob Lannoy <bo...@gmail.com>.
Ok, looks like a stupid mistake :)
I'll give it a go.
Can you give me pointers on how I could use a scheduled task to remove
users in the "toberemoved" state?
Best regards
Bob
On Jun 28, 2012 4:34 PM, "Francesco Chicchiriccò" <il...@apache.org>
wrote:
> On 28/06/2012 16:18, Bob Lannoy wrote:
> > Hi guys,
> >
> > in my activation workflow I want to delete users that present an expired
> token.
> > As I remember, I cannot delete a user in a workflow step.
> > Following Francesco's suggestion, I have a "sink" in my workflow where
> > I put those users.
> > I wanted to rename them & change the email-address (both unique in my
> > schema) so they are free for other (or maybe the same) users.
> >
> > So what I did in my workflow step:
> > ------------
> > SyncopeUser user = (SyncopeUser)
> > execution.getVariable(ActivitiUserWorkflowAdapter.SYNCOPE_USER);
> > UserMod userMod=new UserMod();
> >
> > userMod.setUsername("delete_"+user.getUsername());
> > AttributeMod attMod=new AttributeMod();
> > attMod.setSchema("email");
> > String
> email=user.getAttribute("email").getUniqueValue().getValueAsString();
> >
> > attMod.addValueToBeRemoved(email);
> > attMod.addValueToBeAdded("deleted_"+email);
> >
> > userMod.addAttributeToBeUpdated(attMod);
> >
> > PropagationByResource propByRes = dataBinder.update(user, userMod);
> >
> > execution.setVariable(ActivitiUserWorkflowAdapter.SYNCOPE_USER,
> user);
> > execution.setVariable(ActivitiUserWorkflowAdapter.PROP_BY_RESOURCE,
> > propByRes);
> > -----------
> > The user ends up in the "toberemoved" state in the workflow, which I
> > see in console.
> > However when I press "delete" in the console I get strange errors
> > Cannot delete or update a parent row: a foreign key constraint fails
> > (`syncope`.`uattruniquevalue`, CONSTRAINT `uattruniquevalue_ibfk_1`
> > FOREIGN KEY (`ATTRIBUTE_ID`) REFERENCES `UAttr` (`id`)) {prepstmnt
> > 667215072 DELETE FROM UAttr WHERE id = ? [params=?]} [code=1451,
> > state=23000]
> >
> > I noticed that the UAttrUniqueValue table holds the old emailaddress
> > and new emailaddress, both attached to the same attribute which of
> > course poses a uniqueness problem. When I delete the row with the old
> > address, I can delete the user through console.
> >
> > Any ideas on what I did wrong? or is there another way to delete a
> > user from inside the workflow?
>
> I think that the problem is due to the code performing user update: you
> are doing
>
> attMod.addValueToBeRemoved(email);
> attMod.addValueToBeAdded("deleted_"+email);
>
> but it should be, instead
>
> userMod.addAttributeToBeRemoved("email");
> attMod.addValueToBeAdded("deleted_"+email);
>
> Let me know if this works.
> Regards.
>
> --
> Francesco Chicchiriccò
>
> ASF Member, Apache Cocoon PMC and Apache Syncope PPMC Member
> http://people.apache.org/~ilgrosso/
>
>
Re: Deleting user
Posted by Francesco Chicchiriccò <il...@apache.org>.
On 28/06/2012 16:18, Bob Lannoy wrote:
> Hi guys,
>
> in my activation workflow I want to delete users that present an expired token.
> As I remember, I cannot delete a user in a workflow step.
> Following Francesco's suggestion, I have a "sink" in my workflow where
> I put those users.
> I wanted to rename them & change the email-address (both unique in my
> schema) so they are free for other (or maybe the same) users.
>
> So what I did in my workflow step:
> ------------
> SyncopeUser user = (SyncopeUser)
> execution.getVariable(ActivitiUserWorkflowAdapter.SYNCOPE_USER);
> UserMod userMod=new UserMod();
>
> userMod.setUsername("delete_"+user.getUsername());
> AttributeMod attMod=new AttributeMod();
> attMod.setSchema("email");
> String email=user.getAttribute("email").getUniqueValue().getValueAsString();
>
> attMod.addValueToBeRemoved(email);
> attMod.addValueToBeAdded("deleted_"+email);
>
> userMod.addAttributeToBeUpdated(attMod);
>
> PropagationByResource propByRes = dataBinder.update(user, userMod);
>
> execution.setVariable(ActivitiUserWorkflowAdapter.SYNCOPE_USER, user);
> execution.setVariable(ActivitiUserWorkflowAdapter.PROP_BY_RESOURCE,
> propByRes);
> -----------
> The user ends up in the "toberemoved" state in the workflow, which I
> see in console.
> However when I press "delete" in the console I get strange errors
> Cannot delete or update a parent row: a foreign key constraint fails
> (`syncope`.`uattruniquevalue`, CONSTRAINT `uattruniquevalue_ibfk_1`
> FOREIGN KEY (`ATTRIBUTE_ID`) REFERENCES `UAttr` (`id`)) {prepstmnt
> 667215072 DELETE FROM UAttr WHERE id = ? [params=?]} [code=1451,
> state=23000]
>
> I noticed that the UAttrUniqueValue table holds the old emailaddress
> and new emailaddress, both attached to the same attribute which of
> course poses a uniqueness problem. When I delete the row with the old
> address, I can delete the user through console.
>
> Any ideas on what I did wrong? or is there another way to delete a
> user from inside the workflow?
I think that the problem is due to the code performing user update: you
are doing
attMod.addValueToBeRemoved(email);
attMod.addValueToBeAdded("deleted_"+email);
but it should be, instead
userMod.addAttributeToBeRemoved("email");
attMod.addValueToBeAdded("deleted_"+email);
Let me know if this works.
Regards.
--
Francesco Chicchiriccò
ASF Member, Apache Cocoon PMC and Apache Syncope PPMC Member
http://people.apache.org/~ilgrosso/