You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@syncope.apache.org by Ravindra Singareddy <si...@hotmail.com> on 2017/05/05 22:23:50 UTC
Storing Custom User variables and Unique Email constraint
Hi All,
I need to store User Custom variables like firstName, MiddleName, and Last Name and using following code:
SyncopeClientFactoryBean clientFactory = new SyncopeClientFactoryBean().
setAddress("http://localhost:8080/syncope/rest").
setDomain("Master").
setContentType(SyncopeClientFactoryBean.ContentType.XML).
setUseCompression(true);
SyncopeClient client = clientFactory.create("admin", "password");
UserService userService = client.getService(UserService.class);
UserTO userTo = new UserTO();
userTo.setUsername(username);
userTo.setPassword(password);
userTo.setCreationDate(new Date());
userTo.setCreator("admin");
userTo.setRealm("/");
userTo.getPlainAttrs().add(new AttrTO.Builder().schema("email").value(email).build());
userTo.getPlainAttrs().add(new AttrTO.Builder().schema("firstName").value(firstName).build());
userTo.getPlainAttrs().add(new AttrTO.Builder().schema("middleName").value(middleName).build());
userTo.getPlainAttrs().add(new AttrTO.Builder().schema("lastName").value(lastName).build());
Response userResponse = userService.create(userTo,true);
System.out.println(userResponse.getStatus());
After Successful creation of user, authenticated using email, with following code:
client = clientFactory.
setDomain("Master").create(email, password);
Pair<Map<String, Set<String>>, UserTO> self = client.self();
Object auth = self.getKey();
UserTO selfUserTO = (UserTO)self.getValue();
System.out.println(selfUserTO);
First Question: selfUserTO is not retrieving firstName, middleName, and LastName from Plain Attributes. What are changes needed to be done for storing these plain attributes values?
Second Question: I am able to save email address and also able to retrieve (authenticate) using the email address. If I have created two users with the same email address, the system is not able to log in using this email address. Because the email address is not unique across all users. How to make email address unique across all users.
plainAttrs=[org.apache.syncope.common.lib.to.AttrTO@6f8f9349[
schemaInfo=org.apache.syncope.common.lib.to.PlainSchemaTO@75c9e76b[
type=String
mandatoryCondition=false
multivalue=false
uniqueConstraint=false
readonly=false
conversionPattern=<null>
validatorClass=org.apache.syncope.core.persistence.jpa.attrvalue.validation.EmailAddressValidator
enumerationValues=<null>
enumerationKeys=<null>
secretKey=<null>
cipherAlgorithm=<null>
mimeType=<null>
key=email
anyTypeClass=BaseUser
]
schema=email
values=[abcdef@hotmail.com]
]]
Your help in this regard greatly appreciated.
Thanks
Ravi
<http://www.ooftish.com>
Re: Storing Custom User variables and Unique Email constraint
Posted by Francesco Chicchiriccò <il...@apache.org>.
On 06/05/2017 00:23, Ravindra Singareddy wrote:
>
> Hi All,
>
> I need to store User Custom variables like firstName, MiddleName, and
> Last Name and using following code:
>
>
> SyncopeClientFactoryBean clientFactory = new SyncopeClientFactoryBean().
> setAddress("http://localhost:8080/syncope/rest").
> setDomain("Master").
> setContentType(SyncopeClientFactoryBean.ContentType.XML).
> setUseCompression(true);
> SyncopeClient client = clientFactory.create("admin", "password");
> UserService userService = client.getService(UserService.class);
>
> UserTO userTo = new UserTO();
> userTo.setUsername(username);
> userTo.setPassword(password);
> userTo.setCreationDate(new Date());
> userTo.setCreator("admin");
> userTo.setRealm("/");
> userTo.getPlainAttrs().add(new
> AttrTO.Builder().schema("email").value(email).build());
> userTo.getPlainAttrs().add(new
> AttrTO.Builder().schema("firstName").value(firstName).build());
> userTo.getPlainAttrs().add(new
> AttrTO.Builder().schema("middleName").value(middleName).build());
> userTo.getPlainAttrs().add(new
> AttrTO.Builder().schema("lastName").value(lastName).build());
> Response userResponse = userService.create(userTo,true);
> System.out.println(userResponse.getStatus());
>
> After Successful creation of user, authenticated using email, with
> following code:
>
> client = clientFactory.
> setDomain("Master").create(email, password);
> Pair<Map<String, Set<String>>, UserTO> self = client.self();
> Object auth = self.getKey();
> UserTO selfUserTO = (UserTO)self.getValue();
> System.out.println(selfUserTO);
>
> First Question: selfUserTO is not retrieving firstName, middleName,
> and LastName from Plain Attributes. What are changes needed to be
> done for storing these plain attributes values?
You need to create the related schemas (if you haven't done that yet)
and then to assign such schemas to the AnyTypeClass for users.
More information:
https://cwiki.apache.org/confluence/display/SYNCOPE/Apache+Syncope+2.0+Primer
https://syncope.apache.org/docs/reference-guide.html#type-management
> Second Question: I am able to save email address and also able to
> retrieve (authenticate) using the email address. If I have created two
> users with the same email address, the system is not able to log in
> using this email address. Because the email address is not unique
> across all users. How to make email address unique across all users.
You need to change the email schema definition and flag uniqueConstraint
to true; you can do that either via Admin Console or REST.
Please be aware that, if there are users with the 'email' attribute set,
such update is not possible: you'll need either to create another schema
or to remove all the existing email values.
HTH
Regards.
--
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/