Hi all,
Basically, my requirement is to authenticate the users who're visiting my site through LDAP. And if the authentication is successfull i need to map the users to the teamsite USerProfile object, so that i can execute rules based on the userprofile in my components.
I've created a login controller based on the LdapLoginController.class available with the livesite-runtime.jar.
After the LDAP authentication was successfull, i'm trying to map the attributes of the LDAP user with the attributes of the inbuilt UserProfile object. See the code segment for mapping
protectedstatic UserProfile populateUserProfile(UserProfile profile, Attributes attrs)
{
try
{
profile.setLastName((String)attrs.get("sn").get());
profile.setId((String)attrs.get("uid").get());
profile.setEmail((String)attrs.get("mail").get());
profile.setFirstName((String)attrs.get("givenName").get());
profile.setUserName((String)attrs.get("cn").get());
}
catch (NamingException e)
{
thrownew RuntimeException(e);
}return profile;
}
I was able to set the attributes successfully as shown above.
But when i try to set this profile object to the session object i'm getting the following error,
17:20:38,071 WARN [JDBCExceptionReporter] SQL Error: 2627, SQLState: 23000
17:20:38,071 ERROR [JDBCExceptionReporter] Violation of UNIQUE KEY constraint 'UQ__iwpers_u__7C9273C4693CA210'. Cannot insert duplicate key in object 'dbo.iwpers_user'.
17:20:38,071 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: could not insert: [com.interwoven.livesite.p13n.model.UserProfile]
This is how i'm setting the profile object to session
if (null != profile)
{
BaseUserSession session = (BaseUserSession)context.getSession();
session.setUserProfile(profile);
session.setLoggedIn(true);
session.setAuthFailed(false);
session.setAuthFailedCount(0);
profile.setTransient(false);
profile.setLastLoginDate(new Date());
svc.save(profile);
return true;
}
Does anybody find anything wrong in my code ?
Have i missed anything above ?
Or has anyone have done this approach before ? If yes can you share how you achieved it.
Thanks,
Murugan
TS 7.1, LSCS 7.1