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/