@SuppressWarnings("unchecked")
public void upgrade(UpgradeMessage message)
throws ConfigurationIsCorruptedException
{
Configuration oldc = (Configuration) message.getConfiguration();
org.sonatype.security.model.v2_0_1.Configuration newc = new org.sonatype.security.model.v2_0_1.Configuration();
newc.setVersion(org.sonatype.security.model.v2_0_1.Configuration.MODEL_VERSION);
for (CUser oldu : (List<CUser>) oldc.getUsers()) {
org.sonatype.security.model.v2_0_1.CUser newu = new org.sonatype.security.model.v2_0_1.CUser();
newu.setEmail(oldu.getEmail());
newu.setId(oldu.getId());
newu.setName(oldu.getName());
newu.setPassword(oldu.getPassword());
newu.setStatus(oldu.getStatus());
newu.setRoles(oldu.getRoles());
newc.addUser(newu);
}
List<RoleMap> roleMapList = new ArrayList<RoleMap>();
for (CRole oldr : (List<CRole>) oldc.getRoles()) {
// Simplest case, not an internal role, just copy
if (!getRolesToRemove().contains(oldr.getId())) {
org.sonatype.security.model.v2_0_1.CRole newr = new org.sonatype.security.model.v2_0_1.CRole();
newr.setDescription(oldr.getDescription());
newr.setId(oldr.getId());
newr.setName(oldr.getName());
newr.setPrivileges(oldr.getPrivileges());
newr.setRoles(oldr.getRoles());
newr.setSessionTimeout(oldr.getSessionTimeout());
newc.addRole(newr);
}
// If we have internally, and the user has changed the role previously (as read only is new in this version)
else if (shouldArchiveRole(oldr)) {
org.sonatype.security.model.v2_0_1.CRole newr = new org.sonatype.security.model.v2_0_1.CRole();
newr.setDescription(oldr.getDescription());
newr.setId(oldr.getId() + "-customized");
newr.setName(oldr.getName() + " (Customized)");
newr.setPrivileges(oldr.getPrivileges());
newr.setRoles(oldr.getRoles());
newr.setSessionTimeout(oldr.getSessionTimeout());
newc.addRole(newr);
roleMapList.add(new RoleMap(oldr.getId(), newr.getId()));
}
// else the role will be removed, if it is now internal, and the user hasn't changed it
}
for (CPrivilege oldp : (List<CPrivilege>) oldc.getPrivileges()) {
if (!getPrivsToRemove().contains(oldp.getId())) {
org.sonatype.security.model.v2_0_1.CPrivilege newp =
new org.sonatype.security.model.v2_0_1.CPrivilege();
newp.setDescription(oldp.getDescription());