You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by wo...@apache.org on 2008/10/03 12:25:04 UTC
svn commit: r701344 - in
/portals/jetspeed-2/portal/branches/security-refactoring/components:
jetspeed-page-manager/src/main/java/org/apache/jetspeed/serializer/
jetspeed-profiler/src/main/java/org/apache/jetspeed/serializer/
jetspeed-security/src/main...
Author: woonsan
Date: Fri Oct 3 03:25:02 2008
New Revision: 701344
URL: http://svn.apache.org/viewvc?rev=701344&view=rev
Log:
Flattening the Principal API.
Implemented basic generic principal importing/exporting.
Associations need to be implemented.
Modified:
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/serializer/JetspeedUserTemplateSerializer.java
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/serializer/JetspeedProfilerSerializer.java
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/serializer/JetspeedSecuritySerializer.java
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/JetspeedSerializerImpl.java
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSNVPElements.java
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSPermission.java
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSPrincipal.java
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSPrincipalRules.java
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSPrincipals.java
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSSecurityAttributes.java
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSSnapshot.java
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSUser.java
Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/serializer/JetspeedUserTemplateSerializer.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/serializer/JetspeedUserTemplateSerializer.java?rev=701344&r1=701343&r2=701344&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/serializer/JetspeedUserTemplateSerializer.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/serializer/JetspeedUserTemplateSerializer.java Fri Oct 3 03:25:02 2008
@@ -30,7 +30,6 @@
import org.apache.jetspeed.om.folder.FolderNotFoundException;
import org.apache.jetspeed.om.folder.InvalidFolderException;
import org.apache.jetspeed.page.PageManager;
-import org.apache.jetspeed.page.PageManagerUtils;
import org.apache.jetspeed.page.document.NodeException;
import org.apache.jetspeed.security.JSSubject;
import org.apache.jetspeed.security.JetspeedPrincipalType;
@@ -38,7 +37,7 @@
import org.apache.jetspeed.security.User;
import org.apache.jetspeed.security.UserManager;
import org.apache.jetspeed.serializer.objects.JSSnapshot;
-import org.apache.jetspeed.serializer.objects.JSUser;
+import org.apache.jetspeed.serializer.objects.JSPrincipal;
/**
* JetspeedSecuritySerializer - Security component serializer
@@ -86,6 +85,7 @@
{
log.info("creating user templates");
User adminUser = null;
+
try
{
adminUser = userManager.getUser(this.adminUserName);
@@ -95,30 +95,33 @@
System.out.println("admin user failed to retrieve " + adminUserName);
e.printStackTrace();
adminUser = null;
- }
+ }
+
if (adminUser == null)
throw new SerializerException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.USER, "admin"));
- for (JSUser user : snapshot.getUsers())
+
+ for (JSPrincipal user : snapshot.getUsers())
{
- String folderTemplate = user.getUserTemplate();
- String ssubsite = user.getSubsite();
- if (folderTemplate != null)
- {
- String userTemplate = null;
- String subsite = null;
- if (user.getSubsite() != null)
- {
- subsite = user.getSubsite();
- String path = PageManagerUtils.concatenatePaths(Folder.SUBSITE_ROOT_FOLDER, subsite);
- userTemplate = PageManagerUtils.concatenatePaths(path, Folder.USER_FOLDER + user.getName());
- //userTemplate = Folder.SUBSITE_ROOT_FOLDER + subsite + Folder.USER_FOLDER + user.getName();
- }
- else
- {
- userTemplate = Folder.USER_FOLDER + user.getName();
- }
- this.createUserTemplate(folderTemplate, userTemplate, subsite, this.pageManager, user.getName(), adminUser);
- }
+ // TODO: should have a specific user JSPrincipal class?
+// String folderTemplate = user.getUserTemplate();
+// String ssubsite = user.getSubsite();
+// if (folderTemplate != null)
+// {
+// String userTemplate = null;
+// String subsite = null;
+// if (user.getSubsite() != null)
+// {
+// subsite = user.getSubsite();
+// String path = PageManagerUtils.concatenatePaths(Folder.SUBSITE_ROOT_FOLDER, subsite);
+// userTemplate = PageManagerUtils.concatenatePaths(path, Folder.USER_FOLDER + user.getName());
+// //userTemplate = Folder.SUBSITE_ROOT_FOLDER + subsite + Folder.USER_FOLDER + user.getName();
+// }
+// else
+// {
+// userTemplate = Folder.USER_FOLDER + user.getName();
+// }
+// this.createUserTemplate(folderTemplate, userTemplate, subsite, this.pageManager, user.getName(), adminUser);
+// }
}
}
Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/serializer/JetspeedProfilerSerializer.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/serializer/JetspeedProfilerSerializer.java?rev=701344&r1=701343&r2=701344&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/serializer/JetspeedProfilerSerializer.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/serializer/JetspeedProfilerSerializer.java Fri Oct 3 03:25:02 2008
@@ -41,7 +41,7 @@
import org.apache.jetspeed.serializer.objects.JSRuleCriterion;
import org.apache.jetspeed.serializer.objects.JSRuleCriterions;
import org.apache.jetspeed.serializer.objects.JSSnapshot;
-import org.apache.jetspeed.serializer.objects.JSUser;
+import org.apache.jetspeed.serializer.objects.JSPrincipal;
/**
* JetspeedProfilerSerializer - Profiler component serializer
@@ -176,36 +176,27 @@
log.debug("recreateUserPrincipalRules - started");
// get Rules for each user
-
- Iterator _itUsers = snapshot.getUsers().iterator();
- while (_itUsers.hasNext())
+ for (JSPrincipal _user : snapshot.getUsers())
{
- JSUser _user = (JSUser) _itUsers.next();
- JSPrincipalRules jsRules = _user.getRules();
try
{
User user = userManager.getUser(_user.getName());
-
- if (jsRules != null)
+
+ for (JSPrincipalRule pr : _user.getRules())
{
- Iterator _itRoles = jsRules.iterator();
- while (_itRoles.hasNext())
+ ProfilingRule pRule = pm.getRule(pr.getRule());
+
+ try
{
- JSPrincipalRule pr = (JSPrincipalRule) _itRoles.next();
- ProfilingRule pRule = pm.getRule(pr.getRule());
-
- try
- {
- PrincipalRule p1 = pm.createPrincipalRule();
- p1.setLocatorName(pr.getLocator());
- p1.setProfilingRule(pRule);
- p1.setPrincipalName(user.getName());
- pm.storePrincipalRule(p1);
- }
- catch (Exception eRole)
- {
- eRole.printStackTrace();
- }
+ PrincipalRule p1 = pm.createPrincipalRule();
+ p1.setLocatorName(pr.getLocator());
+ p1.setProfilingRule(pRule);
+ p1.setPrincipalName(user.getName());
+ pm.storePrincipalRule(p1);
+ }
+ catch (Exception eRole)
+ {
+ eRole.printStackTrace();
}
}
}
@@ -214,8 +205,8 @@
eUser.printStackTrace();
}
}
+
log.debug("recreateUserPrincipalRules - done");
-
}
/**
@@ -369,19 +360,15 @@
private void exportUserPrincipalRules(JSSnapshot snapshot, Map settings, Log log) throws SerializerException
{
// get Rules for each user
-
- Iterator _itUsers = snapshot.getUsers().iterator();
- while (_itUsers.hasNext())
+
+ for (JSPrincipal _user : snapshot.getUsers())
{
- JSUser _user = (JSUser) _itUsers.next();
Principal principal = _user.getPrincipal();
+
if (principal != null)
{
- Collection col = pm.getRulesForPrincipal(principal);
- Iterator _itCol = col.iterator();
- while (_itCol.hasNext())
+ for (PrincipalRule p1 : (Collection<PrincipalRule>) pm.getRulesForPrincipal(principal))
{
- PrincipalRule p1 = (PrincipalRule) _itCol.next();
JSPrincipalRule pr = new JSPrincipalRule(p1.getLocatorName(), p1.getProfilingRule().getId());
_user.getRules().add(pr);
}
Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/serializer/JetspeedSecuritySerializer.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/serializer/JetspeedSecuritySerializer.java?rev=701344&r1=701343&r2=701344&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/serializer/JetspeedSecuritySerializer.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/serializer/JetspeedSecuritySerializer.java Fri Oct 3 03:25:02 2008
@@ -31,7 +31,6 @@
import org.apache.jetspeed.security.GroupManager;
import org.apache.jetspeed.security.JetspeedPermission;
import org.apache.jetspeed.security.JetspeedPrincipal;
-import org.apache.jetspeed.security.JetspeedPrincipalManager;
import org.apache.jetspeed.security.JetspeedPrincipalManagerProvider;
import org.apache.jetspeed.security.JetspeedPrincipalType;
import org.apache.jetspeed.security.PasswordCredential;
@@ -51,6 +50,7 @@
import org.apache.jetspeed.serializer.objects.JSPermissions;
import org.apache.jetspeed.serializer.objects.JSPrincipal;
import org.apache.jetspeed.serializer.objects.JSRole;
+import org.apache.jetspeed.serializer.objects.JSSecurityAttributes;
import org.apache.jetspeed.serializer.objects.JSSnapshot;
import org.apache.jetspeed.serializer.objects.JSUser;
import org.apache.jetspeed.serializer.objects.JSUserAttributes;
@@ -66,7 +66,7 @@
*/
public class JetspeedSecuritySerializer extends AbstractJetspeedComponentSerializer
{
- private static String ENCODING_STRING = "JETSPEED 2.1 - 2006";
+ private static String ENCODING_STRING = "JETSPEED 2.2 - 2008";
private static String JETSPEED = "JETSPEED";
private static class ImportRefs
@@ -100,9 +100,9 @@
private static class ExportRefs
{
private HashMap<String, HashMap<String, JSPrincipal>> principalMapByType = new HashMap<String, HashMap<String, JSPrincipal>>();
- private HashMap<String, JSRole> roleMap = new HashMap<String, JSRole>();
- private HashMap<String, JSGroup> groupMap = new HashMap<String, JSGroup>();
- private HashMap<String, JSUser> userMap = new HashMap<String, JSUser>();
+ private HashMap<String, JSPrincipal> roleMap = new HashMap<String, JSPrincipal>();
+ private HashMap<String, JSPrincipal> groupMap = new HashMap<String, JSPrincipal>();
+ private HashMap<String, JSPrincipal> userMap = new HashMap<String, JSPrincipal>();
private HashMap<String, JSPermission> permissionMap = new HashMap<String, JSPermission>();
public HashMap<String, JSPrincipal> getPrincipalMap(String principalTypeName)
@@ -144,14 +144,12 @@
{
log.info("collecting users/roles/groups");
ExportRefs refs = new ExportRefs();
- // TODO: exporting can be dangerous this time..
- //exportJetspeedPrincipals(refs, snapshot, settings, log);
- exportRolesGroupsUsers(refs, snapshot, settings, log);
+ exportJetspeedPrincipals(refs, snapshot, settings, log);
+
if (isSettingSet(settings, JetspeedSerializer.KEY_PROCESS_PERMISSIONS))
{
log.info("collecting permissions");
- // TODO: uncomment and fix after permission refactoring
- //exportPermissions(refs, snapshot, settings, log);
+ exportPermissions(refs, snapshot, settings, log);
}
}
catch (SecurityException se)
@@ -171,7 +169,6 @@
SynchronizationStateAccess.setSynchronizing(Boolean.TRUE);
ImportRefs refs = new ImportRefs();
recreateJetspeedPrincipals(refs, snapshot, settings, log);
- recreateRolesGroupsUsers(refs, snapshot, settings, log);
if (isSettingSet(settings, JetspeedSerializer.KEY_PROCESS_PERMISSIONS))
{
log.info("creating permissions");
@@ -226,71 +223,34 @@
}
/**
- * import the Jetspeed principals to the current environment
- * TODO: how about associations?
+ * import the groups, roles and finally the users to the current environment
*
* @throws SerializerException
*/
private void recreateJetspeedPrincipals(ImportRefs refs, JSSnapshot snapshot, Map settings, Log log)
throws SerializerException
{
- log.debug("recreateJetspeedPrincipals");
-
- Map<String, JetspeedPrincipalType> principalTypeMap = principalManagerProvider.getPrincipalTypeMap();
+ log.debug("recreateRolesGroupsUsers");
- for (JSPrincipal jsPrincipal : snapshot.getJetspeedPrincipals())
+ for (JSGroup jsGroup : snapshot.getOldGroups())
{
+ String name = jsGroup.getName();
+
try
{
- JetspeedPrincipalType type = principalTypeMap.get(jsPrincipal.getType());
- JetspeedPrincipalManager principalManager = principalManagerProvider.getManager(type);
-
- String name = jsPrincipal.getName();
-
- if (!principalManager.principalExists(name))
- {
- JetspeedPrincipal principal = principalManager.newPrincipal(name, jsPrincipal.isMapped());
- principal.setEnabled(jsPrincipal.isEnabled());
- principalManager.addPrincipal(principal, null);
-
- boolean updated = false;
-
- SecurityAttributes secAttrs = principal.getSecurityAttributes();
-
- for (JSNVPElement elem : jsPrincipal.getSecurityAttributes().getValues())
- {
- secAttrs.getAttribute(elem.getKey(), true).setStringValue(elem.getValue());
- updated = true;
- }
-
- if (updated)
- {
- principalManager.updatePrincipal(principal);
- }
-
- refs.getPrincipalMap(type.getName()).put(name, principal);
- }
+ if (!(groupManager.groupExists(name)))
+ groupManager.addGroup(name);
+ Group group = groupManager.getGroup(name);
+ refs.groupMap.put(name, (Principal) group);
}
catch (Exception e)
{
- throw new SerializerException(SerializerException.CREATE_OBJECT_FAILED.create(new String[] { "JetspeedPrincipal",
- e.getMessage() }));
+ throw new SerializerException(SerializerException.CREATE_OBJECT_FAILED.create(new String[] { "Group",
+ e.getMessage() }), e);
}
}
- log.debug("recreateJetspeedPrincipals - done");
- }
-
- /**
- * import the groups, roles and finally the users to the current environment
- *
- * @throws SerializerException
- */
- private void recreateRolesGroupsUsers(ImportRefs refs, JSSnapshot snapshot, Map settings, Log log)
- throws SerializerException
- {
- log.debug("recreateRolesGroupsUsers");
- for (JSGroup jsGroup : snapshot.getGroups())
+ for (JSPrincipal jsGroup : snapshot.getGroups())
{
String name = jsGroup.getName();
try
@@ -306,10 +266,29 @@
e.getMessage() }), e);
}
}
+
log.debug("recreateGroups - done");
+
log.debug("processing roles");
- for (JSRole jsRole : snapshot.getRoles())
+ for (JSRole jsRole : snapshot.getOldRoles())
+ {
+ String name = jsRole.getName();
+ try
+ {
+ if (!(roleManager.roleExists(name)))
+ roleManager.addRole(name);
+ Role role = roleManager.getRole(name);
+ refs.roleMap.put(name, (Principal) role);
+ }
+ catch (Exception e)
+ {
+ throw new SerializerException(SerializerException.CREATE_OBJECT_FAILED.create(new String[] { "Role",
+ e.getMessage() }));
+ }
+ }
+
+ for (JSPrincipal jsRole : snapshot.getRoles())
{
String name = jsRole.getName();
try
@@ -325,12 +304,15 @@
e.getMessage() }));
}
}
+
log.debug("recreateRoles - done");
+
log.debug("processing users");
/** determine whether passwords can be reconstructed or not */
int passwordEncoding = compareCurrentSecurityProvider(snapshot);
- for (JSUser jsuser : snapshot.getUsers())
+
+ for (JSUser jsuser : snapshot.getOldUsers())
{
try
{
@@ -343,7 +325,9 @@
{
if (user == null) // create new one
{
- String password = recreatePassword(jsuser.getPassword());
+ String pwdString = (jsuser.getPwDataValue("password"));
+ char [] pwdChars = (pwdString != null ? pwdString.toCharArray() : null);
+ String password = recreatePassword(pwdChars);
log.debug("add User " + jsuser.getName() + " with password " + (password));
user = userManager.addUser(jsuser.getName());
@@ -359,8 +343,8 @@
try
{
PasswordCredential pwc = userManager.getPasswordCredential(user);
- pwc.setEnabled(jsuser.getPwEnabled());
- pwc.setUpdateRequired(jsuser.getPwRequiredUpdate());
+ pwc.setEnabled(jsuser.getPwDataValueAsBoolean("enabled"));
+ pwc.setUpdateRequired(jsuser.getPwDataValueAsBoolean("requiresUpdate"));
java.sql.Date d = jsuser.getPwExpirationDate();
if (d != null)
pwc.setExpirationDate(d);
@@ -372,6 +356,7 @@
log.error("setting userinfo for " + jsuser.getName() + " failed because of "
+ e.getLocalizedMessage());
}
+
// credentials
Subject subject = userManager.getSubject(user);
List<Credential> listTemp = jsuser.getPrivateCredentials();
@@ -392,6 +377,7 @@
subject.getPublicCredentials().add(_itTemp.next());
}
}
+
JSUserGroups jsUserGroups = jsuser.getGroupString();
List<String> listUserGroups = null;
if (jsUserGroups != null)
@@ -448,6 +434,105 @@
throw new SerializerException(SerializerException.CREATE_OBJECT_FAILED.create(new String[] { "User",
e.getMessage() }));
}
+ }
+
+ for (JSPrincipal jsuser : snapshot.getUsers())
+ {
+ try
+ {
+ User user = null;
+ if (userManager.userExists(jsuser.getName()))
+ {
+ user = userManager.getUser(jsuser.getName());
+ }
+ if ((isSettingSet(settings, JetspeedSerializer.KEY_OVERWRITE_EXISTING)) || (user == null))
+ {
+ if (user == null) // create new one
+ {
+ String pwdString = jsuser.getPwDataValue("password");
+ char [] pwdChars = (pwdString != null ? pwdString.toCharArray() : null);
+ String password = recreatePassword(pwdChars);
+ log.debug("add User " + jsuser.getName() + " with password " + (password));
+
+ user = userManager.addUser(jsuser.getName());
+ if (password != null && password.length() > 0)
+ {
+ PasswordCredential pwc = userManager.getPasswordCredential(user);
+ pwc.setPassword(null, password);
+ pwc.setEncoded((passwordEncoding == JetspeedSerializer.PASSTHRU_REQUIRED));
+ userManager.storePasswordCredential(pwc);
+ }
+ log.debug("add User done ");
+ }
+ try
+ {
+ PasswordCredential pwc = userManager.getPasswordCredential(user);
+ pwc.setEnabled(jsuser.getPwDataValueAsBoolean("enabled"));
+ pwc.setUpdateRequired(jsuser.getPwDataValueAsBoolean("requiresUpdate"));
+ java.sql.Date d = jsuser.getPwDataValueAsDate("expirationDate");
+ if (d != null)
+ pwc.setExpirationDate(d);
+ userManager.storePasswordCredential(pwc);
+ }
+ catch (Exception e)
+ {
+ // most likely caused by protected users (like "guest")
+ log.error("setting userinfo for " + jsuser.getName() + " failed because of "
+ + e.getLocalizedMessage());
+ }
+
+ // TODO: private, public credential??
+// // credentials
+// Subject subject = userManager.getSubject(user);
+// List<Credential> listTemp = jsuser.getPrivateCredentials();
+// if ((listTemp != null) && (listTemp.size() > 0))
+// {
+// Iterator<Credential> _itTemp = listTemp.iterator();
+// while (_itTemp.hasNext())
+// {
+// subject.getPrivateCredentials().add(_itTemp.next());
+// }
+// }
+// listTemp = jsuser.getPublicCredentials();
+// if ((listTemp != null) && (listTemp.size() > 0))
+// {
+// Iterator<Credential> _itTemp = listTemp.iterator();
+// while (_itTemp.hasNext())
+// {
+// subject.getPublicCredentials().add(_itTemp.next());
+// }
+// }
+
+ JSSecurityAttributes attributes = jsuser.getInfoAttributes();
+ if (attributes != null)
+ {
+ SecurityAttributes userSecAttrs = user.getSecurityAttributes();
+
+ for (JSNVPElement element : attributes.getValues())
+ {
+ userSecAttrs.getAttribute(element.getKey(), true).setStringValue(element.getValue());
+ }
+ }
+ JSSecurityAttributes jsNVP = jsuser.getSecurityAttributes();
+ if ((jsNVP != null) && (jsNVP.getValues() != null))
+ {
+ SecurityAttributes userSecAttrs = user.getSecurityAttributes();
+
+ for (JSNVPElement element : jsNVP.getValues())
+ {
+ userSecAttrs.getAttribute(element.getKey(), true).setStringValue(element.getValue());
+ }
+ }
+ refs.userMap.put(jsuser.getName(), (Principal) user);
+ userManager.updateUser(user);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw new SerializerException(SerializerException.CREATE_OBJECT_FAILED.create(new String[] { "User",
+ e.getMessage() }));
+ }
}
log.debug("recreateUsers - done");
}
@@ -588,41 +673,6 @@
}
/**
- * Collect all the principals from the current environment.
- *
- * @throws SerializerException
- * @throws SecurityException
- */
- private void exportJetspeedPrincipals(ExportRefs refs, JSSnapshot snapshot, Map settings, Log log)
- throws SerializerException, SecurityException
- {
- /** set the security provider info in the snapshot file */
- snapshot.setEncryption(getEncryptionString());
-
- Map<String, JetspeedPrincipalType> principalTypeMap = principalManagerProvider.getPrincipalTypeMap();
-
- for (Map.Entry<String, JetspeedPrincipalType> entry : principalTypeMap.entrySet())
- {
- JetspeedPrincipalType principalType = entry.getValue();
- JetspeedPrincipalManager jpm = principalManagerProvider.getManager(principalType);
- List<? extends JetspeedPrincipal> principals = jpm.getPrincipals("");
-
- for (JetspeedPrincipal principal : principals)
- {
- Map<String, JSPrincipal> refMap = refs.getPrincipalMap(principal.getType().getName());
- JSPrincipal _tmpPrincipal = refMap.get(principal.getName());
-
- if (_tmpPrincipal == null)
- {
- _tmpPrincipal = createJSPrincipal(principal);
- refs.getPrincipalMap(principal.getType().getName()).put(_tmpPrincipal.getName(), _tmpPrincipal);
- snapshot.getJetspeedPrincipals().add(_tmpPrincipal);
- }
- }
- }
- }
-
- /**
* Collect all the roles, groups and users from the current environment.
* Include the current SecurityProvider to understand, whether the password
* collected can be used upon import
@@ -630,19 +680,20 @@
* @throws SerializerException
* @throws SecurityException
*/
- private void exportRolesGroupsUsers(ExportRefs refs, JSSnapshot snapshot, Map settings, Log log)
+ private void exportJetspeedPrincipals(ExportRefs refs, JSSnapshot snapshot, Map settings, Log log)
throws SerializerException, SecurityException
{
/** set the security provider info in the snapshot file */
snapshot.setEncryption(getEncryptionString());
+
for (Role role : roleManager.getRoles(""))
{
try
{
- JSRole _tempRole = (JSRole) getObjectBehindPrinicpal(refs.roleMap, role);
+ JSPrincipal _tempRole = (JSPrincipal) getObjectBehindPrinicpal(refs.roleMap, role);
if (_tempRole == null)
{
- _tempRole = createJSRole(role);
+ _tempRole = createJSPrincipal(role);
refs.roleMap.put(_tempRole.getName(), _tempRole);
snapshot.getRoles().add(_tempRole);
}
@@ -654,15 +705,16 @@
"Role", e.getMessage() }));
}
}
+
for (Group group : groupManager.getGroups(""))
{
try
{
- JSGroup _tempGroup = (JSGroup) getObjectBehindPrinicpal(refs.groupMap, group);
+ JSPrincipal _tempGroup = (JSPrincipal) getObjectBehindPrinicpal(refs.groupMap, group);
if (_tempGroup == null)
{
- _tempGroup = createJSGroup(group);
+ _tempGroup = createJSPrincipal(group);
refs.groupMap.put(_tempGroup.getName(), _tempGroup);
snapshot.getGroups().add(_tempGroup);
}
@@ -679,19 +731,19 @@
{
try
{
- JSUser _tempUser = createJSUser(refs, user);
+ JSPrincipal _tempUser = createJSPrincipal(user);
+ PasswordCredential pwc = userManager.getPasswordCredential(user);
+ char [] password = (pwc.getPassword() != null ? pwc.getPassword().toCharArray() : null);
+ _tempUser.setCredential(user.getName(), password, pwc.getExpirationDate(), pwc.isEnabled(), pwc.isExpired(), pwc.isUpdateRequired());
refs.userMap.put(_tempUser.getName(), _tempUser);
snapshot.getUsers().add(_tempUser);
}
catch (Exception e)
{
throw new SerializerException(SerializerException.CREATE_SERIALIZED_OBJECT_FAILED.create(new String[] {
- "User", e.getMessage() }));
+ "User", e.getMessage() }), e);
}
-
}
- return;
-
}
/**
@@ -700,58 +752,57 @@
* @throws SerializerException
*/
// TODO: uncomment and fix after permission refactoring
-// private void exportPermissions(ExportRefs refs, JSSnapshot snapshot, Map settings, Log log) throws SerializerException, SecurityException
-// {
-// for (InternalPermission p : pm.getInternalPermissions())
-// {
-// try
-// {
-// JSPermission _js = new JSPermission();
-// _js.setResource(p.getName());
-// _js.setActions(p.getActions());
-// _js.setId(p.getPermissionId());
-// _js.setType(_js.getTypeForClass(p.getClassname()));
-//
-// Iterator<InternalPrincipal> list2 = p.getPrincipals().iterator();
-// while (list2.hasNext())
-// {
-// InternalPrincipal o = list2.next();
-// InternalPrincipal principal = (InternalPrincipal) o;
-// if (principal.getType().equals(InternalRolePrincipal.ROLE_TYPE))
-// {
-// JSRole _tempRole = (JSRole) this.getObjectBehindPath(refs.roleMap, principal.getName());
-// if (_tempRole != null)
-// {
-// _js.addRole(_tempRole);
-// }
-// }
-// else if (principal.getType().equals(InternalGroupPrincipal.GROUP_TYPE))
-// {
-// JSGroup _tempGroup = (JSGroup) this.getObjectBehindPath(refs.groupMap, principal.getName());
-// if (_tempGroup != null)
-// {
-// _js.addGroup(_tempGroup);
-// }
-// }
-// else if (principal.getType().equals(InternalUserPrincipal.USER_TYPE))
-// {
-// JSUser _tempUser = (JSUser) this.getObjectBehindPath(refs.userMap, principal.getName());
-// if (_tempUser != null)
-// {
-// _js.addUser(_tempUser);
-// }
-// }
-// }
-// refs.permissionMap.put(_js.getType(), _js);
-// snapshot.getPermissions().add(_js);
-// }
-// catch (Exception e)
-// {
-// throw new SerializerException(SerializerException.CREATE_SERIALIZED_OBJECT_FAILED.create(new String[] {
-// "Permissions", e.getMessage() }));
-// }
-// }
-// }
+ private void exportPermissions(ExportRefs refs, JSSnapshot snapshot, Map settings, Log log) throws SerializerException, SecurityException
+ {
+ for (JetspeedPermission perm : pm.getPermissions())
+ {
+ try
+ {
+ JSPermission _js = new JSPermission();
+ _js.setResource(perm.getName());
+ _js.setActions(perm.getActions());
+ _js.setType(perm.getType());
+
+ for (JetspeedPrincipal principal : pm.getPrincipals(perm))
+ {
+ JetspeedPrincipalType principalType = principal.getType();
+
+ if (JetspeedPrincipalType.ROLE.equals(principalType))
+ {
+ JSPrincipal _tempRole = (JSPrincipal) this.getObjectBehindPath(refs.roleMap, principal.getName());
+
+ if (_tempRole != null)
+ {
+ _js.addRole(_tempRole);
+ }
+ }
+ else if (JetspeedPrincipalType.GROUP.equals(principalType))
+ {
+ JSPrincipal _tempGroup = (JSPrincipal) this.getObjectBehindPath(refs.groupMap, principal.getName());
+
+ if (_tempGroup != null)
+ {
+ _js.addGroup(_tempGroup);
+ }
+ }
+ else if (JetspeedPrincipalType.USER.equals(principalType))
+ {
+ JSPrincipal _tempUser = (JSPrincipal) this.getObjectBehindPath(refs.userMap, principal.getName());
+
+ if (_tempUser != null)
+ {
+ _js.addUser(_tempUser);
+ }
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ throw new SerializerException(SerializerException.CREATE_SERIALIZED_OBJECT_FAILED.create(new String[] {
+ "Permissions", e.getMessage() }));
+ }
+ }
+ }
/**
* simple lookup for principal object from a map
@@ -789,6 +840,7 @@
private JSPrincipal createJSPrincipal(JetspeedPrincipal principal)
{
JSPrincipal _jsPrincipal = new JSPrincipal();
+ _jsPrincipal.setPrincipal(principal);
_jsPrincipal.setType(principal.getType().getName());
_jsPrincipal.setName(principal.getName());
_jsPrincipal.setMapped(principal.isMapped());
@@ -843,8 +895,9 @@
if (credential instanceof PasswordCredential)
{
PasswordCredential pw = (PasswordCredential) credential;
- newUser.setUserCredential(pw.getUserName(), pw.getPassword().toCharArray(), pw.getExpirationDate(), pw.isEnabled(), pw
- .isExpired(), pw.isUpdateRequired());
+ char [] pwdChars = (pw.getPassword() != null ? pw.getPassword().toCharArray() : null);
+ newUser.setUserCredential(pw.getUserName(), pwdChars, pw.getExpirationDate(), pw.isEnabled(),
+ pw.isExpired(), pw.isUpdateRequired());
return;
}
else if (isPublic)
@@ -868,7 +921,7 @@
{
if (principal instanceof Role)
{
- JSRole _tempRole = (JSRole) this.getObjectBehindPath(refs.roleMap, principal.getName());
+ JSPrincipal _tempRole = (JSPrincipal) this.getObjectBehindPath(refs.roleMap, principal.getName());
if (_tempRole != null)
{
_newUser.addRole(_tempRole);
@@ -877,7 +930,7 @@
}
else if (principal instanceof Group)
{
- JSGroup _tempGroup = (JSGroup) this.getObjectBehindPath(refs.groupMap, principal.getName());
+ JSPrincipal _tempGroup = (JSPrincipal) this.getObjectBehindPath(refs.groupMap, principal.getName());
if (_tempGroup != null)
{
_newUser.addGroup(_tempGroup);
@@ -888,18 +941,29 @@
_newUser.setPrincipal(principal);
}
}
+
+ Credential credential = userManager.getPasswordCredential(user);
+
+ if (credential != null)
+ {
+ addJSUserCredentials(true, _newUser, credential);
+ }
+
for (Object o : subject.getPublicCredentials())
{
- Credential credential = (Credential)o;
+ credential = (Credential)o;
addJSUserCredentials(true, _newUser, credential);
}
+
for (Object o : subject.getPrivateCredentials())
{
- Credential credential = (Credential)o;
+ credential = (Credential)o;
addJSUserCredentials(false, _newUser, credential);
}
+
_newUser.setSecurityAttributes(user.getSecurityAttributes().getAttributeMap(SecurityAttribute.JETSPEED_CATEGORY));
_newUser.setUserInfo(user.getSecurityAttributes().getInfoAttributeMap());
+
return _newUser;
}
}
Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/JetspeedSerializerImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/JetspeedSerializerImpl.java?rev=701344&r1=701343&r2=701344&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/JetspeedSerializerImpl.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/JetspeedSerializerImpl.java Fri Oct 3 03:25:02 2008
@@ -45,13 +45,13 @@
import org.apache.jetspeed.serializer.objects.JSMediaTypes;
import org.apache.jetspeed.serializer.objects.JSMimeType;
import org.apache.jetspeed.serializer.objects.JSMimeTypes;
+import org.apache.jetspeed.serializer.objects.JSNVPElement;
import org.apache.jetspeed.serializer.objects.JSNVPElements;
import org.apache.jetspeed.serializer.objects.JSPWAttributes;
import org.apache.jetspeed.serializer.objects.JSPermission;
import org.apache.jetspeed.serializer.objects.JSPermissions;
import org.apache.jetspeed.serializer.objects.JSPortlet;
import org.apache.jetspeed.serializer.objects.JSPortlets;
-import org.apache.jetspeed.serializer.objects.JSPrincipal;
import org.apache.jetspeed.serializer.objects.JSPrincipalRule;
import org.apache.jetspeed.serializer.objects.JSPrincipalRules;
import org.apache.jetspeed.serializer.objects.JSPrincipals;
@@ -176,18 +176,18 @@
protected void setupAliases(XMLBinding binding)
{
- binding.setAlias(JSPrincipal.class, "Principal");
binding.setAlias(JSPrincipals.class, "Principals");
- binding.setAlias(JSSecurityAttributes.class, "SecurityAttributes");
- binding.setAlias(JSSecurityAttributes.class, "InfoAttributes");
binding.setAlias(JSRole.class, "Role");
binding.setAlias(JSRoles.class, "Roles");
binding.setAlias(JSGroup.class, "Group");
binding.setAlias(JSGroups.class, "Groups");
binding.setAlias(JSUser.class, "User");
binding.setAlias(JSUsers.class, "Users");
- binding.setAlias(JSNVPElements.class, "preferences");
+ binding.setAlias(JSSecurityAttributes.class, "SecurityAttributes");
binding.setAlias(JSUserAttributes.class, "userinfo");
+ binding.setAlias(JSNVPElements.class, "preferences");
+ binding.setAlias(JSNVPElement.class, "SecurityAttribute");
+ binding.setAlias(JSNVPElement.class, "preference");
binding.setAlias(JSSnapshot.class, "snapshot");
binding.setAlias(JSUserRoles.class, "roles");
binding.setAlias(JSUserGroups.class, "groups");
Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSNVPElements.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSNVPElements.java?rev=701344&r1=701343&r2=701344&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSNVPElements.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSNVPElements.java Fri Oct 3 03:25:02 2008
@@ -77,11 +77,13 @@
try
{
JSNVPElements g = (JSNVPElements) o;
+
for (JSNVPElement element : g.values)
{
xml.add(element, g.getItemElementName(), JSNVPElement.class);
}
- } catch (Exception e)
+ }
+ catch (Exception e)
{
e.printStackTrace();
}
@@ -93,12 +95,16 @@
try
{
JSNVPElements g = (JSNVPElements) o;
+
while (xml.hasNext())
{
- JSNVPElement elem = (JSNVPElement)xml.get(g.getItemElementName(), JSNVPElement.class);
+ // Allow any sub element as long as it has name-value pair.
+ //JSNVPElement elem = (JSNVPElement)xml.get(g.getItemElementName(), JSNVPElement.class);
+ JSNVPElement elem = (JSNVPElement)xml.getNext();
g.add(elem);
}
- } catch (Exception e)
+ }
+ catch (Exception e)
{
/**
* while annoying invalid entries in the file should be
Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSPermission.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSPermission.java?rev=701344&r1=701343&r2=701344&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSPermission.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSPermission.java Fri Oct 3 03:25:02 2008
@@ -18,6 +18,7 @@
import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
import javolution.xml.XMLFormat;
import javolution.xml.stream.XMLStreamException;
@@ -43,11 +44,11 @@
private long id;
- private ArrayList roles = null;
+ private List<JSPrincipal> roles = null;
- private ArrayList groups = null;
+ private List<JSPrincipal> groups = null;
- private ArrayList users = null;
+ private List<JSPrincipal> users = null;
private JSUserRoles roleString;
@@ -101,7 +102,7 @@
return s.toString();
}
- private String putTokens(ArrayList _list)
+ private String putTokens(List<JSPrincipal> _list)
{
if ((_list == null) || (_list.size() == 0))
return "";
@@ -140,7 +141,7 @@
/**
* @return Returns the groups.
*/
- public ArrayList getGroups()
+ public List<JSPrincipal> getGroups()
{
return groups;
}
@@ -174,7 +175,7 @@
/**
* @return Returns the roles.
*/
- public ArrayList getRoles()
+ public List<JSPrincipal> getRoles()
{
return roles;
}
@@ -183,7 +184,7 @@
* @param roles
* The roles to set.
*/
- public void setRoles(ArrayList roles)
+ public void setRoles(List<JSPrincipal> roles)
{
this.roles = roles;
}
@@ -208,7 +209,7 @@
/**
* @return Returns the users.
*/
- public ArrayList getUsers()
+ public List<JSPrincipal> getUsers()
{
return users;
}
@@ -240,27 +241,28 @@
this.id = id;
}
-
-
- public void addGroup(JSGroup group)
+ public void addGroup(JSPrincipal group)
{
if (groups == null)
- groups = new ArrayList();
+ groups = new ArrayList<JSPrincipal>();
+
groups.add(group);
}
- public void addRole(JSRole role)
+ public void addRole(JSPrincipal role)
{
if (roles == null)
- roles = new ArrayList();
+ roles = new ArrayList<JSPrincipal>();
+
roles.add(role);
}
- public void addUser(JSUser user)
+ public void addUser(JSPrincipal user)
{
if (users == null)
- users = new ArrayList();
+ users = new ArrayList<JSPrincipal>();
+
users.add(user);
}
Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSPrincipal.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSPrincipal.java?rev=701344&r1=701343&r2=701344&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSPrincipal.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSPrincipal.java Fri Oct 3 03:25:02 2008
@@ -16,13 +16,18 @@
*/
package org.apache.jetspeed.serializer.objects;
+import java.security.Principal;
+import java.sql.Date;
+import java.util.List;
import java.util.Map;
import javolution.xml.*;
import javolution.xml.stream.XMLStreamException;
import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.jetspeed.security.Credential;
import org.apache.jetspeed.security.SecurityAttribute;
+import org.apache.jetspeed.security.SecurityAttributeType;
/**
* Jetspeed Serialized (JS) JetspeedPrincipal
@@ -38,7 +43,13 @@
private boolean enabled;
private boolean readonly;
private boolean removable;
- private JSSecurityAttributes secAttrs = null;
+ private JSSecurityAttributes secAttrs;
+ private JSSecurityAttributes infoAttrs;
+ private JSPWAttributes pwData;
+ private List<Credential> publicCredentials;
+ private List<Credential> privateCredentials;
+ private transient Principal principal;
+ private JSPrincipalRules rules = new JSPrincipalRules();
public JSPrincipal()
{
@@ -54,7 +65,24 @@
try
{
JSPrincipal p = (JSPrincipal) o;
- xml.addText(p.getName());
+ xml.setAttribute("type", p.getType());
+ xml.setAttribute("name", p.getName());
+ xml.setAttribute("mapped", false);
+ xml.setAttribute("enabled", false);
+ xml.setAttribute("readonly", false);
+ xml.setAttribute("removable", false);
+
+ if (p.pwData != null)
+ xml.add(p.pwData);
+
+ if (p.secAttrs != null && p.secAttrs.size() > 0)
+ xml.add(p.secAttrs);
+
+ if (p.infoAttrs != null && p.infoAttrs.size() > 0)
+ xml.add(p.infoAttrs);
+
+ if (p.rules != null && p.rules.size() > 0)
+ xml.add(p.rules);
}
catch (Exception e)
{
@@ -67,11 +95,11 @@
try
{
JSPrincipal p = (JSPrincipal) o;
- p.setName(StringEscapeUtils.unescapeHtml(xml.getText().toString()));
- p.mapped = Boolean.getBoolean(StringEscapeUtils.unescapeHtml(xml.getAttribute("mapped", "false")));
- p.enabled = Boolean.getBoolean(StringEscapeUtils.unescapeHtml(xml.getAttribute("enabled", "false")));
- p.readonly = Boolean.getBoolean(StringEscapeUtils.unescapeHtml(xml.getAttribute("readonly", "false")));
- p.removable = Boolean.getBoolean(StringEscapeUtils.unescapeHtml(xml.getAttribute("removable", "false")));
+ p.setName(StringEscapeUtils.unescapeHtml(xml.getAttribute("name", "")));
+ p.mapped = xml.getAttribute("mapped", false);
+ p.enabled = xml.getAttribute("enabled", false);
+ p.readonly = xml.getAttribute("readonly", false);
+ p.removable = xml.getAttribute("removable", false);
Object o1 = null;
while (xml.hasNext())
@@ -80,7 +108,24 @@
if (o1 instanceof JSSecurityAttributes)
{
- p.secAttrs = (JSSecurityAttributes) o1;
+ JSSecurityAttributes sas = (JSSecurityAttributes) o1;
+
+ if (SecurityAttributeType.JETSPEED_CATEGORY.equals(sas.getCategory()))
+ {
+ p.secAttrs = sas;
+ }
+ else if (SecurityAttributeType.INFO_CATEGORY.equals(sas.getCategory()))
+ {
+ p.infoAttrs = sas;
+ }
+ }
+ else if (o1 instanceof JSPWAttributes)
+ {
+ p.pwData = (JSPWAttributes) o1;
+ }
+ else if (o1 instanceof JSPrincipalRules)
+ {
+ p.rules = (JSPrincipalRules) o1;
}
}
}
@@ -175,7 +220,7 @@
public void setSecurityAttributes(Map<String, SecurityAttribute> sa)
{
- this.secAttrs = new JSSecurityAttributes();
+ this.secAttrs = new JSSecurityAttributes(SecurityAttributeType.JETSPEED_CATEGORY);
for (Map.Entry<String, SecurityAttribute> e : sa.entrySet())
{
@@ -184,4 +229,106 @@
this.secAttrs.add(element);
}
}
-}
+
+ public JSSecurityAttributes getInfoAttributes()
+ {
+ return this.infoAttrs;
+ }
+
+ public void setInfoAttributes(JSSecurityAttributes infoAttrs)
+ {
+ this.infoAttrs = infoAttrs;
+ }
+
+ public void setInfoAttributes(Map<String, SecurityAttribute> sa)
+ {
+ this.infoAttrs = new JSSecurityAttributes(SecurityAttributeType.INFO_CATEGORY);
+
+ for (Map.Entry<String, SecurityAttribute> e : sa.entrySet())
+ {
+ SecurityAttribute attrib = e.getValue();
+ JSNVPElement element = new JSNVPElement(attrib.getName(), attrib.getStringValue());
+ this.infoAttrs.add(element);
+ }
+ }
+
+ public void setCredential(String name, char [] password, Date expirationDate, boolean isEnabled, boolean isExpired, boolean requireUpdate)
+ {
+ setName(name);
+ this.pwData = new JSPWAttributes();
+
+ if (password != null)
+ {
+ String passwordString = (password.length > 0 ? new String(password) : "");
+ this.pwData.getMyMap().put("password", passwordString);
+
+ if (expirationDate != null)
+ {
+ this.pwData.getMyMap().put("expirationDate",expirationDate.toString());
+ }
+
+ this.pwData.getMyMap().put("enabled", Boolean.toString(isEnabled));
+ this.pwData.getMyMap().put("requiresUpdate", Boolean.toString(requireUpdate));
+ }
+ }
+
+ public String getPwDataValue(String key)
+ {
+ return getPwDataValue(key, null);
+ }
+
+ public String getPwDataValue(String key, String defValue)
+ {
+ String value = (this.pwData != null ? this.pwData.getMyMap().get(key) : null);
+ return (value != null ? value : defValue);
+ }
+
+ public boolean getPwDataValueAsBoolean(String key)
+ {
+ return getPwDataValueAsBoolean(key, false);
+ }
+
+ public boolean getPwDataValueAsBoolean(String key, boolean defValue)
+ {
+ String sv = getPwDataValue(key);
+ return (sv != null ? Boolean.parseBoolean(sv) : defValue);
+ }
+
+ public Date getPwDataValueAsDate(String key)
+ {
+ return getPwDataValueAsDate(key, null);
+ }
+
+ public Date getPwDataValueAsDate(String key, Date defValue)
+ {
+ Date value = null;
+ String sv = getPwDataValue(key, null);
+
+ if (sv != null)
+ {
+ value = Date.valueOf(sv);
+ }
+
+ return (value != null ? value : defValue);
+ }
+
+ public Principal getPrincipal()
+ {
+ return principal;
+ }
+
+ public void setPrincipal(Principal principal)
+ {
+ this.principal = principal;
+ }
+
+ public JSPrincipalRules getRules()
+ {
+ return rules;
+ }
+
+ public void setRules(JSPrincipalRules rules)
+ {
+ this.rules = rules;
+ }
+}
\ No newline at end of file
Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSPrincipalRules.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSPrincipalRules.java?rev=701344&r1=701343&r2=701344&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSPrincipalRules.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSPrincipalRules.java Fri Oct 3 03:25:02 2008
@@ -27,6 +27,6 @@
* @author <a href="mailto:hajo@bluesunrise.com">Hajo Birthelmer</a>
* @version $Id: $
*/
-public class JSPrincipalRules extends ArrayList
+public class JSPrincipalRules extends ArrayList<JSPrincipalRule>
{
}
Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSPrincipals.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSPrincipals.java?rev=701344&r1=701343&r2=701344&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSPrincipals.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSPrincipals.java Fri Oct 3 03:25:02 2008
@@ -18,6 +18,11 @@
import java.util.ArrayList;
+import org.apache.jetspeed.security.JetspeedPrincipalType;
+
+import javolution.xml.XMLFormat;
+import javolution.xml.stream.XMLStreamException;
+
/**
* Simple wrapper class for XML serialization
@@ -28,4 +33,76 @@
public class JSPrincipals extends ArrayList<JSPrincipal>
{
private static final long serialVersionUID = -5698435742048612881L;
+
+ private String type = JetspeedPrincipalType.USER;
+
+ public JSPrincipals()
+ {
+ }
+
+ public JSPrincipals(String type)
+ {
+ this();
+ this.type = type;
+ }
+
+ public String getType()
+ {
+ return this.type;
+ }
+
+ public void setType(String type)
+ {
+ this.type = type;
+ }
+
+ /***************************************************************************
+ * SERIALIZER
+ */
+ private static final XMLFormat XML = new XMLFormat(JSPrincipals.class)
+ {
+
+ public void write(Object o, OutputElement xml)
+ throws XMLStreamException
+ {
+ try
+ {
+ JSPrincipals g = (JSPrincipals) o;
+ xml.setAttribute("type", g.getType());
+
+ for (JSPrincipal p : g)
+ {
+ xml.add(p, "Principal", JSPrincipal.class);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void read(InputElement xml, Object o)
+ {
+
+ try
+ {
+ JSPrincipals g = (JSPrincipals) o;
+ g.setType(xml.getAttribute("type", JetspeedPrincipalType.USER));
+
+ while (xml.hasNext())
+ {
+ JSPrincipal elem = (JSPrincipal) xml.get("Principal", JSPrincipal.class);
+ g.add(elem);
+ }
+ }
+ catch (Exception e)
+ {
+ /**
+ * while annoying invalid entries in the file should be
+ * just disregarded
+ */
+ e.printStackTrace();
+ }
+ }
+ };
}
\ No newline at end of file
Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSSecurityAttributes.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSSecurityAttributes.java?rev=701344&r1=701343&r2=701344&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSSecurityAttributes.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSSecurityAttributes.java Fri Oct 3 03:25:02 2008
@@ -17,11 +17,86 @@
package org.apache.jetspeed.serializer.objects;
+import org.apache.jetspeed.security.SecurityAttributeType;
+
+import javolution.xml.XMLFormat;
+import javolution.xml.stream.XMLStreamException;
+
public class JSSecurityAttributes extends JSNVPElements
{
+ private String category = SecurityAttributeType.JETSPEED_CATEGORY;
+
public JSSecurityAttributes()
{
super("SecurityAttribute");
}
+
+ public JSSecurityAttributes(String category)
+ {
+ this();
+ this.category = category;
+ }
+
+ public String getCategory()
+ {
+ return this.category;
+ }
+
+ public void setCategory(String category)
+ {
+ this.category = category;
+ }
+
+ /***************************************************************************
+ * SERIALIZER
+ */
+ /***************************************************************************
+ * SERIALIZER
+ */
+ private static final XMLFormat XML = new XMLFormat(JSSecurityAttributes.class)
+ {
+
+ public void write(Object o, OutputElement xml)
+ throws XMLStreamException
+ {
+ try
+ {
+ JSSecurityAttributes g = (JSSecurityAttributes) o;
+ xml.setAttribute("category", g.getCategory());
+
+ for (JSNVPElement element : g.getValues())
+ {
+ xml.add(element, g.getItemElementName(), JSNVPElement.class);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void read(InputElement xml, Object o)
+ {
+ try
+ {
+ JSSecurityAttributes g = (JSSecurityAttributes) o;
+ g.setCategory(xml.getAttribute("category", SecurityAttributeType.JETSPEED_CATEGORY));
+
+ while (xml.hasNext())
+ {
+ JSNVPElement elem = (JSNVPElement)xml.get(g.getItemElementName(), JSNVPElement.class);
+ g.add(elem);
+ }
+ }
+ catch (Exception e)
+ {
+ /**
+ * while annoying invalid entries in the file should be
+ * just disregarded
+ */
+ e.printStackTrace();
+ }
+ }
+ };
}
Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSSnapshot.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSSnapshot.java?rev=701344&r1=701343&r2=701344&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSSnapshot.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSSnapshot.java Fri Oct 3 03:25:02 2008
@@ -18,6 +18,7 @@
package org.apache.jetspeed.serializer.objects;
import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.jetspeed.security.JetspeedPrincipalType;
import org.apache.jetspeed.serializer.JetspeedSerializedData;
import javolution.xml.XMLFormat;
@@ -49,13 +50,17 @@
private JSCapabilities capabilities;
- private JSPrincipals jsPrincipals;
-
- private JSRoles roles;
+ private JSPrincipals roles;
+
+ private JSRoles oldRoles;
- private JSGroups groups;
+ private JSPrincipals groups;
+
+ private JSGroups oldGroups;
- private JSUsers users;
+ private JSPrincipals users;
+
+ private JSUsers oldUsers;
private JSPermissions permissions;
@@ -84,10 +89,12 @@
mediaTypes = new JSMediaTypes();
clients = new JSClients();
capabilities = new JSCapabilities();
- jsPrincipals = new JSPrincipals();
- roles = new JSRoles();
- groups = new JSGroups();
- users = new JSUsers();
+ roles = new JSPrincipals(JetspeedPrincipalType.ROLE);
+ oldRoles = new JSRoles();
+ groups = new JSPrincipals(JetspeedPrincipalType.GROUP);
+ oldGroups = new JSGroups();
+ users = new JSPrincipals(JetspeedPrincipalType.USER);
+ oldUsers = new JSUsers();
permissions = new JSPermissions();
rules = new JSProfilingRules();
applications = new JSApplications();
@@ -201,42 +208,43 @@
}
/**
- * @return Returns the Jetspeed principals.
+ * @return Returns the groups.
*/
- public JSPrincipals getJetspeedPrincipals()
+ public JSPrincipals getGroups()
{
- return jsPrincipals;
+ return groups;
}
-
+
/**
- * @param jsPrincipals The Jetspeed principals to set.
+ * @param groups
+ * The groups to set.
*/
- public void setJetspeedPrincipals(JSPrincipals jsPrincipals)
+ public void setGroups(JSPrincipals groups)
{
- this.jsPrincipals = jsPrincipals;
+ this.groups = groups;
}
/**
- * @return Returns the groups.
+ * @return Returns the groups from old format.
*/
- public JSGroups getGroups()
+ public JSGroups getOldGroups()
{
- return groups;
+ return oldGroups;
}
/**
- * @param groups
+ * @param groups from old format
* The groups to set.
*/
- public void setGroups(JSGroups groups)
+ public void setOldGroups(JSGroups oldGroups)
{
- this.groups = groups;
+ this.oldGroups = oldGroups;
}
-
+
/**
* @return Returns the roles.
*/
- public JSRoles getRoles()
+ public JSPrincipals getRoles()
{
return roles;
}
@@ -245,27 +253,52 @@
* @param roles
* The roles to set.
*/
- public void setRoles(JSRoles roles)
+ public void setRoles(JSPrincipals roles)
{
this.roles = roles;
}
/**
- * @return Returns the roles.
+ * @return Returns the roles from old format.
+ */
+ public JSRoles getOldRoles()
+ {
+ return oldRoles;
+ }
+
+ /**
+ * @param roles from old format
+ * The roles to set.
*/
- public JSUsers getUsers()
+ public void setOldRoles(JSRoles oldRoles)
+ {
+ this.oldRoles = oldRoles;
+ }
+
+ /**
+ * @return Returns the users.
+ */
+ public JSPrincipals getUsers()
{
return users;
}
/**
+ * @return Returns the users from old format.
+ */
+ public JSUsers getOldUsers()
+ {
+ return oldUsers;
+ }
+
+ /**
* @return Returns the encryption.
*/
public String getEncryption()
{
return encryption;
}
-
+
/**
* @param encryption
* The encryption to set.
@@ -353,7 +386,7 @@
* @param users
* The users to set.
*/
- public void setUsers(JSUsers users)
+ public void setUsers(JSPrincipals users)
{
this.users = users;
}
@@ -473,18 +506,26 @@
{
xml.add(g.getClients());
}
- if ( !g.getJetspeedPrincipals().isEmpty() )
+ if ( !g.getOldRoles().isEmpty() )
{
- xml.add(g.getJetspeedPrincipals());
+ xml.add(g.getOldRoles());
}
if ( !g.getRoles().isEmpty() )
{
xml.add(g.getRoles());
}
+ if ( !g.getOldGroups().isEmpty() )
+ {
+ xml.add(g.getOldGroups());
+ }
if ( !g.getGroups().isEmpty() )
{
xml.add(g.getGroups());
}
+ if ( !g.getOldUsers().isEmpty() )
+ {
+ xml.add(g.getOldUsers());
+ }
if ( !g.getUsers().isEmpty() )
{
xml.add(g.getUsers());
@@ -551,14 +592,30 @@
g.clients = (JSClients) o1;
else if (o1 instanceof JSCapabilities)
g.capabilities = (JSCapabilities) o1;
- else if (o1 instanceof JSPrincipals)
- g.jsPrincipals = (JSPrincipals) o1;
else if (o1 instanceof JSRoles)
- g.roles = (JSRoles) o1;
+ g.oldRoles = (JSRoles) o1;
else if (o1 instanceof JSGroups)
- g.groups = (JSGroups) o1;
+ g.oldGroups = (JSGroups) o1;
else if (o1 instanceof JSUsers)
- g.users = (JSUsers) o1;
+ g.oldUsers = (JSUsers) o1;
+ else if (o1 instanceof JSPrincipals)
+ {
+ JSPrincipals jsps = (JSPrincipals) o1;
+ String principalType = jsps.getType();
+
+ if (JetspeedPrincipalType.ROLE.equals(principalType))
+ {
+ g.roles = jsps;
+ }
+ else if (JetspeedPrincipalType.GROUP.equals(principalType))
+ {
+ g.groups = jsps;
+ }
+ else if (JetspeedPrincipalType.USER.equals(principalType))
+ {
+ g.users = jsps;
+ }
+ }
else if (o1 instanceof JSPermissions)
g.permissions = (JSPermissions) o1;
else if (o1 instanceof JSProfilingRules)
Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSUser.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSUser.java?rev=701344&r1=701343&r2=701344&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSUser.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-serializer/src/main/java/org/apache/jetspeed/serializer/objects/JSUser.java Fri Oct 3 03:25:02 2008
@@ -45,13 +45,13 @@
private JSPWAttributes pwData = null;
- private List<JSRole> roles = null;
+ private List<JSPrincipal> roles = null;
- private List<JSGroup> groups = null;
+ private List<JSPrincipal> groups = null;
private JSUserAttributes userInfo = null;
- private JSNVPElements attributes = null;
+ private JSSecurityAttributes attributes = null;
private List<Credential> publicCredentials = null;
@@ -86,26 +86,26 @@
privateCredentials.add(o);
}
- public void addGroup(JSGroup group)
+ public void addGroup(JSPrincipal group)
{
if (groups == null)
- groups = new ArrayList<JSGroup>();
+ groups = new ArrayList<JSPrincipal>();
groups.add(group);
}
- public void addRole(JSRole role)
+ public void addRole(JSPrincipal role)
{
if (roles == null)
- roles = new ArrayList<JSRole>();
+ roles = new ArrayList<JSPrincipal>();
roles.add(role);
}
- public List<JSGroup> getGroups()
+ public List<JSPrincipal> getGroups()
{
return groups;
}
- public void setGroups(List<JSGroup> groups)
+ public void setGroups(List<JSPrincipal> groups)
{
this.groups = groups;
}
@@ -211,12 +211,12 @@
this.name = name;
}
- public List<JSRole> getRoles()
+ public List<JSPrincipal> getRoles()
{
return roles;
}
- public void setRoles(List<JSRole> roles)
+ public void setRoles(List<JSPrincipal> roles)
{
this.roles = roles;
}
@@ -226,14 +226,14 @@
return name;
}
- public JSNVPElements getSecurityAttributes()
+ public JSSecurityAttributes getSecurityAttributes()
{
return attributes;
}
public void setSecurityAttributes(Map<String, SecurityAttribute> sa)
{
- this.attributes = new JSNVPElements();
+ this.attributes = new JSSecurityAttributes();
for (Map.Entry<String, SecurityAttribute> e : sa.entrySet())
{
SecurityAttribute attrib = e.getValue();
@@ -372,8 +372,8 @@
g.roleString = (JSUserRoles) o1;
else if (o1 instanceof JSUserAttributes)
g.userInfo = (JSUserAttributes) o1;
- else if (o1 instanceof JSNVPElements)
- g.attributes = (JSNVPElements) o1;
+ else if (o1 instanceof JSSecurityAttributes)
+ g.attributes = (JSSecurityAttributes) o1;
else if (o1 instanceof JSPrincipalRules)
g.rules = (JSPrincipalRules) o1;
}
@@ -387,9 +387,14 @@
};
- private String append(JSRole rule)
+ private String append(JSPrincipal principal)
{
- return rule.getName();
+ return principal.getName();
+ }
+
+ private String append(JSRole role)
+ {
+ return role.getName();
}
private String append(JSGroup group)
@@ -399,6 +404,7 @@
private String append(Object s)
{
+ if (s instanceof JSPrincipal) return append((JSPrincipal) s);
if (s instanceof JSRole) return append((JSRole) s);
if (s instanceof JSGroup) return append((JSGroup) s);
@@ -480,7 +486,47 @@
return pwData;
}
- public void setPwData(JSPWAttributes pwData)
+ public String getPwDataValue(String key)
+ {
+ return getPwDataValue(key, null);
+ }
+
+ public String getPwDataValue(String key, String defValue)
+ {
+ String value = (this.pwData != null ? this.pwData.getMyMap().get(key) : null);
+ return (value != null ? value : defValue);
+ }
+
+ public boolean getPwDataValueAsBoolean(String key)
+ {
+ return getPwDataValueAsBoolean(key, false);
+ }
+
+ public boolean getPwDataValueAsBoolean(String key, boolean defValue)
+ {
+ String sv = getPwDataValue(key);
+ return (sv != null ? Boolean.parseBoolean(sv) : defValue);
+ }
+
+ public Date getPwDataValueAsDate(String key)
+ {
+ return getPwDataValueAsDate(key, null);
+ }
+
+ public Date getPwDataValueAsDate(String key, Date defValue)
+ {
+ Date value = null;
+ String sv = getPwDataValue(key, null);
+
+ if (sv != null)
+ {
+ value = Date.valueOf(sv);
+ }
+
+ return (value != null ? value : defValue);
+ }
+
+ public void setPwData(JSPWAttributes pwData)
{
this.pwData = pwData;
}
@@ -491,7 +537,6 @@
return subsite;
}
-
public void setSubsite(String subsite)
{
this.subsite = subsite;
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org