.getComponent("org.apache.jetspeed.security.GroupManager");
if (groupManager == null)
throw new SerializerException(
SerializerException.COMPONENTMANAGER_DOES_NOT_EXIST
.create("org.apache.jetspeed.security.GroupManager"));
RoleManager roleManager = (RoleManager) getCM()
.getComponent("org.apache.jetspeed.security.RoleManager");
if (roleManager == null)
throw new SerializerException(
SerializerException.COMPONENTMANAGER_DOES_NOT_EXIST
.create("org.apache.jetspeed.security.RoleManager"));
UserManager userManager = (UserManager) getCM()
.getComponent("org.apache.jetspeed.security.UserManager");
if (userManager == null)
throw new SerializerException(
SerializerException.COMPONENTMANAGER_DOES_NOT_EXIST
.create("org.apache.jetspeed.security.UserManager"));
JSGroups groups = null;
JSRoles roles = null;
groups = ((JSSeedData)getSnapshot()).getGroups();
Iterator _it = groups.iterator();
while (_it.hasNext())
{
String name = ((JSGroup)_it.next()).getName();
try
{
if (!(groupManager.groupExists(name)))
groupManager.addGroup(name);
Group group = groupManager.getGroup(name);
this.groupMap.put(name, group.getPrincipal());
} catch (Exception e)
{
throw new SerializerException(
SerializerException.CREATE_OBJECT_FAILED
.create(new String[]
{ "Group", e.getMessage()}));
}
}
logMe("recreateGroups - done");
logMe("processing roles");
roles = ((JSSeedData)getSnapshot()).getRoles();
_it = roles.iterator();
while (_it.hasNext())
{
String name = ((JSRole)_it.next()).getName();
try
{
if (!(roleManager.roleExists(name)))
roleManager.addRole(name);
Role role = roleManager.getRole(name);
this.roleMap.put(name, role.getPrincipal());
} catch (Exception e)
{
throw new SerializerException(
SerializerException.CREATE_OBJECT_FAILED
.create(new String[]
{ "Role", e.getMessage()}));
}
}
logMe("recreateRoles - done");
logMe("processing users");
/** determine whether passwords can be reconstructed or not */
int passwordEncoding = compareCurrentSecurityProvider((JSSeedData)getSnapshot());
JSUsers users = null;
users = ((JSSeedData)getSnapshot()).getUsers();
_it = users.iterator();
while (_it.hasNext())
{
JSUser jsuser = (JSUser)_it.next();
try
{
User user = null;
if (userManager.userExists(jsuser.getName()))
{
user = userManager.getUser(jsuser.getName());
}
if ((this.getSetting(JetspeedSerializer.KEY_OVERWRITE_EXISTING)) || (user == null))
{
if (user == null) //create new one
{
String password = recreatePassword(jsuser.getPassword());
logMe("add User "+ jsuser.getName() + " with password " + password);
userManager.importUser(jsuser.getName(), password,(passwordEncoding == PASSTHRU_REQUIRED));
logMe("add User done ");
user = userManager.getUser(jsuser.getName());
}
try
{
userManager.setPasswordEnabled(jsuser.getName(), jsuser.getPwEnabled());
userManager.setPasswordUpdateRequired(jsuser.getName(), jsuser.getPwRequiredUpdate());
java.sql.Date d = jsuser.getPwExpirationDate();
if (d != null)
userManager.setPasswordExpiration(jsuser.getName(), d);
}
catch (Exception e)
{
// most likely caused by protected users (like "guest")
logMe("setting userinfo for "+ jsuser.getName() + " failed because of " + e.getLocalizedMessage());
}
//credentials
Subject subject = user.getSubject();
ArrayList listTemp = jsuser.getPrivateCredentials();
if ((listTemp != null) && (listTemp.size()>0))
{
Iterator _itTemp = listTemp.iterator();
while (_itTemp.hasNext())
{
subject.getPrivateCredentials().add(_itTemp.next());
}
}
listTemp = jsuser.getPublicCredentials();
if ((listTemp != null) && (listTemp.size()>0))
{
Iterator _itTemp = listTemp.iterator();
while (_itTemp.hasNext())
{
subject.getPublicCredentials().add(_itTemp.next());
}
}
JSUserGroups jsUserGroups = jsuser.getGroupString();
if (jsUserGroups != null)
listTemp = this.getTokens(jsUserGroups.toString());
else
listTemp = null;
if ((listTemp != null) && (listTemp.size()>0))
{
Iterator _itTemp = listTemp.iterator();
while (_itTemp.hasNext())
{
groupManager.addUserToGroup(jsuser.getName(), (String)_itTemp.next());
}
}
JSUserRoles jsUserRoles = jsuser.getRoleString();
if (jsUserRoles != null)
listTemp = this.getTokens(jsUserRoles.toString());
else
listTemp = null;
if ((listTemp != null) && (listTemp.size()>0))
{
Iterator _itTemp = listTemp.iterator();
while (_itTemp.hasNext())
{
roleManager.addRoleToUser(jsuser.getName(), (String)_itTemp.next());
}
}
JSUserAttributes attributes = jsuser.getUserInfo();
if (attributes != null)
{