* @return the new UserVO or null if the user is no ldap user, or has no LdapGroup
* @throws NamingException error on ladp connection
*/
public UserVO createUserFromLdap(String username) throws NamingException
{
UserVO user = new UserDAO().getByUserName(username);
if(!LdapAuthenticator.getInstance().isLdapUser(username))
{
if(log.isDebugEnabled())
log.debug("no ldap user for username: " + username);
return null;
}
else if(user == null)
{
LdapGroupVO profile = getProfileForUser(username);
if(profile != null)
{
if(log.isDebugEnabled())
log.debug("creating new user: " + username);
InitialDirContext ctx = new InitialDirContext(env);
Attributes attrs = ctx.getAttributes("uid=" + username + "," + SystemConfiguration.getInstance().getStringValue(SystemConfiguration.Key.LDAP_USER_PREFIX));
// Defaultwerte setzen
user = new UserVO();
user.setUserName(attrs.get("Uid").get().toString());
user.setProfile(profile.getProfile());
user.setLocale(adminUser.getLocale());
user.setOwnerUser(adminUser.getId());
user.setOwnerGroup(adminUser.getId());
user.setAccessUser(Access.WRITE_SYSTEM);
user.setAccessGroup(Access.READ);
user.setAccessGlobal(Access.READ);
user.setPassword(SignatureUtility.getInstance().createSignature(new PasswordGenerator().generate()));
new UserDAO().insert(user,adminUser);
CalendarVO calendar = new CalendarVO();
calendar.setUser(user);
calendar.setAccessUser(EntityAccess.Access.WRITE_SYSTEM);
calendar.setOwnerUser(user.getId());
calendar.setAccessGroup(EntityAccess.Access.NONE);
calendar.setOwnerGroup(user.getProfile().getDefaultUsergroup().getId());
calendar.setAccessGlobal(EntityAccess.Access.NONE);
new CalendarDAO().insert(calendar, user);
}
else
{
if(log.isDebugEnabled())
log.debug("user has no Ldap group: " + username);
}
}
else if((user.getProfile().getRole().isAdmin() || (user.getProfile().getLdapGroup() == null))&& LdapAuthenticator.getInstance().isLdapUser(username))
{
log.error("username conflict: " + username);
}
else
{