Re: Resource specific counters in Syncope

2020-10-09 Thread Francesco Chicchiriccò
On 07/10/20 14:45, Martin van Es wrote:
> Hi Francesco,
>
> Thx for the quick reply!
>
> On Wed, Oct 7, 2020 at 11:18 AM Francesco Chicchiriccò  > wrote:
>
> Hi Martin,
> so you'd want to keep different counters for different External 
> Resources, and inject appropriate values from such counters during 
> propagation, to populate attributes like as uidNumber and gidNumber, for 
> example.
>
>
> Yes
>
> I think it can be as straightforward as (1) defining appropriate 
> configuration parameters to hold counter values and (2) creating 
> PropagationActions classes to implement the value injection and counter 
> increment logic.
>
>
> Which implies development effort (albeit a little)? Would there be a 
> "lightweight" possibility via scripts?

Yes, you can implement PropagationActions [1] in Groovy.

> Would the configuration parameters be like External Resource specific 
> variables that can be manipulated at will?

My suggestion was to add an manipulate some additional Configuration Parameters 
[2], beyond the predefined set.

Regards.

[1] http://syncope.apache.org/docs/2.1/reference-guide.html#propagationactions
[2] 
http://syncope.apache.org/docs/2.1/reference-guide.html#configuration-parameters

-- 
Francesco Chicchiriccò

Tirasa - Open Source Excellence
http://www.tirasa.net/

Member at The Apache Software Foundation
Syncope, Cocoon, Olingo, CXF, OpenJPA, PonyMail
http://home.apache.org/~ilgrosso/



Re: Flowable set user plain attribute

2020-10-09 Thread thinkingmik
Hi, I have found the way to set plain attributes on user by adding a /service
task/ (with delegate expression ${update}) after my /script task/.

So, my script changed to:

/*** BEGIN SCRIPT ***/
import org.apache.syncope.common.lib.patch.AttrPatch;
import org.apache.syncope.common.lib.types.PatchOperation;
import org.apache.syncope.common.lib.to.AttrTO;
import org.apache.syncope.common.lib.types.CipherAlgorithm;
import org.apache.syncope.common.lib.to.UserTO;
import org.apache.syncope.core.persistence.api.entity.user.User;
import org.apache.syncope.core.flowable.impl.FlowableRuntimeUtils;
import org.apache.syncope.common.lib.patch.UserPatch;
import org.apache.syncope.common.lib.patch.PasswordPatch;
import org.apache.syncope.common.lib.patch.BooleanReplacePatchItem;
import org.apache.syncope.common.lib.patch.PasswordPatch;

User user = execution.getVariable(FlowableRuntimeUtils.USER, User.class);

def password = generatePassword(12);

UserPatch userPatch = new UserPatch();
userPatch.setKey(user.getKey());

BooleanReplacePatchItem boolPatch = new BooleanReplacePatchItem();
boolPatch.setValue(true);
userPatch.setMustChangePassword(boolPatch);

PasswordPatch passwordPatch = new PasswordPatch();
passwordPatch.setValue(password);
passwordPatch.setOnSyncope(true);
userPatch.setPassword(passwordPatch);

userPatch.getPlainAttrs().add(createUpdatePatch("tempPassword", password));

execution.setVariable(FlowableRuntimeUtils.USER_PATCH, userPatch);

def String generatePassword(int n) {
String alphabet =
(('A'..'N')+('P'..'Z')+('a'..'k')+('m'..'z')+('2'..'9')).join();
return new Random().with { (1..n).collect { alphabet[ nextInt(
alphabet.length() ) ] }.join(); }
}

def AttrPatch createUpdatePatch(String key, String value) {
return new
AttrPatch.Builder().operation(PatchOperation.ADD_REPLACE).attrTO(createAttrTO(key,
value)).build();
}

def AttrTO createAttrTO(String key, String value) {
return new AttrTO.Builder().schema(key).value(value).build();
}
/*** END SCRIPT ***/

 

Thank you anyway

-
Michele
--
Sent from: http://syncope-user.1051894.n5.nabble.com/