Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Copyright (C) 2007 Bull S. A. S.
* Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation
* version 2.1 of the License.
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301, USA.
**/
package org.ow2.bonita.identity.impl;
import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.security.Permission;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Properties;
import java.util.Set;
import org.ow2.bonita.identity.GroupOp;
import org.ow2.bonita.identity.Membership;
import org.ow2.bonita.identity.UserOp;
import org.ow2.bonita.util.Misc;
import org.xml.sax.SAXParseException;
/**
* @author "Pierre Vigneras"
* @date Dec 13, 2007
*/
public class XMLIdentityService extends PersistentIdentityService {
public XMLIdentityService(final String fileName, boolean create) throws IOException {
this(new File(fileName), create);
}
public XMLIdentityService(final File file, boolean create) throws IOException {
super(file, create);
}
protected void flush() {
XMLEncoder encoder = null;
try {
encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(
file)));
encoder.writeObject(next);
writeGroups(encoder);
writeUsers(encoder);
encoder.flush();
} catch (IOException ioe) {
throw new RuntimeException(ioe);
} finally {
Misc.close(encoder);
}
}
//private static final String NEXT_HEADER = "Next";
private static final String USERS_NB_HEADER = "Users nb";
private static final String USER_ID_HEADER = "UserOp id";
//private static final String USER_PROPERTIES_NB_HEADER = "UserOp Properties nb";
private static final String USER_PROPERTIES_HEADER = "UserOp Properties";
private static final String USER_MEMBERSHIPS_NB_HEADER = "UserOp Memberships nb";
private static final String USER_PERMISSIONS_HEADER = "UserOp Permissions";
private static final String GROUP_NB_HEADER = "Groups nb";
private static final String GROUP_ID_HEADER = "GroupOp id";
private static final String GROUP_PARENT_HEADER = "GroupOp parent";
private static final String GROUP_CHILDREN_NB_HEADER = "GroupOp children";
//private static final String GROUP_PROPERTIES_NB_HEADER = "GroupOp Properties nb";
private static final String GROUP_PROPERTIES_HEADER = "GroupOp Properties";
private static final String GROUP_MEMBERSHIPS_NB_HEADER = "GroupOp Memberships nb";
private static final String GROUP_PERMISSIONS_HEADER = "GroupOp Permissions";
//private static final String GROUP_PERMISSIONS_NB_HEADER = "Group Pemissions nb";
private void writeGroups(final XMLEncoder encoder) throws IOException {
encoder.writeObject(GROUP_NB_HEADER);
encoder.writeObject(groupOps.size());
final Collection< ? extends GroupOp> groupCollection = groupOps.values();
for (GroupOp groupOp : groupCollection) {
encoder.writeObject(GROUP_ID_HEADER);
encoder.writeObject(groupOp.getId());
encoder.writeObject(GROUP_PARENT_HEADER);
encoder.writeObject(groupOp.getParent().getId());
final Set children = groupOp.getChildren();
encoder.writeObject(GROUP_CHILDREN_NB_HEADER);
encoder.writeObject(children.size());
for (GroupOp child : children) {
encoder.writeObject(child.getId());
}
encoder.writeObject(GROUP_PROPERTIES_HEADER);
// writeProperties(encoder, groupOp.getProperties());
encoder.writeObject(groupOp.getProperties());
final Set memberships = groupOp.getMemberships();
encoder.writeObject(GROUP_MEMBERSHIPS_NB_HEADER);
encoder.writeObject(memberships.size());
for (Membership m : memberships) {
encoder.writeObject(m.getUser().getId());
}
encoder.writeObject(GROUP_PERMISSIONS_HEADER);
writePermissions(encoder, groupOp.getPermissions());
}
}
private void writePermissions(final XMLEncoder encoder,
Set permissions) {
encoder.writeObject(permissions);
}
/*
private void writeProperties(final XMLEncoder encoder, Properties properties) {
encoder.writeObject(properties.size());
for (Entry