();
for (JetspeedPrincipalAssociationType assocType : principalManager.getAssociationTypes())
{
String associationName = assocType.getAssociationName();
if (associationNames.add(associationName))
{
for (String otherPrincipalTypeName : copiedPrincipalTypes.keySet())
{
otherPrincipalManager = this.principalManagerProvider.getManager(this.principalManagerProvider.getPrincipalType(otherPrincipalTypeName));
for (JetspeedPrincipal toPrincipal : otherPrincipalManager.getAssociatedFrom(principal.getName(), principal.getType(), associationName))
{
JSPrincipalAssociation jsAssoc = createJSPrincipalAssociation(associationName, principal, toPrincipal);
snapshot.addPrincipalAssociation(jsAssoc);
}
}
}
}
}
}
}
private JSPrincipalAssociation createJSPrincipalAssociation(String associationName, JetspeedPrincipal from, JetspeedPrincipal to)
{
JSPrincipalAssociation jsAssoc = new JSPrincipalAssociation();
jsAssoc.setName(associationName);
jsAssoc.setFromType(from.getType().getName());
jsAssoc.setFromName(from.getName());
jsAssoc.setToType(to.getType().getName());
jsAssoc.setToName(to.getName());
return jsAssoc;
}
/**
* extract all permissions from the current environment
*
* @throws SerializerException
*/
private void exportPermissions(ExportRefs refs, JSSnapshot snapshot, Map settings, Logger 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))
{
String principalTypeName = principal.getType().getName();
JSPrincipal jsPrincipal = refs.getPrincipalMap(principalTypeName).get(principal.getName());
if (jsPrincipal != null)
{
// TODO: handle permission principals generically
if (JetspeedPrincipalType.ROLE.equals(principalTypeName))
{
_js.addRole(jsPrincipal);
}
else if (JetspeedPrincipalType.GROUP.equals(principalTypeName))
{
_js.addGroup(jsPrincipal);
}
else if (JetspeedPrincipalType.USER.equals(principalTypeName))
{
_js.addUser(jsPrincipal);
}
}
}
snapshot.getPermissions().add(_js);
}
catch (Exception e)
{
throw new SerializerException(SerializerException.CREATE_SERIALIZED_OBJECT_FAILED.create(new String[] {
"Permissions", e.getMessage() }));
}
}
}
/**
* Add the credentials to the JSUser object.
*
* If the credential provided is a PasswordCredential, userid and password
* are extracted and set explcitely
*
* @param isPublic
* public or private credential
* @param newUser
* the JS user object reference
* @param credential
* the credential object
*/
private void addJSPrincipalCredentials(boolean isPublic, JSPrincipal newPrincipal, Credential credential)
{
if (credential == null)
return;
if (credential instanceof PasswordCredential)
{
PasswordCredential pw = (PasswordCredential) credential;
char [] pwdChars = (pw.getPassword() != null ? pw.getPassword().toCharArray() : null);
newPrincipal.setCredential(pw.getUserName(), pwdChars, pw.getExpirationDate(), pw.isEnabled(),
pw.isExpired(), pw.isUpdateRequired());
return;
}
else if (isPublic)
newPrincipal.addPublicCredential(credential);
else
newPrincipal.addPrivateCredential(credential);
}
private JSPrincipal createJSPrincipal(JetspeedPrincipal principal) throws SecurityException
{
JSPrincipal _jsPrincipal = new JSPrincipal();
_jsPrincipal.setPrincipal(principal);
_jsPrincipal.setType(principal.getType().getName());
_jsPrincipal.setName(principal.getName());
_jsPrincipal.setMapped(principal.isMapped());
_jsPrincipal.setEnabled(principal.isEnabled());
_jsPrincipal.setReadonly(principal.isReadOnly());
_jsPrincipal.setRemovable(principal.isRemovable());
_jsPrincipal.setExtendable(principal.isExtendable());
if (JetspeedPrincipalType.USER.equals(principal.getType().getName()))
{
Credential credential = userManager.getPasswordCredential((User) principal);
Subject subject = userManager.getSubject((User) principal);
if (credential != null)
{
addJSPrincipalCredentials(true, _jsPrincipal, credential);
}
for (Object o : subject.getPublicCredentials())
{
credential = (Credential)o;
addJSPrincipalCredentials(true, _jsPrincipal, credential);
}
for (Object o : subject.getPrivateCredentials())
{
credential = (Credential)o;
addJSPrincipalCredentials(false, _jsPrincipal, credential);
}
}
_jsPrincipal.setSecurityAttributes(principal.getSecurityAttributes().getAttributeMap());
return _jsPrincipal;
}
}