Re: How to make sql queries on a authentication groovy script

2018-02-28 Thread Andrea Patricelli

Good morning,


Il 27/02/2018 17:59, HugoCerdeira ha scritto:

Hi,

I'm making an authentication groovy script my goal is the following flow:

1. Script makes a request to a service sending the user and password.
2. If the request response is successful query the syncope db for the user
id, using the username.
3. Return the user id.

The problem is, since the resource is configured as a REST resource, how can
execute sql queries from the script? is it possible to do that without
having to hardcode the sql connection config into my groovy script?
You do not need to query Syncope database to look for id on Syncope. 
Because you only need to return the value of the attribute that, on 
Syncope, is mapped as remote key. I mean: if your mapping for remote key 
looks like "username -> idattribute" (syncope -> REST resource) you only 
need to return the value of idattribute on REST resource. Syncope will 
take care of look (on the REST resource) if id is correct by using the 
mapping.


P.S. if you need to look for an user on Syncope always prefer rest apis 
[1] to db client ;)


Thanks,
Hugo Cerdeira.

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

Best regards,
Andrea

[1] https://syncope.apache.org/docs/reference-guide.html#rest

--
Dott. Andrea Patricelli
Tel. +39 3204524292

Developer @ Tirasa S.r.l.
Viale D'Annunzio 267 - 65127 Pescara
Tel +39 0859116307 / FAX +39 085973
http://www.tirasa.net

Apache Syncope PMC Member



Re: How to make sql queries on a authentication groovy script

2018-02-28 Thread HugoCerdeira
Hi,

Well that helps, but what if I need to get the user email in order to make
the external authentication work?
its seems like I cant access the email, even if I map it on the resource.

Thanks for your help,
Hugo Cerdeira.

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


Re: How to make sql queries on a authentication groovy script

2018-02-28 Thread Andrea Patricelli


Il 28/02/2018 11:31, HugoCerdeira ha scritto:

Hi,

Well that helps, but what if I need to get the user email in order to make
the external authentication work?
its seems like I cant access the email, even if I map it on the resource.
Use email as remote key and add mapping on Syncope: email -> 
external_email. In groovy script you just need to return external_email 
value and add the previous mapping to Syncope.


Thanks for your help,
Hugo Cerdeira.

Best regards,
Andrea


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


--
Dott. Andrea Patricelli
Tel. +39 3204524292

Developer @ Tirasa S.r.l.
Viale D'Annunzio 267 - 65127 Pescara
Tel +39 0859116307 / FAX +39 085973
http://www.tirasa.net

Apache Syncope PMC Member



Re: How to make sql queries on a authentication groovy script

2018-02-28 Thread HugoCerdeira
Hi, 
Thanks for your quick answers,

After mapping the email on the resource, I cant access it on the
groovyscript.

This is my mapping:

 

If I use the external_email on the groovyscript, my script just fails to
execute.
Any idea on whats going on?

Cheers,
Hugo Cerdeira.

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


Re: How to make sql queries on a authentication groovy script

2018-02-28 Thread Andrea Patricelli

Il 28/02/2018 13:08, HugoCerdeira ha scritto:

Hi,
Thanks for your quick answers,

After mapping the email on the resource, I cant access it on the
groovyscript.

This is my mapping:


If I use the external_email on the groovyscript, my script just fails to
execute.
Any idea on whats going on?
Please try to set the mapping as bidirectional: double arrow icon in 
mapping tab.


Cheers,
Hugo Cerdeira.

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

Best regards,
Andrea

--
Dott. Andrea Patricelli
Tel. +39 3204524292

Engineer @ Tirasa S.r.l.
Viale D'Annunzio 267 - 65127 Pescara
Tel +39 0859116307 / FAX +39 085973
http://www.tirasa.net

Apache Syncope PMC Member



Re: How to make sql queries on a authentication groovy script

2018-02-28 Thread HugoCerdeira
Thanks once again for the quick reply,

Setting the mapping as bidirectional, did not work.

Using the command "this.binding.variables.each {k,v -> map[k]=v}"
on my groovy script, to check what it actually has I get the following map:

[password:authPassword,
log:org.identityconnectors.common.logging.Log@2d9ed949,
objectClass:__ACCOUNT__, options:[:],
client:org.apache.cxf.jaxrs.client.WebClient@2adc36e6, action:AUTHENTICATE,
username:authUsername]

Its like the mapping is being ignored.

Cheers,
Hugo Cerdeira.

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


Re: How to make sql queries on a authentication groovy script

2018-02-28 Thread Andrea Patricelli

Ok now I got.

You do not need to read Syncope mapping, or anything by Syncope, but 
options and objectClass.
You only have to return the value of the email attribute read from the 
REST WS response. The name of the external attribute you should already 
know, it is static, because is the one used in the mapping.


Best regards,
Andrea


Il 28/02/2018 13:21, HugoCerdeira ha scritto:

Thanks once again for the quick reply,

Setting the mapping as bidirectional, did not work.

Using the command "this.binding.variables.each {k,v -> map[k]=v}"
on my groovy script, to check what it actually has I get the following map:

[password:authPassword,
log:org.identityconnectors.common.logging.Log@2d9ed949,
objectClass:__ACCOUNT__, options:[:],
client:org.apache.cxf.jaxrs.client.WebClient@2adc36e6, action:AUTHENTICATE,
username:authUsername]

Its like the mapping is being ignored.

Cheers,
Hugo Cerdeira.

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


--
Dott. Andrea Patricelli
Tel. +39 3204524292

Developer @ Tirasa S.r.l.
Viale D'Annunzio 267 - 65127 Pescara
Tel +39 0859116307 / FAX +39 085973
http://www.tirasa.net

Apache Syncope PMC Member



Re: How to make sql queries on a authentication groovy script

2018-02-28 Thread HugoCerdeira
After i few tries, and with all your help i think i got it.

The external key always come to the script via the "username" variable,
since its, probably, the way the connector is written, if i map the email as
external id, i can access the email field of the user from the groovy script
via the "username" variable. If i return the username AKA external key i get
a valid authentication, just like intended. yay!

Thanks for all your help!

Cheers,
Hugo Cerdeira.

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


Re: How to make sql queries on a authentication groovy script

2018-02-28 Thread Andrea Patricelli

Welcome.

BTW sorry, I missed to say that in order to use email to login you also 
have to add email field to configuration parameter named 
authentication.attributes.


HTH,
Andrea


Il 28/02/2018 15:55, HugoCerdeira ha scritto:

After i few tries, and with all your help i think i got it.

The external key always come to the script via the "username" variable,
since its, probably, the way the connector is written, if i map the email as
external id, i can access the email field of the user from the groovy script
via the "username" variable. If i return the username AKA external key i get
a valid authentication, just like intended. yay!

Thanks for all your help!

Cheers,
Hugo Cerdeira.

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


--
Dott. Andrea Patricelli
Tel. +39 3204524292

Developer @ Tirasa S.r.l.
Viale D'Annunzio 267 - 65127 Pescara
Tel +39 0859116307 / FAX +39 085973
http://www.tirasa.net

Apache Syncope PMC Member



Re: How to make sql queries on a authentication groovy script

2018-02-28 Thread HugoCerdeira
Thats not a problem because i authenticate on syncope via username/password i
only need the email for the  webservice that i sue on the groovy script, so
it works as it is! Thanks anyway.

Cheers,
Hugo Cerdeira.

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