[jbpm-commits] JBoss JBPM SVN: r4245 - in jbpm4/branches/tbaeyens/modules/pvm/src: main/java/org/jbpm/pvm/internal/wire/binding and 3 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Mon Mar 16 05:55:22 EDT 2009
Author: tom.baeyens at jboss.com
Date: 2009-03-16 05:55:22 -0400 (Mon, 16 Mar 2009)
New Revision: 4245
Added:
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/identity/impl/JBossIdmIdentitySessionImpl.java
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/identity/impl/MembershipImpl.java
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/JbossIdmIdentitySessionDescriptor.java
jbpm4/branches/tbaeyens/modules/pvm/src/test/resources/jbpm.identity.hbm.xml
Modified:
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/identity/impl/GroupImpl.java
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/identity/impl/IdentitySessionImpl.java
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/identity/impl/UserImpl.java
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/IdentitySessionBinding.java
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/IdentitySessionDescriptor.java
jbpm4/branches/tbaeyens/modules/pvm/src/test/java/org/jbpm/pvm/internal/identity/IdentityTest.java
jbpm4/branches/tbaeyens/modules/pvm/src/test/resources/jbpm.hibernate.cfg.xml
Log:
work
Modified: jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/identity/impl/GroupImpl.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/identity/impl/GroupImpl.java 2009-03-14 14:28:09 UTC (rev 4244)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/identity/impl/GroupImpl.java 2009-03-16 09:55:22 UTC (rev 4245)
@@ -33,8 +33,17 @@
private static final long serialVersionUID = 1L;
+ protected long dbid;
+ protected int dbversion;
+
+ protected GroupImpl parent;
+
protected String name;
+ protected String type;
+ public GroupImpl() {
+ }
+
public GroupImpl(String name) {
this.name = name;
}
@@ -42,4 +51,19 @@
public String getName() {
return name;
}
-}
+ public void setName(String name) {
+ this.name = name;
+ }
+ public GroupImpl getParent() {
+ return parent;
+ }
+ public void setParent(GroupImpl parent) {
+ this.parent = parent;
+ }
+ public String getType() {
+ return type;
+ }
+ public void setType(String type) {
+ this.type = type;
+ }
+}
\ No newline at end of file
Modified: jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/identity/impl/IdentitySessionImpl.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/identity/impl/IdentitySessionImpl.java 2009-03-14 14:28:09 UTC (rev 4244)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/identity/impl/IdentitySessionImpl.java 2009-03-16 09:55:22 UTC (rev 4245)
@@ -1,291 +1,128 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This 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; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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 software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jbpm.pvm.internal.identity.impl;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-import org.jboss.identity.idm.api.Attribute;
-import org.jboss.identity.idm.api.AttributesManager;
-import org.jboss.identity.idm.api.GroupType;
-import org.jboss.identity.idm.api.Identity;
-import org.jboss.identity.idm.api.IdentitySearchControl;
-import org.jboss.identity.idm.api.IdentitySession;
-import org.jboss.identity.idm.api.Role;
-import org.jboss.identity.idm.api.RoleType;
-import org.jboss.identity.idm.exception.IdentityException;
-import org.jboss.identity.idm.impl.api.NameFilterSearchControl;
-import org.jboss.identity.idm.impl.api.SimpleAttribute;
-import org.jboss.identity.idm.impl.api.model.SimpleGroupType;
-import org.jboss.identity.idm.p3p.P3PConstants;
-import org.jbpm.JbpmException;
-import org.jbpm.env.Environment;
-import org.jbpm.identity.Group;
-import org.jbpm.identity.User;
-import org.jbpm.pvm.internal.tx.StandardTransaction;
-
-
-/**
- * @author Tom Baeyens
- */
-public class IdentitySessionImpl implements org.jbpm.pvm.internal.identity.spi.IdentitySession {
-
- protected IdentitySession identitySession;
-
- public IdentitySessionImpl(IdentitySession identitySession) {
- this.identitySession = identitySession;
-
- StandardTransaction transaction = Environment.getFromCurrent(StandardTransaction.class);
- IdentitySessionResource identitySessionResource = new IdentitySessionResource(identitySession);
- transaction.enlistResource(identitySessionResource);
- }
-
- public void createUser(String userName, String givenName, String lastName) {
- try {
- Identity identity = identitySession.getPersistenceManager().createIdentity(userName);
- Attribute[] attributes = new Attribute[] {
- new SimpleAttribute(P3PConstants.INFO_USER_NAME_GIVEN, new String[] { givenName }),
- new SimpleAttribute(P3PConstants.INFO_USER_NAME_FAMILY, new String[] { lastName })
- };
- identitySession.getAttributesManager().addAttributes(identity, attributes);
- } catch (IdentityException e) {
- throw new JbpmException("couldn't create user "+userName, e);
- }
- }
-
- public List<User> getUsers() {
- try {
- Collection<Identity> identities = identitySession
- .getPersistenceManager()
- .findIdentity((IdentitySearchControl[])null);
-
- List<User> users = new ArrayList<User>();
- for (Identity identity : identities) {
- String name = identity.getName();
- String givenName = getAttributeString(identity, null, P3PConstants.INFO_USER_NAME_GIVEN);
- String familyName = getAttributeString(identity, P3PConstants.INFO_USER_NAME_FAMILY);
-
- UserImpl user = new UserImpl(name, givenName, familyName);
- users.add(user);
- }
-
- return users;
-
- } catch (IdentityException e) {
- throw new JbpmException("couldn't get users from identity component", e);
- }
- }
-
- public void deleteUser(String userName) {
- try {
- org.jboss.identity.idm.api.Identity identity = findIdentity(userName);
-
- if (identity==null) {
- return;
- }
-
- identitySession
- .getPersistenceManager()
- .removeIdentity(identity, true);
-
- } catch (IdentityException e) {
- throw new JbpmException("couldn't delete group "+userName, e);
- }
- }
-
- public void createGroup(String groupName, String groupType, String parentGroupName) {
- try {
- GroupType simpleGroupType = new SimpleGroupType(groupType);
- org.jboss.identity.idm.api.Group group = identitySession.getPersistenceManager().createGroup(groupName, simpleGroupType);
-
- if (parentGroupName!=null) {
- org.jboss.identity.idm.api.Group parentGroup = findGroup(parentGroupName, groupType);
- if (parentGroup==null) {
- throw new JbpmException("parent group "+parentGroupName+" doesn't exist");
- }
- identitySession.getRelationshipManager().associateGroups(parentGroup, group);
- }
-
- } catch (IdentityException e) {
- throw new JbpmException("couldn't create group "+groupName, e);
- }
- }
-
- public List<Group> getGroups(String groupType) {
- try {
- GroupType simpleGroupType = new SimpleGroupType(groupType);
- Collection<org.jboss.identity.idm.api.Group> idGroups = identitySession
- .getPersistenceManager()
- .findGroup(simpleGroupType);
-
- List<Group> groups = new ArrayList<Group>();
- for (org.jboss.identity.idm.api.Group idGroup: idGroups) {
- String groupName = idGroup.getName();
-
- GroupImpl group = new GroupImpl(groupName);
- groups.add(group);
- }
-
- return groups;
-
- } catch (IdentityException e) {
- throw new JbpmException("couldn't get users from identity component", e);
- }
- }
-
- public void deleteGroup(String groupName, String groupType) {
- try {
- org.jboss.identity.idm.api.Group group = findGroup(groupName, groupType);
-
- if (group==null) {
- return;
- }
-
- identitySession
- .getPersistenceManager()
- .removeGroup(group, true);
-
- } catch (IdentityException e) {
- throw new JbpmException("couldn't delete group "+groupName, e);
- }
- }
-
- public void createMembership(String userName, String groupName, String groupType, String role) {
- try {
- org.jboss.identity.idm.api.Group group = findGroup(groupName, groupType);
- if (group==null) {
- throw new JbpmException("group "+groupName+" doesn't exist");
- }
-
- org.jboss.identity.idm.api.Identity identity = findIdentity(userName);
- if (identity==null) {
- throw new JbpmException("user "+userName+" doesn't exist");
- }
-
-
- if (role!=null) {
- RoleType roleType = identitySession.getRoleManager().getRoleType(role);
- if (roleType==null) {
- roleType = identitySession.getRoleManager().createRoleType(role);
- }
-
- identitySession.getRoleManager().createRole(roleType, identity, group);
-
- } else {
- identitySession.getRelationshipManager().associateIdentities(group, identity);
- }
-
- } catch (Exception e) {
- throw new JbpmException("couldn't create membership "+userName+", "+groupName+", "+role, e);
- }
- }
-
- public List<Group> findGroupsByUserAndGroupType(String userName, String groupType) {
- try {
- org.jboss.identity.idm.api.Identity identity = findIdentity(userName);
- if (identity==null) {
- return Collections.EMPTY_LIST;
- }
-
- List<Group> groups = new ArrayList<Group>();
-
- GroupType identityGroupType = new SimpleGroupType(groupType);
- Collection<org.jboss.identity.idm.api.Group> identityGroups = identitySession
- .getRoleManager()
- .findGroupsWithRelatedRole(identity, identityGroupType, null);
-
- for (org.jboss.identity.idm.api.Group identityGroup: identityGroups) {
- String groupName = identityGroup.getName();
- GroupImpl group = new GroupImpl(groupName);
- groups.add(group);
- }
-
- return groups;
-
- } catch (Exception e) {
- throw new JbpmException("couldn't get groups for user "+userName+" and groupType "+groupType, e);
- }
- }
-
- protected org.jboss.identity.idm.api.Identity findIdentity(String userName) throws IdentityException {
- Collection<org.jboss.identity.idm.api.Identity> identities = identitySession
- .getPersistenceManager()
- .findIdentity(new IdentitySearchControl[]{
- new NameFilterSearchControl(userName)
- } );
-
- if ( (identities==null) || (identities.size()==0) ) {
- return null;
- }
-
- return identities.iterator().next();
- }
-
- protected org.jboss.identity.idm.api.Group findGroup(String groupName, String groupType) throws IdentityException {
- GroupType groupIdType = new SimpleGroupType(groupType);
-
- Collection<org.jboss.identity.idm.api.Group> groups = identitySession
- .getPersistenceManager()
- .findGroup(groupIdType, new IdentitySearchControl[]{
- new NameFilterSearchControl(groupName)
- } );
-
- if ( (groups==null) || (groups.size()==0) ) {
- return null;
- }
-
- return groups.iterator().next();
- }
-
- protected String getAttributeString(Identity identity, String attributeName) throws IdentityException {
- return getAttributeString(identity, null, attributeName);
- }
-
- protected String getAttributeString(org.jboss.identity.idm.api.Group idGroup, String attributeName) throws IdentityException {
- return getAttributeString(null, idGroup, attributeName);
- }
-
- protected String getAttributeString(Identity identity, org.jboss.identity.idm.api.Group idGroup, String attributeName) throws IdentityException {
- AttributesManager attributesManager = identitySession.getAttributesManager();
- Attribute attribute = null;
- if (identity!=null) {
- attribute = attributesManager.getAttribute(identity, attributeName);
- } else {
- attribute = attributesManager.getAttribute(idGroup, attributeName);
- }
- if (attribute!=null) {
- return (String) attribute.getValue();
- }
- return null;
- }
-
-
- public IdentitySession getIdentitySession() {
- return identitySession;
- }
-
- public void setIdentitySession(IdentitySession identitySession) {
- this.identitySession = identitySession;
- }
-}
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.identity.impl;
+
+import java.util.List;
+
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.jbpm.identity.Group;
+import org.jbpm.identity.User;
+import org.jbpm.pvm.internal.identity.spi.IdentitySession;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class IdentitySessionImpl implements IdentitySession {
+
+ protected Session session;
+
+ public void createGroup(String groupName, String groupType, String parentGroupName) {
+ GroupImpl group = new GroupImpl();
+ group.setName(groupName);
+ group.setType(groupType);
+
+ if (parentGroupName!=null) {
+ GroupImpl parentGroup = findGroup(parentGroupName, null);
+ group.setParent(parentGroup);
+ }
+
+ session.save(group);
+ }
+
+ protected GroupImpl findGroup(String name, String type) {
+ GroupImpl group = (GroupImpl) session.createQuery(
+ "select group " +
+ "from "+GroupImpl.class.getName()+" as group " +
+ "where group.name = '"+name+"'" +
+ (type!=null ? " and group.type = '"+type+"'" : "")
+ ).uniqueResult();
+ return group;
+ }
+
+ protected UserImpl findUser(String name) {
+ UserImpl user = (UserImpl) session.createQuery(
+ "select user " +
+ "from "+UserImpl.class.getName()+" as user " +
+ "where user.name = '"+name+"'"
+ ).uniqueResult();
+ return user;
+ }
+
+ public void createMembership(String userName, String groupName, String groupType, String role) {
+ UserImpl user = findUser(userName);
+ GroupImpl group = findGroup(groupName, groupType);
+
+ MembershipImpl membership = new MembershipImpl();
+ membership.setUser(user);
+ membership.setGroup(group);
+ membership.setRole(role);
+
+ session.save(membership);
+ }
+
+ public void createUser(String userName, String givenName, String familyName) {
+ UserImpl user = new UserImpl();
+ user.setName(userName);
+ user.setGivenName(givenName);
+ user.setFamilyName(familyName);
+
+ session.save(user);
+ }
+
+ public void deleteGroup(String groupName, String groupType) {
+ GroupImpl group = findGroup(groupName, groupType);
+ session.delete(group);
+ }
+
+ public void deleteUser(String userName) {
+ UserImpl user = findUser(userName);
+ session.delete(user);
+ }
+
+ public List<Group> findGroupsByUserAndGroupType(String userName, String groupType) {
+ Query query = session.createQuery(
+ "select distinct membership.group " +
+ "from "+MembershipImpl.class.getName()+" as membership, " +
+ "where membership.user.name = '"+userName+"'" +
+ " and membership.group.type = '"+groupType+"'"
+ );
+ return query.list();
+ }
+
+ public List<Group> getGroups(String groupType) {
+ return session.createQuery(
+ "from "+GroupImpl.class.getName()
+ ).list();
+ }
+
+ public List<User> getUsers() {
+ return session.createQuery(
+ "from "+UserImpl.class.getName()
+ ).list();
+ }
+
+ public void setSession(Session session) {
+ this.session = session;
+ }
+}
Copied: jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/identity/impl/JBossIdmIdentitySessionImpl.java (from rev 4244, jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/identity/impl/IdentitySessionImpl.java)
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/identity/impl/JBossIdmIdentitySessionImpl.java (rev 0)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/identity/impl/JBossIdmIdentitySessionImpl.java 2009-03-16 09:55:22 UTC (rev 4245)
@@ -0,0 +1,290 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.identity.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import org.jboss.identity.idm.api.Attribute;
+import org.jboss.identity.idm.api.AttributesManager;
+import org.jboss.identity.idm.api.GroupType;
+import org.jboss.identity.idm.api.Identity;
+import org.jboss.identity.idm.api.IdentitySearchControl;
+import org.jboss.identity.idm.api.IdentitySession;
+import org.jboss.identity.idm.api.RoleType;
+import org.jboss.identity.idm.exception.IdentityException;
+import org.jboss.identity.idm.impl.api.NameFilterSearchControl;
+import org.jboss.identity.idm.impl.api.SimpleAttribute;
+import org.jboss.identity.idm.impl.api.model.SimpleGroupType;
+import org.jboss.identity.idm.p3p.P3PConstants;
+import org.jbpm.JbpmException;
+import org.jbpm.env.Environment;
+import org.jbpm.identity.Group;
+import org.jbpm.identity.User;
+import org.jbpm.pvm.internal.tx.StandardTransaction;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class JBossIdmIdentitySessionImpl implements org.jbpm.pvm.internal.identity.spi.IdentitySession {
+
+ protected IdentitySession identitySession;
+
+ public JBossIdmIdentitySessionImpl(IdentitySession identitySession) {
+ this.identitySession = identitySession;
+
+ StandardTransaction transaction = Environment.getFromCurrent(StandardTransaction.class);
+ IdentitySessionResource identitySessionResource = new IdentitySessionResource(identitySession);
+ transaction.enlistResource(identitySessionResource);
+ }
+
+ public void createUser(String userName, String givenName, String lastName) {
+ try {
+ Identity identity = identitySession.getPersistenceManager().createIdentity(userName);
+ Attribute[] attributes = new Attribute[] {
+ new SimpleAttribute(P3PConstants.INFO_USER_NAME_GIVEN, new String[] { givenName }),
+ new SimpleAttribute(P3PConstants.INFO_USER_NAME_FAMILY, new String[] { lastName })
+ };
+ identitySession.getAttributesManager().addAttributes(identity, attributes);
+ } catch (IdentityException e) {
+ throw new JbpmException("couldn't create user "+userName, e);
+ }
+ }
+
+ public List<User> getUsers() {
+ try {
+ Collection<Identity> identities = identitySession
+ .getPersistenceManager()
+ .findIdentity((IdentitySearchControl[])null);
+
+ List<User> users = new ArrayList<User>();
+ for (Identity identity : identities) {
+ String name = identity.getName();
+ String givenName = getAttributeString(identity, null, P3PConstants.INFO_USER_NAME_GIVEN);
+ String familyName = getAttributeString(identity, P3PConstants.INFO_USER_NAME_FAMILY);
+
+ UserImpl user = new UserImpl(name, givenName, familyName);
+ users.add(user);
+ }
+
+ return users;
+
+ } catch (IdentityException e) {
+ throw new JbpmException("couldn't get users from identity component", e);
+ }
+ }
+
+ public void deleteUser(String userName) {
+ try {
+ org.jboss.identity.idm.api.Identity identity = findIdentity(userName);
+
+ if (identity==null) {
+ return;
+ }
+
+ identitySession
+ .getPersistenceManager()
+ .removeIdentity(identity, true);
+
+ } catch (IdentityException e) {
+ throw new JbpmException("couldn't delete group "+userName, e);
+ }
+ }
+
+ public void createGroup(String groupName, String groupType, String parentGroupName) {
+ try {
+ GroupType simpleGroupType = new SimpleGroupType(groupType);
+ org.jboss.identity.idm.api.Group group = identitySession.getPersistenceManager().createGroup(groupName, simpleGroupType);
+
+ if (parentGroupName!=null) {
+ org.jboss.identity.idm.api.Group parentGroup = findGroup(parentGroupName, groupType);
+ if (parentGroup==null) {
+ throw new JbpmException("parent group "+parentGroupName+" doesn't exist");
+ }
+ identitySession.getRelationshipManager().associateGroups(parentGroup, group);
+ }
+
+ } catch (IdentityException e) {
+ throw new JbpmException("couldn't create group "+groupName, e);
+ }
+ }
+
+ public List<Group> getGroups(String groupType) {
+ try {
+ GroupType simpleGroupType = new SimpleGroupType(groupType);
+ Collection<org.jboss.identity.idm.api.Group> idGroups = identitySession
+ .getPersistenceManager()
+ .findGroup(simpleGroupType);
+
+ List<Group> groups = new ArrayList<Group>();
+ for (org.jboss.identity.idm.api.Group idGroup: idGroups) {
+ String groupName = idGroup.getName();
+
+ GroupImpl group = new GroupImpl(groupName);
+ groups.add(group);
+ }
+
+ return groups;
+
+ } catch (IdentityException e) {
+ throw new JbpmException("couldn't get users from identity component", e);
+ }
+ }
+
+ public void deleteGroup(String groupName, String groupType) {
+ try {
+ org.jboss.identity.idm.api.Group group = findGroup(groupName, groupType);
+
+ if (group==null) {
+ return;
+ }
+
+ identitySession
+ .getPersistenceManager()
+ .removeGroup(group, true);
+
+ } catch (IdentityException e) {
+ throw new JbpmException("couldn't delete group "+groupName, e);
+ }
+ }
+
+ public void createMembership(String userName, String groupName, String groupType, String role) {
+ try {
+ org.jboss.identity.idm.api.Group group = findGroup(groupName, groupType);
+ if (group==null) {
+ throw new JbpmException("group "+groupName+" doesn't exist");
+ }
+
+ org.jboss.identity.idm.api.Identity identity = findIdentity(userName);
+ if (identity==null) {
+ throw new JbpmException("user "+userName+" doesn't exist");
+ }
+
+
+ if (role!=null) {
+ RoleType roleType = identitySession.getRoleManager().getRoleType(role);
+ if (roleType==null) {
+ roleType = identitySession.getRoleManager().createRoleType(role);
+ }
+
+ identitySession.getRoleManager().createRole(roleType, identity, group);
+
+ } else {
+ identitySession.getRelationshipManager().associateIdentities(group, identity);
+ }
+
+ } catch (Exception e) {
+ throw new JbpmException("couldn't create membership "+userName+", "+groupName+", "+role, e);
+ }
+ }
+
+ public List<Group> findGroupsByUserAndGroupType(String userName, String groupType) {
+ try {
+ org.jboss.identity.idm.api.Identity identity = findIdentity(userName);
+ if (identity==null) {
+ return Collections.EMPTY_LIST;
+ }
+
+ List<Group> groups = new ArrayList<Group>();
+
+ GroupType identityGroupType = new SimpleGroupType(groupType);
+ Collection<org.jboss.identity.idm.api.Group> identityGroups = identitySession
+ .getRoleManager()
+ .findGroupsWithRelatedRole(identity, identityGroupType, null);
+
+ for (org.jboss.identity.idm.api.Group identityGroup: identityGroups) {
+ String groupName = identityGroup.getName();
+ GroupImpl group = new GroupImpl(groupName);
+ groups.add(group);
+ }
+
+ return groups;
+
+ } catch (Exception e) {
+ throw new JbpmException("couldn't get groups for user "+userName+" and groupType "+groupType, e);
+ }
+ }
+
+ protected org.jboss.identity.idm.api.Identity findIdentity(String userName) throws IdentityException {
+ Collection<org.jboss.identity.idm.api.Identity> identities = identitySession
+ .getPersistenceManager()
+ .findIdentity(new IdentitySearchControl[]{
+ new NameFilterSearchControl(userName)
+ } );
+
+ if ( (identities==null) || (identities.size()==0) ) {
+ return null;
+ }
+
+ return identities.iterator().next();
+ }
+
+ protected org.jboss.identity.idm.api.Group findGroup(String groupName, String groupType) throws IdentityException {
+ GroupType groupIdType = new SimpleGroupType(groupType);
+
+ Collection<org.jboss.identity.idm.api.Group> groups = identitySession
+ .getPersistenceManager()
+ .findGroup(groupIdType, new IdentitySearchControl[]{
+ new NameFilterSearchControl(groupName)
+ } );
+
+ if ( (groups==null) || (groups.size()==0) ) {
+ return null;
+ }
+
+ return groups.iterator().next();
+ }
+
+ protected String getAttributeString(Identity identity, String attributeName) throws IdentityException {
+ return getAttributeString(identity, null, attributeName);
+ }
+
+ protected String getAttributeString(org.jboss.identity.idm.api.Group idGroup, String attributeName) throws IdentityException {
+ return getAttributeString(null, idGroup, attributeName);
+ }
+
+ protected String getAttributeString(Identity identity, org.jboss.identity.idm.api.Group idGroup, String attributeName) throws IdentityException {
+ AttributesManager attributesManager = identitySession.getAttributesManager();
+ Attribute attribute = null;
+ if (identity!=null) {
+ attribute = attributesManager.getAttribute(identity, attributeName);
+ } else {
+ attribute = attributesManager.getAttribute(idGroup, attributeName);
+ }
+ if (attribute!=null) {
+ return (String) attribute.getValue();
+ }
+ return null;
+ }
+
+
+ public IdentitySession getIdentitySession() {
+ return identitySession;
+ }
+
+ public void setIdentitySession(IdentitySession identitySession) {
+ this.identitySession = identitySession;
+ }
+}
Property changes on: jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/identity/impl/JBossIdmIdentitySessionImpl.java
___________________________________________________________________
Name: svn:mergeinfo
+
Added: jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/identity/impl/MembershipImpl.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/identity/impl/MembershipImpl.java (rev 0)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/identity/impl/MembershipImpl.java 2009-03-16 09:55:22 UTC (rev 4245)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.identity.impl;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class MembershipImpl {
+
+ protected long dbid;
+ protected int dbversion;
+
+ protected UserImpl user;
+ protected GroupImpl group;
+ protected String role;
+
+ public UserImpl getUser() {
+ return user;
+ }
+
+ public void setUser(UserImpl user) {
+ this.user = user;
+ }
+
+ public GroupImpl getGroup() {
+ return group;
+ }
+
+ public void setGroup(GroupImpl group) {
+ this.group = group;
+ }
+
+ public String getRole() {
+ return role;
+ }
+
+ public void setRole(String role) {
+ this.role = role;
+ }
+}
Modified: jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/identity/impl/UserImpl.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/identity/impl/UserImpl.java 2009-03-14 14:28:09 UTC (rev 4244)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/identity/impl/UserImpl.java 2009-03-16 09:55:22 UTC (rev 4245)
@@ -33,10 +33,16 @@
private static final long serialVersionUID = 1L;
+ protected long dbid;
+ protected int dbversion;
+
protected String name;
protected String givenName;
protected String familyName;
+ public UserImpl() {
+ }
+
public UserImpl(String name, String givenName, String familyName) {
this.name = name;
this.givenName = givenName;
@@ -61,4 +67,14 @@
}
return name;
}
+
+ public void setName(String name) {
+ this.name = name;
+ }
+ public void setGivenName(String givenName) {
+ this.givenName = givenName;
+ }
+ public void setFamilyName(String familyName) {
+ this.familyName = familyName;
+ }
}
Modified: jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/IdentitySessionBinding.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/IdentitySessionBinding.java 2009-03-14 14:28:09 UTC (rev 4244)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/IdentitySessionBinding.java 2009-03-16 09:55:22 UTC (rev 4245)
@@ -21,7 +21,7 @@
*/
package org.jbpm.pvm.internal.wire.binding;
-import org.jbpm.pvm.internal.wire.descriptor.IdentitySessionDescriptor;
+import org.jbpm.pvm.internal.wire.descriptor.JbossIdmIdentitySessionDescriptor;
import org.jbpm.pvm.internal.xml.Parse;
import org.jbpm.pvm.internal.xml.Parser;
import org.w3c.dom.Element;
@@ -37,7 +37,7 @@
}
public Object parse(Element element, Parse parse, Parser parser) {
- IdentitySessionDescriptor descriptor = new IdentitySessionDescriptor();
+ JbossIdmIdentitySessionDescriptor descriptor = new JbossIdmIdentitySessionDescriptor();
if (element.hasAttribute("realm")) {
descriptor.setRealmName(element.getAttribute("realm"));
Modified: jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/IdentitySessionDescriptor.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/IdentitySessionDescriptor.java 2009-03-14 14:28:09 UTC (rev 4244)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/IdentitySessionDescriptor.java 2009-03-16 09:55:22 UTC (rev 4245)
@@ -1,53 +1,69 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This 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; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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 software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jbpm.pvm.internal.wire.descriptor;
-
-import org.jboss.identity.idm.api.IdentitySession;
-import org.jboss.identity.idm.api.IdentitySessionFactory;
-import org.jbpm.env.Environment;
-import org.jbpm.pvm.internal.identity.impl.IdentitySessionImpl;
-import org.jbpm.pvm.internal.wire.WireContext;
-import org.jbpm.pvm.internal.wire.WireDefinition;
-
-
-/**
- * @author Tom Baeyens
- */
-public class IdentitySessionDescriptor extends AbstractDescriptor {
-
- private static final long serialVersionUID = 1L;
-
- protected String realmName;
-
- public Object construct(WireContext wireContext) {
- IdentitySessionFactory identitySessionFactory = Environment.getFromCurrent(IdentitySessionFactory.class);
- return new IdentitySessionImpl(identitySessionFactory.createIdentitySession(realmName));
- }
-
- public Class< ? > getType(WireDefinition wireDefinition) {
- return org.jbpm.pvm.internal.identity.spi.IdentitySession.class;
- }
-
- public void setRealmName(String realmName) {
- this.realmName = realmName;
- }
-}
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.wire.descriptor;
+
+import org.hibernate.Session;
+import org.jbpm.pvm.internal.identity.impl.IdentitySessionImpl;
+import org.jbpm.pvm.internal.identity.spi.IdentitySession;
+import org.jbpm.pvm.internal.wire.WireContext;
+import org.jbpm.pvm.internal.wire.WireDefinition;
+import org.jbpm.pvm.internal.wire.WireException;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class IdentitySessionDescriptor extends AbstractDescriptor {
+
+ private static final long serialVersionUID = 1L;
+
+ String sessionName;
+
+ public Object construct(WireContext wireContext) {
+ return new IdentitySessionImpl();
+ }
+
+ public void initialize(Object object, WireContext wireContext) {
+ // get the hibernate-session
+ Session session = null;
+ if (sessionName!=null) {
+ session = (Session) wireContext.get(sessionName);
+ } else {
+ session = wireContext.get(Session.class);
+ }
+
+ if (session==null) {
+ throw new WireException("couldn't find hibernate-session "+(sessionName!=null ? "'"+sessionName+"'" : "by type ")+"to create identity-session");
+ }
+
+ // inject the session
+ ((IdentitySessionImpl)object).setSession(session);
+ }
+
+ public Class<?> getType(WireDefinition wireDefinition) {
+ return IdentitySession.class;
+ }
+
+ public void setSessionName(String sessionName) {
+ this.sessionName = sessionName;
+ }
+}
Copied: jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/JbossIdmIdentitySessionDescriptor.java (from rev 4244, jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/IdentitySessionDescriptor.java)
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/JbossIdmIdentitySessionDescriptor.java (rev 0)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/JbossIdmIdentitySessionDescriptor.java 2009-03-16 09:55:22 UTC (rev 4245)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.wire.descriptor;
+
+import org.jboss.identity.idm.api.IdentitySessionFactory;
+import org.jbpm.env.Environment;
+import org.jbpm.pvm.internal.identity.impl.JBossIdmIdentitySessionImpl;
+import org.jbpm.pvm.internal.wire.WireContext;
+import org.jbpm.pvm.internal.wire.WireDefinition;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class JbossIdmIdentitySessionDescriptor extends AbstractDescriptor {
+
+ private static final long serialVersionUID = 1L;
+
+ protected String realmName;
+
+ public Object construct(WireContext wireContext) {
+ IdentitySessionFactory identitySessionFactory = Environment.getFromCurrent(IdentitySessionFactory.class);
+ return new JBossIdmIdentitySessionImpl(identitySessionFactory.createIdentitySession(realmName));
+ }
+
+ public Class< ? > getType(WireDefinition wireDefinition) {
+ return org.jbpm.pvm.internal.identity.spi.IdentitySession.class;
+ }
+
+ public void setRealmName(String realmName) {
+ this.realmName = realmName;
+ }
+}
Property changes on: jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/JbossIdmIdentitySessionDescriptor.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: jbpm4/branches/tbaeyens/modules/pvm/src/test/java/org/jbpm/pvm/internal/identity/IdentityTest.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/test/java/org/jbpm/pvm/internal/identity/IdentityTest.java 2009-03-14 14:28:09 UTC (rev 4244)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/test/java/org/jbpm/pvm/internal/identity/IdentityTest.java 2009-03-16 09:55:22 UTC (rev 4245)
@@ -21,7 +21,6 @@
*/
package org.jbpm.pvm.internal.identity;
-import java.util.Collection;
import java.util.List;
import org.jbpm.IdentityService;
Modified: jbpm4/branches/tbaeyens/modules/pvm/src/test/resources/jbpm.hibernate.cfg.xml
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/test/resources/jbpm.hibernate.cfg.xml 2009-03-14 14:28:09 UTC (rev 4244)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/test/resources/jbpm.hibernate.cfg.xml 2009-03-16 09:55:22 UTC (rev 4245)
@@ -19,5 +19,6 @@
<mapping resource="jbpm.execution.hbm.xml" />
<mapping resource="jbpm.history.hbm.xml" />
<mapping resource="jbpm.task.hbm.xml" />
+ <mapping resource="jbpm.identity.hbm.xml" />
</session-factory>
</hibernate-configuration>
Added: jbpm4/branches/tbaeyens/modules/pvm/src/test/resources/jbpm.identity.hbm.xml
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/test/resources/jbpm.identity.hbm.xml (rev 0)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/test/resources/jbpm.identity.hbm.xml 2009-03-16 09:55:22 UTC (rev 4245)
@@ -0,0 +1,57 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.jbpm.pvm.internal.identity.impl" default-access="field">
+
+ <!-- ### USER ########################################################### -->
+ <class name="UserImpl" table="JBPM_ID_USER">
+ <id name="dbid" column="DBID_">
+ <generator class="native" />
+ </id>
+ <version name="dbversion" column="DBVERSION_" />
+
+ <property name="name" column="NAME_" />
+ <property name="givenName" column="GIVENNAME_" />
+ <property name="familyName" column="FAMILYNAME_" />
+ </class>
+
+ <!-- ### MEMBERSHIP ##################################################### -->
+ <class name="MembershipImpl" table="JBPM_ID_MEMBERSHIP">
+ <id name="dbid" column="DBID_">
+ <generator class="native" />
+ </id>
+ <version name="dbversion" column="DBVERSION_" />
+
+ <many-to-one name="user"
+ column="USER_"
+ class="UserImpl"
+ foreign-key="FK_MEM_USER"
+ index="IDX_MEM_USER"/>
+
+ <many-to-one name="group"
+ column="GROUP_"
+ class="GroupImpl"
+ foreign-key="FK_MEM_GROUP"
+ index="IDX_MEM_GROUP"/>
+
+ <property name="role" column="NAME_" />
+ </class>
+
+ <!-- ### GROUP ########################################################### -->
+ <class name="GroupImpl" table="JBPM_ID_GROUP">
+ <id name="dbid" column="DBID_">
+ <generator class="native" />
+ </id>
+ <version name="dbversion" column="DBVERSION_" />
+
+ <property name="name" column="NAME_" />
+ <property name="type" column="TYPE_" />
+
+ <many-to-one name="parent"
+ column="PARENT_"
+ class="GroupImpl"
+ foreign-key="FK_GROUP_PARENT"
+ index="IDX_GROUP_PARENT"/>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
More information about the jbpm-commits
mailing list