final String innerUserFolderPath = userFolderPath;
final PageManager innerPageManager = pageManager;
final String innerUserName = userName;
final User innerUser = user;
User powerUser = userManager.getUser(this.adminUser);
JetspeedException pe = (JetspeedException) JSSubject.doAsPrivileged(userManager.getSubject(powerUser), new PrivilegedAction()
{
public Object run()
{
try
{
if (innerUserFolderPath != null)
{
innerUser.getSecurityAttributes().getAttribute(User.JETSPEED_USER_SUBSITE_ATTRIBUTE, true).setStringValue(innerUserFolderPath);
userManager.updateUser(innerUser);
}
// ensure user folder parents are created
Folder makeFolder = innerPageManager.getFolder("/");
for (;;)
{
String path = makeFolder.getPath();
if (!path.endsWith("/"))
{
path += "/";
}
if (innerUserFolderPath.startsWith(path))
{
String makeFolderName = innerUserFolderPath.substring(path.length());
int endFolderNameIndex = makeFolderName.indexOf('/');
if (endFolderNameIndex != -1)
{
makeFolderName = makeFolderName.substring(0, endFolderNameIndex);
String makeFolderPath = path+makeFolderName;
if (!innerPageManager.folderExists(makeFolderPath))
{
makeFolder = innerPageManager.newFolder(makeFolderPath);
innerPageManager.updateFolder(makeFolder);
}
else
{
makeFolder = innerPageManager.getFolder(makeFolderPath);
}
}
else
{
break;
}
}
else
{
throw new FolderNotFoundException("Cannot make parent folders for user folder: "+innerUserFolderPath);
}
}
// create user's home folder
// deep copy from the default folder template tree, creating a deep-copy of the template
// in the new user's folder tree
Folder source = innerPageManager.getFolder(innerFolderTemplate);
innerPageManager.deepCopyFolder(source, innerUserFolderPath, innerUserName);
Folder newFolder = pageManager.getFolder(innerUserFolderPath);
newFolder.setTitle("My Home Space");
newFolder.setShortTitle("My Space");
return null;
}
catch (SecurityException s1)
{
return s1;
}
catch (FolderNotFoundException e1)
{
return e1;
}
catch (InvalidFolderException e1)
{
return e1;
}
catch (NodeException e1)
{
return e1;
}
}
}, null);
if(pe != null)
{
// rollback user creation and cascade roles, groups, etc
try
{
if (userManager.getUser(userName) != null)
{
userManager.removeUser(userName);
}
}
catch (Exception e)
{
log.error("Registration Error: Failed to rollback user " + userName);
}
log.error("Registration Error: Failed to create user folders for " + userName + ", " + pe.toString());
throw pe;
}
}
catch (Exception e)