Author: bdaw
Date: 2008-10-15 06:59:42 -0400 (Wed, 15 Oct 2008)
New Revision: 103
Added:
trunk/identity-api/src/main/java/org/jboss/identity/api/RoleManager.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/hibernate/HibernateIdentityObjectRelationshipName.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/ldap/LDAPIdentityObjectRelationshipImpl.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/
trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/APITestContext.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/GroupTypeEnum.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/OrganizationTest.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/SimpleGroupType.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/CommonIdentityStoreTest.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/IdentityStoreTestContext.java
trunk/identity-spi/src/main/java/org/jboss/identity/spi/exception/OperationNotSupportedException.java
Removed:
trunk/identity-api/src/main/java/org/jboss/identity/api/RelationshipType.java
Modified:
trunk/identity-api/src/main/java/org/jboss/identity/api/Group.java
trunk/identity-api/src/main/java/org/jboss/identity/api/Identity.java
trunk/identity-api/src/main/java/org/jboss/identity/api/IdentitySession.java
trunk/identity-api/src/main/java/org/jboss/identity/api/IdentityType.java
trunk/identity-api/src/main/java/org/jboss/identity/api/PersistenceManager.java
trunk/identity-api/src/main/java/org/jboss/identity/api/RealmManager.java
trunk/identity-api/src/main/java/org/jboss/identity/api/RelationshipManager.java
trunk/identity-api/src/main/java/org/jboss/identity/api/Role.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/hibernate/HibernateIdentityObject.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/hibernate/HibernateIdentityObjectRelationship.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/hibernate/HibernateIdentityObjectRelationshipType.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/hibernate/HibernateIdentityObjectType.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/hibernate/HibernateIdentityStoreImpl.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/ldap/LDAPIdentityObjectTypeConfiguration.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/ldap/LDAPIdentityStore.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/hibernate/HibernateIdentityStoreTestCase.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/ldap/LDAPIdentityStoreTestCase.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/ldap/SimpleLDAPIdentityObjectTypeConfiguration.java
trunk/identity-impl/src/test/resources/META-INF/persistence.xml
trunk/identity-impl/src/test/resources/ldap/initial-empty-opends.ldif
trunk/identity-spi/src/main/java/org/jboss/identity/spi/model/IdentityObjectRelationship.java
trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/AttributeStore.java
trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/IdentityStore.java
trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/OperationType.java
trunk/parent/pom.xml
Log:
just syncing code
Modified: trunk/identity-api/src/main/java/org/jboss/identity/api/Group.java
===================================================================
--- trunk/identity-api/src/main/java/org/jboss/identity/api/Group.java 2008-09-20 20:24:55
UTC (rev 102)
+++ trunk/identity-api/src/main/java/org/jboss/identity/api/Group.java 2008-10-15 10:59:42
UTC (rev 103)
@@ -34,9 +34,10 @@
{
/**
- * @return description
+ * <p>Return the name of the identity</p>
+ * @return
*/
- String getDescription();
+ String getName();
/**
* @return
Modified: trunk/identity-api/src/main/java/org/jboss/identity/api/Identity.java
===================================================================
--- trunk/identity-api/src/main/java/org/jboss/identity/api/Identity.java 2008-09-20
20:24:55 UTC (rev 102)
+++ trunk/identity-api/src/main/java/org/jboss/identity/api/Identity.java 2008-10-15
10:59:42 UTC (rev 103)
@@ -29,7 +29,14 @@
*/
public interface Identity extends IdentityType
{
+
/**
+ * <p>Return the name of the identity</p>
+ * @return
+ */
+ String getName();
+
+ /**
* Whether this is a virtual
* identity (such as a pseudonym)
* @return true (virtual identity)
Modified: trunk/identity-api/src/main/java/org/jboss/identity/api/IdentitySession.java
===================================================================
---
trunk/identity-api/src/main/java/org/jboss/identity/api/IdentitySession.java 2008-09-20
20:24:55 UTC (rev 102)
+++
trunk/identity-api/src/main/java/org/jboss/identity/api/IdentitySession.java 2008-10-15
10:59:42 UTC (rev 103)
@@ -70,6 +70,9 @@
*/
boolean isOpen();
+ //TODO: expose metadata describing capabilities of underlaying stores - or split it
between managers
+ //TODO: which groupType names are supported and etc.
+
/**
* @return
*/
@@ -96,4 +99,8 @@
*/
ProfileManager getProfileManager();
+
+ //TODO: proper exception if roles are not supported
+ RoleManager getRoleManager();
+
}
\ No newline at end of file
Modified: trunk/identity-api/src/main/java/org/jboss/identity/api/IdentityType.java
===================================================================
--- trunk/identity-api/src/main/java/org/jboss/identity/api/IdentityType.java 2008-09-20
20:24:55 UTC (rev 102)
+++ trunk/identity-api/src/main/java/org/jboss/identity/api/IdentityType.java 2008-10-15
10:59:42 UTC (rev 103)
@@ -22,33 +22,25 @@
package org.jboss.identity.api;
-import org.jboss.identity.exception.PolicyValidationException;
-
/**
- * Marker Interface representing
+ * Interface representing
* an object of the Identity Model
+ *
* @author Anil.Saldhana(a)redhat.com
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
* @since Jul 10, 2008
*/
public interface IdentityType
{
-
/**
* @return id of this identity object
*/
Object getId();
/**
- * <p>Return the name of the identity</p>
- * @return
+ * @return description
*/
- String getName();
+ String getDescription();
- /**
- * Validate configured Policies
- * @throws org.jboss.identity.exception.PolicyValidationException
- */
- void validatePolicy() throws PolicyValidationException;
}
\ No newline at end of file
Modified: trunk/identity-api/src/main/java/org/jboss/identity/api/PersistenceManager.java
===================================================================
---
trunk/identity-api/src/main/java/org/jboss/identity/api/PersistenceManager.java 2008-09-20
20:24:55 UTC (rev 102)
+++
trunk/identity-api/src/main/java/org/jboss/identity/api/PersistenceManager.java 2008-10-15
10:59:42 UTC (rev 103)
@@ -57,33 +57,47 @@
Group createGroup(String groupName, GroupType groupType)
throws IdentityException;
- /**
- * <p>Create a role in the realm</p>
- * @param roleName name of role
- * @param roleType Type of Role
- * @return
- */
- Role createRole(String roleName, RoleType roleType)
- throws IdentityException;
-
// Remove
/**
* Remove given identity
*
* @param identity
+ * @param force - if true all present relationships will be removed, if false any
present relationship will cause
+ * removal to fail
* @throws org.jboss.identity.exception.IdentityException
*/
- void removeIdentity(IdentityType identity) throws IdentityException;
+ void removeIdentity(Identity identity, boolean force) throws IdentityException;
-
+ /**
+ * Remove given group
+ *
+ * @param group
+ * @param force - if true all present relationships will be removed, if false any
present relationship will cause
+ * removal to fail
+ * @throws org.jboss.identity.exception.IdentityException
+ */
+ void removeGroup(Group group, boolean force) throws IdentityException;
+
+
+ // Refresh
+
+ /**
+ * Objects like Identity and Group can be simple pojos. This method should be used to
update DisplayName or Description
+ * values from the underlying store.
+ * @param it
+ * @throws IdentityException
+ */
+ void refreshIdentityType(IdentityType it) throws IdentityException;
+
+
// Search
/**
- * @return a number of stored identities with a given type
+ * @return a number of stored identities
* @throws org.jboss.identity.exception.IdentityException
*/
- int getIdentityTypeCount()
+ int getIdentityCount()
throws IdentityException;
/**
@@ -95,15 +109,6 @@
throws IdentityException;
/**
- * @param roleType
- * @return a number of stored roles with a given type
- * @throws org.jboss.identity.exception.IdentityException
- */
- int getRoleTypeCount(RoleType roleType)
- throws IdentityException;
-
-
- /**
* Find identity with a given name
*
* @param name
@@ -127,6 +132,7 @@
* are not supported in this store implementation, dedicated
* parameters will take no effect
*
+ * @param filterName can be null
* @param offset
* @param limit 0 means unlimited page size
* @param orderedByAttributeName can be null
@@ -134,7 +140,7 @@
* @return
* @throws org.jboss.identity.exception.IdentityException
*/
- Collection<Identity> findIdentity(int offset, int limit,
+ Collection<Identity> findIdentity(String filterName, int offset, int limit,
String orderedByAttributeName,
boolean ascending) throws IdentityException;
@@ -143,6 +149,7 @@
* orderedSearch operations
* are not supported in this store implementation, dedicated parameters will take no
effect
*
+ * @param filterName can be null
* @param attributes
* @param offset
* @param limit 0 means unlimited page size
@@ -151,68 +158,10 @@
* @return
* @throws org.jboss.identity.exception.IdentityException
*/
- Collection<Identity> findIdentity(Map<String, String[]> attributes,
+ Collection<Identity> findIdentity(String filterName, Map<String, String[]>
attributes,
int offset, int limit,
String orderedByAttributeName, boolean ascending)
throws IdentityException;
- // Search Roles
- /**
- * Find role with a given name
- *
- * @param name
- * @param roleType
- * @return
- * @throws org.jboss.identity.exception.IdentityException
- */
- Role findRole(String name, RoleType roleType) throws IdentityException;
-
- /**
- * Find role with a given id
- *
- * @param id
- * @return
- * @throws org.jboss.identity.exception.IdentityException
- */
- Role findRole(Object id) throws IdentityException;
-
- /**
- * Find role with a given type paginated and ordered.
- * If the paginatedSearch or orderedSearch operations
- * are not supported in this store implementation, dedicated
- * parameters will take no effect
- *
- * @param roleType
- * @param offset
- * @param limit 0 means unlimited page size
- * @param orderedByAttributeName can be null
- * @param ascending default true
- * @return
- * @throws org.jboss.identity.exception.IdentityException
- */
- Collection<Role> findRole(RoleType roleType,
- int offset, int limit,
- String orderedByAttributeName,
- boolean ascending) throws IdentityException;
-
- /**
- * Find identities with a given attributes values. If the paginatedSearch or
- * orderedSearch operations
- * are not supported in this store implementation, dedicated parameters will take no
effect
- *
- * @param roleType
- * @param attributes
- * @param offset
- * @param limit 0 means unlimited page size
- * @param orderedByAttributeName can be null
- * @param ascending default true
- * @return
- * @throws org.jboss.identity.exception.IdentityException
- */
- Collection<Identity> findRole(RoleType roleType,
- Map<String, String[]> attributes,
- int offset, int limit,
- String orderedByAttributeName, boolean ascending) throws
IdentityException;
-
// Search Groups
/**
@@ -241,6 +190,7 @@
* parameters will take no effect
*
* @param groupType
+ * @param filterName can be null
* @param offset
* @param limit 0 means unlimited page size
* @param orderedByAttributeName can be null
@@ -248,7 +198,7 @@
* @return
* @throws org.jboss.identity.exception.IdentityException
*/
- Collection<Group> findRole(GroupType groupType,
+ Collection<Group> findRole(GroupType groupType, String filterName,
int offset, int limit,
String orderedByAttributeName,
boolean ascending) throws IdentityException;
@@ -259,6 +209,7 @@
* are not supported in this store implementation, dedicated parameters will take no
effect
*
* @param groupType
+ * @param filterName can be null
* @param attributes
* @param offset
* @param limit 0 means unlimited page size
@@ -267,38 +218,9 @@
* @return
* @throws org.jboss.identity.exception.IdentityException
*/
- Collection<Group> findGroup(GroupType groupType,
+ Collection<Group> findGroup(GroupType groupType, String filterName,
Map<String, String[]> attributes,
int offset, int limit,
String orderedByAttributeName, boolean ascending) throws
IdentityException;
-
-
-
- // Search with relationship types
-
- /**
- * Find identites that have relationship with given identity. Relationships are
directional (from parent to child).
- * If the paginatedSearch or orderedSearch operations
- * are not supported in this store implementation, dedicated parameters will
- * take no effect
- *
- * @param identity
- * @param relationshipType
- * @param parent defines if given identity is parent or child side in the
- * relationship - default is true (parent)
- * @param offset
- * @param limit 0 means unlimited page size
- * @param orderedByAttributeName can be null
- * @param ascending default true
- * @return
- * @throws org.jboss.identity.exception.IdentityException
- */
- Collection<IdentityType> findRelatedIdentityTypes(IdentityType identity,
- RelationshipType relationshipType,
- boolean parent,
- int offset, int limit,
- String orderedByAttributeName,
- boolean ascending) throws
IdentityException;
-
}
Modified: trunk/identity-api/src/main/java/org/jboss/identity/api/RealmManager.java
===================================================================
--- trunk/identity-api/src/main/java/org/jboss/identity/api/RealmManager.java 2008-09-20
20:24:55 UTC (rev 102)
+++ trunk/identity-api/src/main/java/org/jboss/identity/api/RealmManager.java 2008-10-15
10:59:42 UTC (rev 103)
@@ -58,22 +58,20 @@
* <p>Associate a relationship between two realms</p>
* @param realmA
* @param realmB
- * @param relationshipType
* @throws org.jboss.identity.api.exception.PersistenceManagerNotFoundException PM not
set
* @throws org.jboss.identity.api.exception.SessionNotOpenException session is not
open
*/
- void associate(Realm realmA, Realm realmB, RelationshipType relationshipType)
+ void associate(Realm realmA, Realm realmB)
throws PersistenceManagerNotFoundException, SessionNotOpenException;
/**
* <p>Disassociate a relationship between two realms</p>
* @param realmA
* @param realmB
- * @param relationshipType
* @throws PersistenceManagerNotFoundException PM not set
* @throws SessionNotOpenException session is not open
*/
- void disassociate(Realm realmA, Realm realmB, RelationshipType relationshipType)
+ void disassociate(Realm realmA, Realm realmB)
throws PersistenceManagerNotFoundException,SessionNotOpenException;
/**
@@ -81,7 +79,7 @@
* @param toRealm
* @return returns a relationship type between this and given Realm.
*/
- RelationshipType getRelationship(Realm fromRealm, Realm toRealm);
+ boolean isAssosiated(Realm fromRealm, Realm toRealm);
/**
* <p>Return a realm</p>
Modified:
trunk/identity-api/src/main/java/org/jboss/identity/api/RelationshipManager.java
===================================================================
---
trunk/identity-api/src/main/java/org/jboss/identity/api/RelationshipManager.java 2008-09-20
20:24:55 UTC (rev 102)
+++
trunk/identity-api/src/main/java/org/jboss/identity/api/RelationshipManager.java 2008-10-15
10:59:42 UTC (rev 103)
@@ -24,8 +24,7 @@
import org.jboss.identity.exception.IdentityException;
-import java.util.List;
-import java.util.Set;
+import java.util.Collection;
/**
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
@@ -39,189 +38,143 @@
*/
IdentitySession getIdentitySession();
-
-
+ // Assignation
/**
- * <p>Associate a relationship between two groups</p>
- * @param groupA
- * @param groupB
- * @param relationshipType
+ * <p>Associate groups</p>
+ * @param parents
+ * @param members
* @throws org.jboss.identity.exception.IdentityException
*/
- void associate(Group groupA, Group groupB, RelationshipType relationshipType)
+ void associateGroups(Collection<Group> parents, Collection<Group>
members)
throws IdentityException;
/**
- * Associate a relationship between one group and a list of other groups
- * @param groupA
- * @param groupB a list of groups which are related to groupA
- * @param relationshipType
+ * <p>Associate groups</p>
+ * @param parent
+ * @param member
* @throws org.jboss.identity.exception.IdentityException
*/
- void associate(Group groupA, List<Group> groupB, RelationshipType
relationshipType)
+ void associateGroups(Group parent, Group member)
throws IdentityException;
-
-
/**
- * <p>Associate a role with an Identity</p>
- * @param identity
- * @param aRole
+ * <p>Associate identities to groups</p>
+ * @param parents
+ * @param members
* @throws org.jboss.identity.exception.IdentityException
*/
- void associate(Identity identity, Role aRole)
+ void associateIdentities(Collection<Group> parents, Collection<Identity>
members)
throws IdentityException;
/**
- * <p>Associate a list of roles with an Identity</p>
- * @param identity
- * @param aRoleList
+ * <p>Associate identities to groups</p>
+ * @param parents
+ * @param members
* @throws org.jboss.identity.exception.IdentityException
*/
- void associate(Identity identity, List<Role> aRoleList)
+ void associateIdentities(Group parents, Identity members)
throws IdentityException;
/**
- * <p>Associate a group with an identity</p>
- * @param identity
- * @param aGroup
+ * <p>Disassociate groups</p>
+ * @param parents
+ * @param members
* @throws org.jboss.identity.exception.IdentityException
*/
- void associate(Identity identity, Group aGroup)
+ void disassociateGroups(Collection<Group> parents, Collection<Group>
members)
throws IdentityException;
/**
- * <p>Associate a set of groups with an identity</p>
- * @param identity
- * @param aGroupSet
+ * <p>Disassociate identities from groups</p>
+ * @param parents
+ * @param members
* @throws org.jboss.identity.exception.IdentityException
*/
- void associate(Identity identity, Set<Group> aGroupSet)
+ void disassociateIdentities(Collection<Group> parents,
Collection<Identity> members)
throws IdentityException;
/**
- * <p>Disassociate a relationship between two groups</p>
- * @param groupA
- * @param groupB
- * @param relationshipType
+ * <p>Check if association is present </p>
+ * @param parents
+ * @param members
+ * @return
* @throws org.jboss.identity.exception.IdentityException
*/
- void disassociate(Group groupA, Group groupB, RelationshipType relationshipType)
+ <G extends IdentityType, I extends IdentityType> boolean
isAssociated(Collection<G> parents, Collection<I> members)
throws IdentityException;
- /**
- * Disassociate a relationship between one group and a list of other groups
- * @param groupA
- * @param groupB
- * @param relationshipType
- * @throws org.jboss.identity.exception.IdentityException
- */
- void disassociate(Group groupA, List<Group> groupB, RelationshipType
relationshipType)
- throws IdentityException;
+ // Resolve relationships
-
-
/**
- * <p>Disassociate a role with an Identity</p>
- * @param identity
- * @param aRole
- * @throws org.jboss.identity.exception.IdentityException
- */
- void disassociate(Identity identity, Role aRole)
- throws IdentityException;
-
- /**
- * <p>Disassociate a list of roles with an Identity</p>
- * @param identity
- * @param aRoleList
- * @throws org.jboss.identity.exception.IdentityException
- */
- void disassociate(Identity identity, List<Role> aRoleList)
- throws IdentityException;
-
- /**
- * <p>Disassociate a group with an identity</p>
- * @param identity
- * @param aGroup
- * @throws org.jboss.identity.exception.IdentityException
- */
- void disassociate(Identity identity, Group aGroup)
- throws IdentityException;
-
- /**
- * <p>Disassociate a set of groups with an identity</p>
- * @param identity
- * @param aGroupSet
- * @throws org.jboss.identity.api.exception.PersistenceManagerNotFoundException PM not
set
- * @throws org.jboss.identity.api.exception.SessionNotOpenException session is not
open
- */
- void disassociate(Identity identity, Set<Group> aGroupSet)
- throws IdentityException;
-
- /**
- * @param fromGroup
- * @param toGroup
- * @return returns a relationship type between this and given group.
- */
- RelationshipType getRelationship(Group fromGroup, Group toGroup);
-
- // Relationship - abstract methods
-
- /**
- * Create directional relationship of a given type between identities
+ * Find groups that are associated with given group.
+ * If the paginatedSearch or orderedSearch operations
+ * are not supported in this store implementation, dedicated parameters will
+ * take no effect. If 'parent' parameter is set to false, all parent group
will be returned. If parent parameter is
+ * set to true (default) and 'inherited' is set to true all nested subgroubs
will be returned.
*
- * @param fromIdentity
- * @param toIdentity
- * @param relationshipType
+ * @param group parent group
+ * @param groupType can be null
+ * @param parent defines if given identity is parent or child side in the
+ * relationship - default is true (parent)
+ * @param inherited if true also identities from subgroubs will be retreived. Matters
only when parent is set to true.
+ * Default is false
+ * @param offset
+ * @param limit 0 means unlimited page size
+ * @param orderedByAttributeName can be null
+ * @param ascending default true
+ * @return
* @throws org.jboss.identity.exception.IdentityException
*/
- <R extends RelationshipType> void createRelationship(IdentityType fromIdentity,
- IdentityType toIdentity,
- R relationshipType) throws IdentityException;
+ Collection<Group> findAssociatedGroups(Group group,
+ GroupType groupType,
+ boolean parent,
+ boolean inherited,
+ int offset, int limit,
+ String orderedByAttributeName,
+ boolean ascending) throws IdentityException;
/**
- * Remove relationship between identities. Relationships can be directional so
- * order of parameters matters
+ * Find all groups that given identity is associated with.
+ * If the paginatedSearch or orderedSearch operations
+ * are not supported in this store implementation, dedicated parameters will
+ * take no effect
*
- * @param fromIdentity
- * @param toIdentity
- * @param relationshipType
+ * @param identity child identity
+ * @param groupType can be null
+ * @param offset
+ * @param limit 0 means unlimited page size
+ * @param orderedByAttributeName can be null
+ * @param ascending default true
+ * @return
* @throws org.jboss.identity.exception.IdentityException
*/
- <R extends RelationshipType> void removeRelationship(IdentityType fromIdentity,
- IdentityType toIdentity,
- R relationshipType) throws IdentityException;
+ Collection<Group> findAssociatedGroups(Identity identity,
+ GroupType groupType,
+ int offset, int limit,
+ String orderedByAttributeName,
+ boolean ascending) throws IdentityException;
/**
- * Remove all relationships between identities. Direction of relationships
doesn't
- * matter - all active relationships
- * will be removed
+ * Find identities that have relationship with given parent group.
+ * If the paginatedSearch or orderedSearch operations
+ * are not supported in this store implementation, dedicated parameters will
+ * take no effect
*
- * @param identity1
- * @param identity2
- * @throws org.jboss.identity.exception.IdentityException
- */
- void removeRelationships(IdentityType identity1, IdentityType identity2)
- throws IdentityException;
-
- /**
- * Resolve relationship types between two identities. Relationships can be
directional
- * so order of parameters matters
- *
- * @param fromIdentity
- * @param toIdentity
+ * @param group parent group
+ * @param inherited if true also identities from subgroubs will be retreived. Default
is false
+ * @param offset
+ * @param limit 0 means unlimited page size
+ * @param orderedByAttributeName can be null
+ * @param ascending default true
* @return
* @throws org.jboss.identity.exception.IdentityException
*/
- Set<RelationshipType> resolveRelationships(IdentityType fromIdentity,
IdentityType toIdentity)
- throws IdentityException;
+ Collection<Identity> findAssociatedIdentities(Group group,
+ boolean inherited,
+ int offset, int limit,
+ String orderedByAttributeName,
+ boolean ascending) throws IdentityException;
- /**
- * @param fromRealm
- * @param toRealm
- * @return returns a relationship type between this and given Realm.
- */
- RelationshipType getRelationship(Realm fromRealm, Realm toRealm);
}
Deleted: trunk/identity-api/src/main/java/org/jboss/identity/api/RelationshipType.java
===================================================================
---
trunk/identity-api/src/main/java/org/jboss/identity/api/RelationshipType.java 2008-09-20
20:24:55 UTC (rev 102)
+++
trunk/identity-api/src/main/java/org/jboss/identity/api/RelationshipType.java 2008-10-15
10:59:42 UTC (rev 103)
@@ -1,34 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, 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.jboss.identity.api;
-
-/**
- * Defines a <b>relationship</b> between groups, domains etc
- * @author Anil.Saldhana(a)redhat.com
- * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
- * @since Jul 9, 2008
- */
-public interface RelationshipType
-{
- String getName();
-}
\ No newline at end of file
Modified: trunk/identity-api/src/main/java/org/jboss/identity/api/Role.java
===================================================================
--- trunk/identity-api/src/main/java/org/jboss/identity/api/Role.java 2008-09-20 20:24:55
UTC (rev 102)
+++ trunk/identity-api/src/main/java/org/jboss/identity/api/Role.java 2008-10-15 10:59:42
UTC (rev 103)
@@ -28,8 +28,12 @@
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
* @since Jun 30, 2008
*/
-public interface Role extends IdentityType
+public interface Role
{
+ /**
+ * @return id of this identity object
+ */
+ Object getId();
/**
* @return description
@@ -37,8 +41,18 @@
String getDescription();
/**
- * @return group type
+ * @return role type
*/
RoleType getRoleType();
+ /**
+ * @return identity participating in this role
+ */
+ Identity getIdentity();
+
+ /**
+ * @return group associated with this role
+ */
+ Group getGroup();
+
}
\ No newline at end of file
Added: trunk/identity-api/src/main/java/org/jboss/identity/api/RoleManager.java
===================================================================
--- trunk/identity-api/src/main/java/org/jboss/identity/api/RoleManager.java
(rev 0)
+++ trunk/identity-api/src/main/java/org/jboss/identity/api/RoleManager.java 2008-10-15
10:59:42 UTC (rev 103)
@@ -0,0 +1,193 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, 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.jboss.identity.api;
+
+import org.jboss.identity.exception.IdentityException;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public interface RoleManager
+{
+
+ /**
+ * @return Session associated with this object instance
+ */
+ IdentitySession getIdentitySession();
+
+ // RoleType
+
+ /**
+ * Create RoleType
+ * @param name
+ * @return
+ * @throws IdentityException
+ */
+ RoleType createRoleType(String name) throws IdentityException;
+
+ /**
+ * Remove RoleType
+ * @param name
+ * @throws IdentityException
+ */
+ void removeRoleType(String name) throws IdentityException;
+
+ /**
+ * Remove RoleType
+ * @param roleType
+ * @throws IdentityException
+ */
+ void removeRoleType(RoleType roleType) throws IdentityException;
+
+ /**
+ * Get RoleType
+ * @param name
+ * @return
+ * @throws IdentityException
+ */
+ RoleType getRoleType(String name) throws IdentityException;
+
+ /**
+ * Find all RoleType objects stored
+ * @param filterName
+ * @param offset
+ * @param limit
+ * @param orderedByName
+ * @param ascending
+ * @return
+ * @throws IdentityException
+ */
+ Collection<RoleType> findRoleTypes(String filterName,
+ int offset, int limit,
+ String orderedByName,
+ boolean ascending) throws IdentityException;
+
+
+ // Role
+
+
+ /**
+ * Create role
+ * @param roleType
+ * @param identity
+ * @param group
+ * @return
+ * @throws IdentityException
+ */
+ Role createRole(RoleType roleType, Identity identity, Group group) throws
IdentityException;
+
+ /**
+ * Remove Role
+ * @param roleType
+ * @param identity
+ * @param group
+ * @throws IdentityException
+ */
+ void removeRole(RoleType roleType, Identity identity, Group group) throws
IdentityException;
+
+ /**
+ * Remove Role
+ * @param role
+ * @throws IdentityException
+ */
+ void removeRole(Role role) throws IdentityException;
+
+ /**
+ * Check if Role is present
+ * @param identity
+ * @param group
+ * @param roleType
+ * @return
+ * @throws IdentityException
+ */
+ boolean hasRole(Identity identity, Group group, RoleType roleType) throws
IdentityException;
+
+ /**
+ * Find RoleType objects for roles associated with a given Identity and Group
+ * @param identity
+ * @param group
+ * @param offset
+ * @param limit
+ * @param orderedByName
+ * @param ascending
+ * @return
+ * @throws IdentityException
+ */
+ Collection<RoleType> findRoleTypes(Identity identity, Group group,
+ int offset, int limit,
+ boolean orderedByName,
+ boolean ascending) throws IdentityException;
+
+ /**
+ * Find RoleType objects for roles associated with a given Identity
+ * @param identity
+ * @param offset
+ * @param limit
+ * @param orderedByName
+ * @param ascending
+ * @return
+ * @throws IdentityException
+ */
+ Collection<RoleType> findIdentityRoleTypes(Identity identity,
+ int offset, int limit,
+ boolean orderedByName,
+ boolean ascending) throws IdentityException;
+
+ /**
+ * Find RoleType objects for roles associated with a given Group
+ * @param identity
+ * @param offset
+ * @param limit
+ * @param orderedByName
+ * @param ascending
+ * @return
+ * @throws IdentityException
+ */
+ Collection<RoleType> findGroupRoleTypes(Identity identity,
+ int offset, int limit,
+ boolean orderedByName,
+ boolean ascending) throws IdentityException;
+
+ /**
+ * Find Role objects with a given RoleType associated with a given IdentityType
+ * @param identityType
+ * @param roleType
+ * @param offset
+ * @param limit
+ * @param orderedByName
+ * @param ascending
+ * @return
+ * @throws IdentityException
+ */
+ <T extends IdentityType> Collection<Role> findRoles(T identityType,
+ RoleType roleType,
+ int offset, int limit,
+ boolean orderedByName,
+ boolean ascending) throws
IdentityException;
+
+}
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/hibernate/HibernateIdentityObject.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/hibernate/HibernateIdentityObject.java 2008-09-20
20:24:55 UTC (rev 102)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/hibernate/HibernateIdentityObject.java 2008-10-15
10:59:42 UTC (rev 103)
@@ -135,6 +135,15 @@
return null;
}
+ public Set<String> getAttribute(String name)
+ {
+ if (attributes.containsKey(name))
+ {
+ return Collections.unmodifiableSet((attributes.get(name)).getValues());
+ }
+ return new HashSet<String>();
+ }
+
public Map<String, Set<String>> getAttributes()
{
Map<String, Set<String>> map = new HashMap<String,
Set<String>>();
@@ -152,6 +161,20 @@
attributes.put(name, new HibernateIdentityObjectAttribute(name, new
HashSet<String>(values)));
}
+ public void addAttributeValues(String name, Set<String> values)
+ {
+ if (!attributes.containsKey(name))
+ {
+ setAttribute(name, values);
+ }
+ else
+ {
+ Set<String> mergedValues = new
HashSet<String>((attributes.get(name)).getValues());
+ mergedValues.addAll(values);
+ setAttribute(name, mergedValues);
+ }
+ }
+
public void setAttributes(Map<String, Set<String>> values)
{
Map<String, HibernateIdentityObjectAttribute> newAttrs= new
HashMap<String, HibernateIdentityObjectAttribute>();
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/hibernate/HibernateIdentityObjectRelationship.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/hibernate/HibernateIdentityObjectRelationship.java 2008-09-20
20:24:55 UTC (rev 102)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/hibernate/HibernateIdentityObjectRelationship.java 2008-10-15
10:59:42 UTC (rev 103)
@@ -31,6 +31,7 @@
import javax.persistence.NamedQuery;
import javax.persistence.JoinColumn;
import javax.persistence.UniqueConstraint;
+import javax.persistence.Column;
import org.jboss.identity.spi.model.IdentityObjectRelationship;
import org.jboss.identity.spi.model.IdentityObjectRelationshipType;
@@ -45,10 +46,14 @@
@NamedQuery(
name = "findIdentityObjectRelationshipsByType",
query = "select r from HibernateIdentityObjectRelationship r where r.type.name
like :typeName"
+ ),
+ @NamedQuery(
+ name = "findIdentityObjectRelationshipNamesByType",
+ query = "select r.name from HibernateIdentityObjectRelationship r where
r.type.name like :typeName"
)
})
@Entity
-@Table(name="identity_relationships", uniqueConstraints =
{@UniqueConstraint(columnNames = {"TYPE", "FROM_IDENTITY",
"TO_IDENTITY"})})
+@Table(name="identity_relationship", uniqueConstraints =
{@UniqueConstraint(columnNames = {"NAME", "TYPE",
"FROM_IDENTITY", "TO_IDENTITY"})})
public class HibernateIdentityObjectRelationship implements IdentityObjectRelationship
{
@@ -57,6 +62,10 @@
private Long id;
@ManyToOne
+ @JoinColumn(nullable = true, unique = false, name="NAME")
+ private HibernateIdentityObjectRelationshipName name;
+
+ @ManyToOne
@JoinColumn(nullable = false, name="TYPE")
private HibernateIdentityObjectRelationshipType type;
@@ -81,6 +90,16 @@
toIdentityObject.getToRelationships().add(this);
}
+ public HibernateIdentityObjectRelationship(HibernateIdentityObjectRelationshipType
type, HibernateIdentityObject fromIdentityObject, HibernateIdentityObject
toIdentityObject, HibernateIdentityObjectRelationshipName name)
+ {
+ this.type = type;
+ this.fromIdentityObject = fromIdentityObject;
+ fromIdentityObject.getFromRelationships().add(this);
+ this.toIdentityObject = toIdentityObject;
+ toIdentityObject.getToRelationships().add(this);
+ this.name = name;
+ }
+
public Long getId()
{
return id;
@@ -120,4 +139,18 @@
{
this.toIdentityObject = toIdentityObject;
}
+
+ public String getName()
+ {
+ if (name != null)
+ {
+ return name.getName();
+ }
+ return null;
+ }
+
+ public void setName(HibernateIdentityObjectRelationshipName name)
+ {
+ this.name = name;
+ }
}
Added:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/hibernate/HibernateIdentityObjectRelationshipName.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/hibernate/HibernateIdentityObjectRelationshipName.java
(rev 0)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/hibernate/HibernateIdentityObjectRelationshipName.java 2008-10-15
10:59:42 UTC (rev 103)
@@ -0,0 +1,88 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, 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.jboss.identity.impl.model.hibernate;
+
+import javax.persistence.Table;
+import javax.persistence.Entity;
+import javax.persistence.Column;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.Id;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+@Entity
+@Table(name="identity_relationship_name")
+@NamedQueries({
+ @NamedQuery(
+ name = "findIdentityObjectRelationshipNameByName",
+ query = "select rn from HibernateIdentityObjectRelationshipName rn where
rn.name like :name"
+ ),
+ @NamedQuery(
+ name = "findIdentityObjectRelationshipNames",
+ query = "select rn.name from HibernateIdentityObjectRelationshipName rn"
+ ),
+ @NamedQuery(
+ name = "findIdentityObjectRelationshipNamesForIdentityObject",
+ query = "select r.name.name from HibernateIdentityObjectRelationship r where
r.fromIdentityObject like :identityObject or r.toIdentityObject like
:identityObject"
+ )
+ })
+public class HibernateIdentityObjectRelationshipName
+{
+ @Id
+ Long id;
+
+ @Column(nullable = false, unique = true, name = "NAME")
+ String name;
+
+ public HibernateIdentityObjectRelationshipName()
+ {
+ }
+
+ public HibernateIdentityObjectRelationshipName(String name)
+ {
+ this.name = name;
+ }
+
+ public Long getId()
+ {
+ return id;
+ }
+
+ public void setId(Long id)
+ {
+ this.id = id;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+}
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/hibernate/HibernateIdentityObjectRelationshipType.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/hibernate/HibernateIdentityObjectRelationshipType.java 2008-09-20
20:24:55 UTC (rev 102)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/hibernate/HibernateIdentityObjectRelationshipType.java 2008-10-15
10:59:42 UTC (rev 103)
@@ -43,7 +43,7 @@
)
})
@Entity
-@Table(name = "identity_relationship_types")
+@Table(name = "identity_relationship_type")
public class HibernateIdentityObjectRelationshipType implements
IdentityObjectRelationshipType
{
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/hibernate/HibernateIdentityObjectType.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/hibernate/HibernateIdentityObjectType.java 2008-09-20
20:24:55 UTC (rev 102)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/hibernate/HibernateIdentityObjectType.java 2008-10-15
10:59:42 UTC (rev 103)
@@ -43,7 +43,7 @@
)
})
@Entity
-@Table(name = "identity_obj_types")
+@Table(name = "identity_obj_type")
public class HibernateIdentityObjectType implements IdentityObjectType
{
@Id
Added:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/ldap/LDAPIdentityObjectRelationshipImpl.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/ldap/LDAPIdentityObjectRelationshipImpl.java
(rev 0)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/ldap/LDAPIdentityObjectRelationshipImpl.java 2008-10-15
10:59:42 UTC (rev 103)
@@ -0,0 +1,79 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, 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.jboss.identity.impl.model.ldap;
+
+import org.jboss.identity.spi.model.IdentityObjectRelationship;
+import org.jboss.identity.spi.model.IdentityObjectRelationshipType;
+import org.jboss.identity.spi.model.IdentityObject;
+import org.jboss.identity.spi.model.IdentityObjectType;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class LDAPIdentityObjectRelationshipImpl implements IdentityObjectRelationship
+{
+
+ private final String name;
+
+ private final IdentityObject from;
+
+ private final IdentityObject to;
+
+ //TODO:
+ //private final IdentityObjectType type;
+
+ public LDAPIdentityObjectRelationshipImpl(String name, IdentityObject from,
IdentityObject to)
+ {
+ this.name = name;
+ this.from = from;
+ this.to = to;
+ }
+
+ public String getName()
+ {
+ return null;
+ }
+
+ public IdentityObjectRelationshipType getType()
+ {
+ //TODO
+ return new IdentityObjectRelationshipType()
+ {
+ public String getName()
+ {
+ return "";
+ }
+ };
+ }
+
+ public IdentityObject getFromIdentityObject()
+ {
+ return null;
+ }
+
+ public IdentityObject getToIdentityObject()
+ {
+ return null;
+ }
+}
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/hibernate/HibernateIdentityStoreImpl.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/hibernate/HibernateIdentityStoreImpl.java 2008-09-20
20:24:55 UTC (rev 102)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/hibernate/HibernateIdentityStoreImpl.java 2008-10-15
10:59:42 UTC (rev 103)
@@ -28,15 +28,21 @@
import org.jboss.identity.spi.model.IdentityObjectRelationshipType;
import org.jboss.identity.spi.model.IdentityObject;
import org.jboss.identity.spi.model.IdentityObjectType;
+import org.jboss.identity.spi.model.IdentityObjectRelationship;
+import org.jboss.identity.spi.exception.OperationNotSupportedException;
import org.jboss.identity.exception.IdentityException;
import org.jboss.identity.impl.model.hibernate.HibernateIdentityObject;
import org.jboss.identity.impl.model.hibernate.HibernateIdentityObjectRelationship;
import org.jboss.identity.impl.model.hibernate.HibernateIdentityObjectRelationshipType;
import org.jboss.identity.impl.model.hibernate.HibernateIdentityObjectType;
+import org.jboss.identity.impl.model.hibernate.HibernateIdentityObjectRelationshipName;
import org.jboss.identity.impl.NotYetImplementedException;
+import org.jboss.identity.impl.helper.Tools;
import org.jboss.identity.impl.store.FeaturesDescriptionImpl;
import org.jboss.identity.impl.store.hibernate.HibernateIdentityStoreInvocationContext;
import org.hibernate.ejb.HibernateEntityManager;
+import org.hibernate.criterion.Restrictions;
+import org.hibernate.HibernateException;
import javax.persistence.NoResultException;
import javax.persistence.Query;
@@ -47,6 +53,8 @@
import java.util.LinkedList;
import java.util.Iterator;
import java.util.HashSet;
+import java.util.Collections;
+import java.util.HashMap;
import java.io.IOException;
/**
@@ -55,6 +63,9 @@
*/
public class HibernateIdentityStoreImpl implements IdentityStore
{
+
+ //TODO: logging
+
private final String QUERY_RELATIONSHIP_BY_FROM_TO =
"select r from HibernateIdentityObjectRelationship r where
r.fromIdentityObject like :fromIO and " +
"r.toIdentityObject like :toIO";
@@ -154,13 +165,12 @@
public void removeIdentityObject(IdentityStoreInvocationContext ctx, IdentityObject
identity) throws IdentityException
{
- checkIOInstance(identity);
+ HibernateIdentityObject hibernateObject = safeGet(ctx, identity);
//TODO: handle cleanup of present relationships
try
{
- HibernateIdentityObject hibernateObject = getHibernateIdentityObject(ctx,
identity);
getHibernateEntityManager(ctx).remove(hibernateObject);
}
catch (Exception e)
@@ -241,17 +251,21 @@
return hibernateObject;
}
- public Collection<IdentityObject>
findIdentityObject(IdentityStoreInvocationContext ctx, IdentityObjectType identityType,
int offset, int limit, boolean orderedByName, boolean ascending) throws IdentityException
+ public Collection<IdentityObject>
findIdentityObject(IdentityStoreInvocationContext ctx, IdentityObjectType identityType,
String nameFilter, int offset, int limit, boolean orderedByName, boolean ascending) throws
IdentityException
{
+
+ //TODO:OrderBy
+ //TODO:Improve pagination
+
checkIOType(identityType);
HibernateIdentityObjectType hibernateType = getHibernateIdentityObjectType(ctx,
identityType);
- List<IdentityObject> results = new LinkedList<IdentityObject>();
+ List<IdentityObject> results;
try
{
- //TODO:OrderBy
+
Query q =
getHibernateEntityManager(ctx).createNamedQuery("findIdentityObjectsByType")
.setParameter("typeName", hibernateType.getName())
.setFirstResult(offset);
@@ -280,25 +294,89 @@
public Collection<IdentityObject>
findIdentityObject(IdentityStoreInvocationContext ctx, IdentityObject identity,
IdentityObjectRelationshipType relationshipType, boolean parent, int offset, int limit,
boolean orderByName, boolean ascending) throws IdentityException
{
- //TODO: NYI
- throw new NotYetImplementedException();
+ //TODO:test
+ //TODO:Improve pagination
+
+ HibernateIdentityObject hibernateObject = safeGet(ctx, identity);
+
+ List<IdentityObject> results = null;
+
+ try
+ {
+ org.hibernate.Query q = null;
+
+ StringBuilder hqlString = new StringBuilder("");
+
+ if (orderByName)
+ {
+ hqlString.append(" orderBy ior.toIdentityObject.name");
+ if (ascending)
+ {
+ hqlString.append(" asc");
+ }
+ }
+
+ if (parent)
+ {
+ hqlString.append("select ior.toIdentityObject from
HibernateIdentityObjectRelationship ior where ior.type.name like :relType and
ior.fromIdentityObject like :identity");
+
+ if (orderByName)
+ {
+ hqlString.append(" orderBy ior.toIdentityObject.name");
+ if (ascending)
+ {
+ hqlString.append(" asc");
+ }
+ }
+ }
+ else
+ {
+ hqlString.append("select ior.fromIdentityObject from
HibernateIdentityObjectRelationship ior where ior.type.name like :relType and
ior.toIdentityObject like :identity");
+
+ if (orderByName)
+ {
+ hqlString.append(" orderBy ior.toIdentityObject.name");
+ if (ascending)
+ {
+ hqlString.append(" asc");
+ }
+ }
+ }
+
+ q =
getHibernateEntityManager(ctx).getSession().createQuery(hqlString.toString())
+ .setParameter("relType", relationshipType)
+ .setParameter("identity",hibernateObject)
+ .setFirstResult(offset);
+
+ if (limit > 0)
+ {
+ q.setMaxResults(limit);
+ }
+
+ results = (List<IdentityObject>)q.list();
+
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("Cannot find IdentityObjects", e);
+ }
+
+ return results;
}
- public void createRelationship(IdentityStoreInvocationContext ctx, IdentityObject
fromIdentity, IdentityObject toIdentity, IdentityObjectRelationshipType relationshipType)
throws IdentityException
+ public void createRelationship(IdentityStoreInvocationContext ctx, IdentityObject
fromIdentity, IdentityObject toIdentity,
+ IdentityObjectRelationshipType relationshipType,
+ String name, boolean createNames) throws
IdentityException
{
- //TODO: NYI
- //throw new NotYetImplementedException();
+ //TODO: name
if (relationshipType == null)
{
throw new IllegalArgumentException("RelationshipType is null");
}
- checkIOInstance(fromIdentity);
- checkIOInstance(toIdentity);
-
- HibernateIdentityObject fromIO = getHibernateIdentityObject(ctx, fromIdentity);
- HibernateIdentityObject toIO = getHibernateIdentityObject(ctx, toIdentity);
+ HibernateIdentityObject fromIO = safeGet(ctx, fromIdentity);
+ HibernateIdentityObject toIO = safeGet(ctx, toIdentity);
HibernateIdentityObjectRelationshipType type =
getHibernateIdentityObjectRelationshipType(ctx, relationshipType);
getSupportedFeatures().isRelationshipTypeSupported(fromIO.getIdentityType(),
toIO.getIdentityType(), relationshipType);
@@ -321,19 +399,17 @@
}
- public void removeRelationship(IdentityStoreInvocationContext ctx, IdentityObject
fromIdentity, IdentityObject toIdentity, IdentityObjectRelationshipType relationshipType)
throws IdentityException
+ public void removeRelationship(IdentityStoreInvocationContext ctx, IdentityObject
fromIdentity, IdentityObject toIdentity, IdentityObjectRelationshipType relationshipType,
String name) throws IdentityException
{
+ //TODO: name
if (relationshipType == null)
{
throw new IllegalArgumentException("RelationshipType is null");
}
- checkIOInstance(fromIdentity);
- checkIOInstance(toIdentity);
-
- HibernateIdentityObject fromIO = getHibernateIdentityObject(ctx, fromIdentity);
- HibernateIdentityObject toIO = getHibernateIdentityObject(ctx, toIdentity);
+ HibernateIdentityObject fromIO = safeGet(ctx, fromIdentity);
+ HibernateIdentityObject toIO = safeGet(ctx, toIdentity);
HibernateIdentityObjectRelationshipType type =
getHibernateIdentityObjectRelationshipType(ctx, relationshipType);
getSupportedFeatures().isRelationshipTypeSupported(fromIO.getIdentityType(),
toIO.getIdentityType(), relationshipType);
@@ -359,13 +435,12 @@
}
- public void removeRelationships(IdentityStoreInvocationContext ctx, IdentityObject
identity1, IdentityObject identity2) throws IdentityException
+ public void removeRelationships(IdentityStoreInvocationContext ctx, IdentityObject
identity1, IdentityObject identity2, boolean named) throws IdentityException
{
- checkIOInstance(identity1);
- checkIOInstance(identity2);
+ //TODO: named
- HibernateIdentityObject hio1 = getHibernateIdentityObject(ctx, identity1);
- HibernateIdentityObject hio2 = getHibernateIdentityObject(ctx, identity2);
+ HibernateIdentityObject hio1 = safeGet(ctx, identity1);
+ HibernateIdentityObject hio2 = safeGet(ctx, identity2);
org.hibernate.Query query =
getHibernateEntityManager(ctx).getSession().createQuery(QUERY_RELATIONSHIP_BY_IDENTITIES)
.setParameter("IO1", hio1)
@@ -382,13 +457,11 @@
}
}
- public Set<IdentityObjectRelationshipType>
resolveRelationships(IdentityStoreInvocationContext ctx, IdentityObject fromIdentity,
IdentityObject toIdentity) throws IdentityException
+ public Set<IdentityObjectRelationship>
resolveRelationships(IdentityStoreInvocationContext ctx, IdentityObject fromIdentity,
IdentityObject toIdentity) throws IdentityException
{
- checkIOInstance(fromIdentity);
- checkIOInstance(toIdentity);
- HibernateIdentityObject hio1 = getHibernateIdentityObject(ctx, fromIdentity);
- HibernateIdentityObject hio2 = getHibernateIdentityObject(ctx, toIdentity);
+ HibernateIdentityObject hio1 = safeGet(ctx, fromIdentity);
+ HibernateIdentityObject hio2 = safeGet(ctx, toIdentity);
org.hibernate.Query query =
getHibernateEntityManager(ctx).getSession().createQuery(QUERY_RELATIONSHIP_BY_FROM_TO)
.setParameter("fromIO", hio1)
@@ -396,31 +469,145 @@
List<HibernateIdentityObjectRelationship> results = query.list();
- Set<IdentityObjectRelationshipType> types = new
HashSet<IdentityObjectRelationshipType>();
+ return new HashSet<IdentityObjectRelationship>(results);
+ }
- for (Iterator<HibernateIdentityObjectRelationship> iterator =
results.iterator(); iterator.hasNext();)
+ public String createRelationshipName(IdentityStoreInvocationContext ctx, String name)
throws IdentityException, OperationNotSupportedException
+ {
+ if (name == null)
{
- HibernateIdentityObjectRelationship relationship = iterator.next();
- types.add(relationship.getType());
+ throw new IllegalArgumentException("name is null");
}
- return types;
+
+ try
+ {
+ HibernateIdentityObjectRelationshipName hiorn =
(HibernateIdentityObjectRelationshipName)getHibernateEntityManager(ctx).getSession().createCriteria(HibernateIdentityObjectRelationshipName.class)
+ .add(Restrictions.eq("name", name)).uniqueResult();
+
+ if (hiorn != null)
+ {
+ throw new IdentityException("Relationship name already exists");
+ }
+
+ hiorn = new HibernateIdentityObjectRelationshipName(name);
+ getHibernateEntityManager(ctx).persist(hiorn);
+
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("Cannot create new relationship name: " +
name, e);
+ }
+
+
+ return name;
}
+ public String removeRelationshipName(IdentityStoreInvocationContext ctx, String name)
throws IdentityException, OperationNotSupportedException
+ {
+ if (name == null)
+ {
+ throw new IllegalArgumentException("name is null");
+ }
+
+ try
+ {
+ HibernateIdentityObjectRelationshipName hiorn =
(HibernateIdentityObjectRelationshipName)getHibernateEntityManager(ctx).getSession().createCriteria(HibernateIdentityObjectRelationshipName.class)
+ .add(Restrictions.eq("name", name)).uniqueResult();
+
+ if (hiorn == null)
+ {
+ throw new IdentityException("Relationship name doesn't
exist");
+ }
+
+ getHibernateEntityManager(ctx).remove(hiorn);
+
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("Cannot create new relationship name: " +
name, e);
+ }
+
+
+ return name;
+ }
+
+ public Set<String> getRelationshipNames(IdentityStoreInvocationContext ctx, int
offset, int limit, boolean orderByName, boolean ascending) throws IdentityException,
OperationNotSupportedException
+ {
+
+ //TODO: orderByName
+
+ Set<String> names = new HashSet<String>();
+
+ try
+ {
+ Query q =
getHibernateEntityManager(ctx).createNamedQuery("findIdentityObjectRelationshipNames")
+ .setFirstResult(offset);
+
+ if(limit > 0)
+ {
+ q.setMaxResults(limit);
+ }
+
+ List<String> results = (List<String>)q.getResultList();
+
+ names = new HashSet<String>(results);
+
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("Cannot get relationship names. ", e);
+ }
+
+ return names;
+ }
+
+ public Set<String> getRelationshipNames(IdentityStoreInvocationContext ctx,
IdentityObject identity, int offset, int limit, boolean orderByName, boolean ascending)
throws IdentityException, OperationNotSupportedException
+ {
+ //TODO: NYI
+
+ //TODO: orderByName
+
+ Set<String> names;
+
+ HibernateIdentityObject hibernateObject = safeGet(ctx, identity);
+
+ try
+ {
+ Query q =
getHibernateEntityManager(ctx).createNamedQuery("findIdentityObjectRelationshipNamesForIdentityObject")
+ .setParameter("identityObject", hibernateObject)
+ .setFirstResult(offset);
+
+ if(limit > 0)
+ {
+ q.setMaxResults(limit);
+ }
+
+ List<String> results = (List<String>)q.getResultList();
+
+ names = new HashSet<String>(results);
+
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("Cannot get relationship names. ", e);
+ }
+
+ return names;
+ }
+
// Attribute store
public <T extends IdentityObjectType> Set<String>
getSupportedAttributeNames(IdentityStoreInvocationContext ctx, T identityType) throws
IdentityException
{
//TODO: NYI
- return null;
+ throw new NotYetImplementedException();
}
public Map<String, Set<String>>
getAttributes(IdentityStoreInvocationContext ctx, IdentityObject identity) throws
IdentityException
{
- checkIOInstance(identity);
+ HibernateIdentityObject hibernateObject = safeGet(ctx, identity);
- HibernateIdentityObject hibernateObject = getHibernateIdentityObject(ctx,
identity);
-
return hibernateObject.getAttributes();
}
@@ -428,48 +615,45 @@
public void updateAttributes(IdentityStoreInvocationContext ctx, IdentityObject
identity, Map<String, Set<String>> attributes) throws IdentityException
{
- checkIOInstance(identity);
-
if (attributes == null)
{
throw new IllegalArgumentException("attributes are null");
}
- HibernateIdentityObject hibernateObject = getHibernateIdentityObject(ctx,
identity);
+ HibernateIdentityObject hibernateObject = safeGet(ctx, identity);
- hibernateObject.setAttributes(attributes);
+ for (String name : attributes.keySet())
+ {
+ hibernateObject.setAttribute(name, attributes.get(name));
+ }
}
public void addAttributes(IdentityStoreInvocationContext ctx, IdentityObject identity,
Map<String, Set<String>> attributes) throws IdentityException
{
- checkIOInstance(identity);
-
if (attributes == null)
{
throw new IllegalArgumentException("attributes are null");
}
- HibernateIdentityObject hibernateObject = getHibernateIdentityObject(ctx,
identity);
+ HibernateIdentityObject hibernateObject = safeGet(ctx, identity);
for (String name : attributes.keySet())
{
- hibernateObject.setAttribute(name, attributes.get(name));
+ hibernateObject.addAttributeValues(name, attributes.get(name));
}
}
public void removeAttributes(IdentityStoreInvocationContext ctx, IdentityObject
identity, Set<String> attributes) throws IdentityException
{
- checkIOInstance(identity);
-
if (attributes == null)
{
throw new IllegalArgumentException("attributes are null");
}
- HibernateIdentityObject hibernateObject = getHibernateIdentityObject(ctx,
identity);
+ HibernateIdentityObject hibernateObject = safeGet(ctx, identity);
for (String attr : attributes)
{
@@ -477,6 +661,24 @@
}
}
+ public boolean hasPasswordAttribute(IdentityStoreInvocationContext ctx,
IdentityObjectType type) throws IdentityException
+ {
+ //TODO: NYI
+ throw new NotYetImplementedException();
+ }
+
+ public boolean validatePassword(IdentityStoreInvocationContext ctx, IdentityObject
identityObject, String password) throws IdentityException
+ {
+ //TODO: NYI
+ throw new NotYetImplementedException();
+ }
+
+ public void updatePassword(IdentityStoreInvocationContext ctx, IdentityObject
identityObject, String password) throws IdentityException
+ {
+ //TODO: NYI
+ throw new NotYetImplementedException();
+ }
+
// Internal
public void addIdentityObjectType(IdentityStoreInvocationContext ctx,
IdentityObjectType type) throws IdentityException
@@ -510,13 +712,23 @@
throw new IllegalArgumentException("IdentityObject is null");
}
- if (!(io instanceof HibernateIdentityObject))
+
+ }
+
+ private HibernateIdentityObject safeGet(IdentityStoreInvocationContext ctx,
IdentityObject io) throws IdentityException
+ {
+ checkIOInstance(io);
+
+ if (io instanceof HibernateIdentityObject)
{
- throw new IllegalArgumentException("IdentityObject type not supported by
this " +
- "IdentityStore implementation: " + io.getClass().getName());
+ return (HibernateIdentityObject)io;
}
+
+ return getHibernateIdentityObject(ctx, io);
+
}
+
private void checkIOType(IdentityObjectType iot) throws IdentityException
{
if (iot == null)
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/ldap/LDAPIdentityObjectTypeConfiguration.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/ldap/LDAPIdentityObjectTypeConfiguration.java 2008-09-20
20:24:55 UTC (rev 102)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/ldap/LDAPIdentityObjectTypeConfiguration.java 2008-10-15
10:59:42 UTC (rev 103)
@@ -50,5 +50,7 @@
boolean allowEmptyMemberships();
- String getAttributeName(String identityAttribute);
+ String getAttributeMapping(String identityAttribute);
+
+ Set<String> getMappedAttributesNames();
}
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/ldap/LDAPIdentityStore.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/ldap/LDAPIdentityStore.java 2008-09-20
20:24:55 UTC (rev 102)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/ldap/LDAPIdentityStore.java 2008-10-15
10:59:42 UTC (rev 103)
@@ -28,20 +28,25 @@
import org.jboss.identity.spi.model.IdentityObject;
import org.jboss.identity.spi.model.IdentityObjectType;
import org.jboss.identity.spi.model.IdentityObjectRelationshipType;
+import org.jboss.identity.spi.model.IdentityObjectRelationship;
+import org.jboss.identity.spi.exception.OperationNotSupportedException;
import org.jboss.identity.exception.IdentityException;
import org.jboss.identity.impl.store.FeaturesDescriptionImpl;
import org.jboss.identity.impl.model.ldap.LDAPIdentityObjectImpl;
+import org.jboss.identity.impl.model.ldap.LDAPIdentityObjectRelationshipImpl;
import org.jboss.identity.impl.helper.Tools;
import org.jboss.identity.impl.helper.LDAPTools;
import org.jboss.identity.impl.NotYetImplementedException;
import javax.naming.ldap.LdapContext;
+import javax.naming.ldap.LdapName;
import javax.naming.directory.Attributes;
import javax.naming.directory.Attribute;
import javax.naming.directory.SearchControls;
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.SearchResult;
+import javax.naming.directory.DirContext;
import javax.naming.NamingException;
import javax.naming.NamingEnumeration;
import javax.naming.Context;
@@ -53,6 +58,11 @@
import java.util.LinkedList;
import java.util.Iterator;
import java.util.NoSuchElementException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Arrays;
+import java.util.logging.Logger;
+import java.util.logging.Level;
/**
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
@@ -61,13 +71,18 @@
public class LDAPIdentityStore implements IdentityStore
{
+ private static Logger log = Logger.getLogger(LDAPIdentityStore.class.getName());
+
+ private final String id;
+
private FeaturesDescription supportedFeatures;
- public LDAPIdentityStore()
+ public LDAPIdentityStore(String id)
{
// For now just dummy impl
//TODO: initialize with configuration
supportedFeatures = new FeaturesDescriptionImpl();
+ this.id = id;
}
public void bootstrap() throws IOException
@@ -77,7 +92,7 @@
public String getId()
{
- return null;
+ return id;
}
public FeaturesDescription getSupportedFeatures()
@@ -91,13 +106,14 @@
{
throw new IdentityException("Name cannot be null");
}
- if (type == null)
+
+ checkIOType(type);
+
+ if (log.isLoggable(Level.FINER))
{
- throw new IdentityException("IdentityObjectType cannot be null");
+ log.finer(toString() + ".createIdentityObject with name: " + name +
" and type: " + type.getName());
}
- checkIOType(type);
-
LdapContext ldapContext = getLDAPContext(invocationCtx);
try
@@ -117,7 +133,6 @@
{
String attributeName = (String)it1.next();
- //log.debug("adding attribute: " + attributeName);
Attribute attr = new BasicAttribute(attributeName);
String[] attributeValues = attributesToAdd.get(attributeName);
@@ -126,23 +141,23 @@
for (String attrValue : attributeValues)
{
- //log.debug("adding attribute value: " + attrValue);
attr.add(attrValue);
}
attrs.put(attr);
}
- String validName = LDAPTools.encodeRfc2253Name(name);
+ // Make it RFC 2253 compliant
+ LdapName validLDAPName = new LdapName(getTypeConfiguration(invocationCtx,
type).getIdAttributeName().concat("=").concat(name));
- String rdn = getTypeConfiguration(invocationCtx,
type).getIdAttributeName().concat("=").concat(validName);
+ //String rdn = getTypeConfiguration(invocationCtx,
type).getIdAttributeName().concat("=").concat(validLDAPName.toString());
- //log.debug("creating ldap entry for: " + rdn + "; " +
attrs);
- ctx.createSubcontext(rdn, attrs);
+ log.finer("creating ldap entry for: " + validLDAPName + "; "
+ attrs);
+ ctx.createSubcontext(validLDAPName, attrs);
}
catch (Exception e)
{
- throw new IdentityException("Failed to create user", e);
+ throw new IdentityException("Failed to create identity object", e);
}
finally
{
@@ -162,14 +177,15 @@
public void removeIdentityObject(IdentityStoreInvocationContext invocationCtx,
IdentityObject identity) throws IdentityException
{
- //LDAPUserImpl ldapu = (LDAPUserImpl)findUserById(id);
+ if (log.isLoggable(Level.FINER))
+ {
+ log.finer(toString() + ".removeIdentityObject: " + identity);
+ }
- checkIOInstance(identity);
+ LDAPIdentityObjectImpl ldapIdentity = getSafeLDAPIO(invocationCtx, identity);
- // as this is valid LDAPIdentityObjectImpl DN is obtained from the Id
+ String dn = ldapIdentity.getDn();
- String dn = ((LDAPIdentityObjectImpl)identity).getDn();
-
if (dn == null)
{
throw new IdentityException("Cannot obtain DN of identity");
@@ -179,7 +195,7 @@
try
{
- //log.debug("removing entry: " + dn);
+ log.finer("removing entry: " + dn);
ldapContext.unbind(dn);
}
catch (Exception e)
@@ -202,9 +218,16 @@
public int getIdentityObjectsCount(IdentityStoreInvocationContext ctx,
IdentityObjectType identityType) throws IdentityException
{
+ if (log.isLoggable(Level.FINER))
+ {
+ log.finer(toString() + ".getIdentityObjectsCount for type: " +
identityType);
+ }
+
+ checkIOType(identityType);
+
try
{
- String filter = getTypeConfiguration(ctx,identityType).getEntrySearchFilter();
+ String filter = getTypeConfiguration(ctx, identityType).getEntrySearchFilter();
if (filter != null && filter.length() > 0)
{
@@ -214,11 +237,11 @@
else
{
//search all entries
- filter =
"(".concat(getTypeConfiguration(ctx,identityType).getIdAttributeName()).concat("=").concat("*").concat(")");
+ filter = "(".concat(getTypeConfiguration(ctx,
identityType).getIdAttributeName()).concat("=").concat("*").concat(")");
}
//log.debug("Search filter: " + filter);
- List sr = searchIdentityObjects(ctx, identityType, filter, null);
+ List sr = searchIdentityObjects(ctx, identityType, filter, null, new
String[]{getTypeConfiguration(ctx, identityType).getIdAttributeName()});
return sr.size();
@@ -236,6 +259,12 @@
public IdentityObject findIdentityObject(IdentityStoreInvocationContext invocationCtx,
String name, IdentityObjectType type) throws IdentityException
{
+
+ if (log.isLoggable(Level.FINER))
+ {
+ log.finer(toString() + ".findIdentityObject with name: " + name +
"; and type: " + type);
+ }
+
Context ctx = null;
checkIOType(type);
try
@@ -247,21 +276,19 @@
throw new IdentityException("Identity object name canot be null");
}
- String filter =
getTypeConfiguration(invocationCtx,type).getEntrySearchFilter();
+ String filter = getTypeConfiguration(invocationCtx,
type).getEntrySearchFilter();
List sr = null;
if (filter != null && filter.length() > 0)
{
- //* chars are escaped in filterArgs so we must replace it manually
- filter = filter.replaceAll("\\{0\\}", "*");
Object[] filterArgs = {name};
- sr = searchIdentityObjects(invocationCtx, type, filter, filterArgs);
+ sr = searchIdentityObjects(invocationCtx, type, filter, filterArgs, new
String[]{getTypeConfiguration(invocationCtx, type).getIdAttributeName()});
}
else
{
//search all entries
filter = "(".concat(getTypeConfiguration(invocationCtx,
type).getIdAttributeName()).concat("=").concat(name).concat(")");
- sr = searchIdentityObjects(invocationCtx, type, filter, null);
+ sr = searchIdentityObjects(invocationCtx, type, filter, null, new
String[]{getTypeConfiguration(invocationCtx, type).getIdAttributeName()});
}
//log.debug("Search filter: " + filter);
@@ -307,6 +334,11 @@
public IdentityObject findIdentityObject(IdentityStoreInvocationContext ctx, Object
id) throws IdentityException
{
+ if (log.isLoggable(Level.FINER))
+ {
+ log.finer(toString() + ".findIdentityObject with id: " + id);
+ }
+
LdapContext ldapContext = getLDAPContext(ctx);
try
@@ -327,7 +359,7 @@
//Recognize the type by ctx DN
- IdentityObjectType[] possibleTypes =
getConfiguration(ctx).getConfiguredTypes();
+ IdentityObjectType[] possibleTypes =
getConfiguration(ctx).getConfiguredTypes();
for (IdentityObjectType possibleType : possibleTypes)
{
@@ -386,78 +418,843 @@
return null;
}
- public Collection<IdentityObject>
findIdentityObject(IdentityStoreInvocationContext invocationCtx, IdentityObjectType
identityType, int offset, int limit, boolean orderByName, boolean ascending) throws
IdentityException
+ public Collection<IdentityObject>
findIdentityObject(IdentityStoreInvocationContext invocationCtx, IdentityObjectType type,
String nameFilter, int offset, int limit, boolean orderByName, boolean ascending) throws
IdentityException
{
- //TODO: NYI
- throw new NotYetImplementedException();
+ if (log.isLoggable(Level.FINER))
+ {
+ log.finer(toString() + ".findIdentityObject with type: " + type
+ + "; nameFilter: " + nameFilter
+ + "; offset: " + offset
+ + "; limit: " + limit
+ + "; orderByName: " + orderByName
+ + "; ascending: " + ascending
+ );
+ }
+
+ //TODO: handle paged results and sort
+
+ Context ctx = getLDAPContext(invocationCtx);
+ checkIOType(type);
+
+ List<IdentityObject> objects = new LinkedList<IdentityObject>();
+
+ try
+ {
+ String filter = getTypeConfiguration(invocationCtx,
type).getEntrySearchFilter();
+ List<SearchResult> sr = null;
+
+ if (filter != null && filter.length() > 0)
+ {
+
+ Object[] filterArgs = {nameFilter};
+ sr = searchIdentityObjects(invocationCtx, type, filter, filterArgs, new
String[]{getTypeConfiguration(invocationCtx, type).getIdAttributeName()});
+ }
+ else
+ {
+ filter = "(".concat(getTypeConfiguration(invocationCtx,
type).getIdAttributeName()).concat("=").concat(nameFilter).concat(")");
+ sr = searchIdentityObjects(invocationCtx, type, filter, null, new
String[]{getTypeConfiguration(invocationCtx, type).getIdAttributeName()});
+ }
+
+
+ for (SearchResult res : sr)
+ {
+ ctx = (Context)res.getObject();
+ String dn = ctx.getNameInNamespace();
+ objects.add(createIdentityObjectInstance(invocationCtx, type,
res.getAttributes(), dn));
+ }
+
+ ctx.close();
+ return objects;
+
+ }
+ catch (NoSuchElementException e)
+ {
+ //log.debug("No identity object found with name: " + name, e);
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("IdentityObject search failed.", e);
+ }
+ finally
+ {
+ try
+ {
+ if (ctx != null)
+ {
+ ctx.close();
+ }
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Failed to close LDAP connection", e);
+ }
+ }
+
+ return objects;
}
- public Collection<IdentityObject>
findIdentityObject(IdentityStoreInvocationContext invocationCtx, IdentityObjectType
identityType, Map<String, String[]> attributes, int offset, int limit, boolean
orderByName, boolean ascending) throws IdentityException
+ public Collection<IdentityObject>
findIdentityObject(IdentityStoreInvocationContext invocationCtx, IdentityObjectType type,
Map<String, String[]> attributes, int offset, int limit, boolean orderByName,
boolean ascending) throws IdentityException
{
- //TODO: NYI
- throw new NotYetImplementedException();
+ //TODO: handle paged results and sort
+
+ if (log.isLoggable(Level.FINER))
+ {
+ log.finer(toString() + ".findIdentityObject with type: " + type
+ + "; attributes: " + attributes
+ + "; offset: " + offset
+ + "; limit: " + limit
+ + "; orderByName: " + orderByName
+ + "; ascending: " + ascending
+ );
+ }
+
+ Context ctx = getLDAPContext(invocationCtx);
+ checkIOType(type);
+
+ List<IdentityObject> objects = new LinkedList<IdentityObject>();
+
+ try
+ {
+ String filter = getTypeConfiguration(invocationCtx,
type).getEntrySearchFilter();
+ List<SearchResult> sr = null;
+
+ //TODO: if no search filter is present just use search method with
matchingAttributes from DirContext instead of
+ //TODO: concatenating filter
+
+ StringBuilder af = new StringBuilder("(&");
+
+ for (Map.Entry<String, String[]> stringEntry : attributes.entrySet())
+ {
+ for (String value : stringEntry.getValue())
+ {
+ af.append("(")
+ .append(stringEntry.getKey())
+ .append("=")
+ .append(value)
+ .append(")");
+ }
+ }
+
+ af.append(")");
+
+ if (filter != null && filter.length() > 0)
+ {
+ // chars are escaped in filterArgs so we must replace it manually
+ filter = filter.replaceAll("\\{0\\}", "*");
+
+ Object[] filterArgs = {};
+ sr = searchIdentityObjects(invocationCtx, type, "&(" + filter +
")" + af.toString(), filterArgs, new
String[]{getTypeConfiguration(invocationCtx, type).getIdAttributeName()});
+ }
+ else
+ {
+ filter = "(".concat(getTypeConfiguration(invocationCtx,
type).getIdAttributeName()).concat("=").concat("*").concat(")");
+ sr = searchIdentityObjects(invocationCtx, type, "&(" + filter +
")" + af.toString(), null, new String[]{getTypeConfiguration(invocationCtx,
type).getIdAttributeName()});
+ }
+
+
+ for (SearchResult res : sr)
+ {
+ ctx = (Context)res.getObject();
+ String dn = ctx.getNameInNamespace();
+ objects.add(createIdentityObjectInstance(invocationCtx, type,
res.getAttributes(), dn));
+ }
+
+ ctx.close();
+ return objects;
+
+ }
+ catch (NoSuchElementException e)
+ {
+ //log.debug("No identity object found with name: " + name, e);
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("IdentityObject search failed.", e);
+ }
+ finally
+ {
+ try
+ {
+ if (ctx != null)
+ {
+ ctx.close();
+ }
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Failed to close LDAP connection", e);
+ }
+ }
+
+ return objects;
}
- public Collection<IdentityObject>
findIdentityObject(IdentityStoreInvocationContext invocationCxt, IdentityObject identity,
IdentityObjectRelationshipType relationshipType, boolean parent, int offset, int limit,
boolean orderByName, boolean ascending) throws IdentityException
+ public Collection<IdentityObject>
findIdentityObject(IdentityStoreInvocationContext ctx, IdentityObject identity,
IdentityObjectRelationshipType relationshipType, boolean parent, int offset, int limit,
boolean orderByName, boolean ascending) throws IdentityException
{
- //TODO: NYI
- throw new NotYetImplementedException();
+ // relationshipType is ignored for now
+
+ if (log.isLoggable(Level.FINER))
+ {
+ log.finer(toString() + ".findIdentityObject with identity: " +
identity
+ + "; relationshipType: " + relationshipType
+ + "; offset: " + offset
+ + "; limit: " + limit
+ + "; orderByName: " + orderByName
+ + "; ascending: " + ascending
+ );
+ }
+
+ //TODO: handle paged results and sort
+
+ Set<IdentityObjectRelationship> relationships = new
HashSet<IdentityObjectRelationship>();
+
+ LDAPIdentityObjectImpl ldapFromIO = getSafeLDAPIO(ctx, identity);
+
+ LDAPIdentityObjectTypeConfiguration typeConfig = getTypeConfiguration(ctx,
identity.getIdentityType());
+
+ LdapContext ldapContext = getLDAPContext(ctx);
+
+ List<IdentityObject> objects = new LinkedList<IdentityObject>();
+
+ try
+ {
+
+ // If parent simply look for all its members
+ if (parent)
+ {
+ Attributes attrs = ldapContext.getAttributes(ldapFromIO.getDn());
+ Attribute member = attrs.get(typeConfig.getMembershipAttributeName());
+
+ if (member != null)
+ {
+ NamingEnumeration memberValues = member.getAll();
+ while (memberValues.hasMoreElements())
+ {
+ String memberRef = memberValues.nextElement().toString();
+
+ if (typeConfig.isMembershipAttributeDN())
+ {
+ //TODO: improve
+ objects.add(findIdentityObject(ctx, memberRef));
+ }
+ else
+ {
+ //TODO:
+ throw new NotYetImplementedException();
+ }
+ break;
+ }
+ }
+ }
+
+ // if not parent all parent entries need to be found
+ else
+ {
+ //TODO:
+ throw new NotYetImplementedException();
+ }
+
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Failed to resolve relationship", e);
+ }
+ finally
+ {
+ try
+ {
+ ldapContext.close();
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Failed to close LDAP connection", e);
+ }
+ }
+ return objects;
}
- public void createRelationship(IdentityStoreInvocationContext invocationCxt,
IdentityObject fromIdentity, IdentityObject toIdentity, IdentityObjectRelationshipType
relationshipType) throws IdentityException
+ public void createRelationship(IdentityStoreInvocationContext ctx, IdentityObject
fromIdentity, IdentityObject toIdentity,
+ IdentityObjectRelationshipType relationshipType,
+ String name, boolean createNames) throws
IdentityException
{
- //TODO: NYI
- throw new NotYetImplementedException();
+
+ //TODO: relationshipType is ignored for now
+
+ if (log.isLoggable(Level.FINER))
+ {
+ log.finer(toString() + ".createRelationship with "
+ + "fromIdentity: " + fromIdentity
+ + "; toIdentity: " + toIdentity
+ + "; relationshipType: " + relationshipType
+ );
+ }
+
+ LDAPIdentityObjectImpl ldapFromIO = getSafeLDAPIO(ctx, fromIdentity);
+
+ LDAPIdentityObjectImpl ldapToIO = getSafeLDAPIO(ctx, toIdentity);
+
+ LDAPIdentityObjectTypeConfiguration fromTypeConfig = getTypeConfiguration(ctx,
fromIdentity.getIdentityType());
+
+ LdapContext ldapContext = getLDAPContext(ctx);
+
+ // Check posibilities
+ //TODO: Supported features should handle information from type configurations
+
+ if
(!getSupportedFeatures().isRelationshipTypeSupported(fromIdentity.getIdentityType(),
toIdentity.getIdentityType(), relationshipType))
+ {
+ throw new IdentityException("Relationship not supported");
+ }
+
+ try
+ {
+ //construct new member attribute values
+ Attributes attrs = new BasicAttributes(true);
+
+ Attribute member = new
BasicAttribute(fromTypeConfig.getMembershipAttributeName());
+
+ if (fromTypeConfig.isMembershipAttributeDN())
+ {
+ member.add(ldapToIO.getDn());
+ }
+ else
+ {
+ member.add(toIdentity.getName());
+ }
+
+ attrs.put(member);
+
+ ldapContext.modifyAttributes(ldapFromIO.getDn(), DirContext.REPLACE_ATTRIBUTE,
attrs);
+
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Failed to create relationship", e);
+ }
+ finally
+ {
+ try
+ {
+ ldapContext.close();
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Failed to close LDAP connection", e);
+ }
+ }
}
- public void removeRelationship(IdentityStoreInvocationContext invocationCxt,
IdentityObject fromIdentity, IdentityObject toIdentity, IdentityObjectRelationshipType
relationshipType) throws IdentityException
+ public void removeRelationship(IdentityStoreInvocationContext ctx, IdentityObject
fromIdentity, IdentityObject toIdentity, IdentityObjectRelationshipType relationshipType,
String name) throws IdentityException
{
+ // relationshipType is ignored for now
+
+ if (log.isLoggable(Level.FINER))
+ {
+ log.finer(toString() + ".removeRelationship with "
+ + "fromIdentity: " + fromIdentity
+ + "; toIdentity: " + toIdentity
+ + "; relationshipType: " + relationshipType
+ );
+ }
+
+ LDAPIdentityObjectImpl ldapFromIO = getSafeLDAPIO(ctx, fromIdentity);
+ LDAPIdentityObjectImpl ldapToIO = getSafeLDAPIO(ctx, toIdentity);
+
+ LDAPIdentityObjectTypeConfiguration fromTypeConfig = getTypeConfiguration(ctx,
fromIdentity.getIdentityType());
+
+ // If relationship is not allowed simply return
+ //TODO: use features description instead
+ if
(!Arrays.asList(fromTypeConfig.getAllowedMembershipTypes()).contains(ldapToIO.getIdentityType().getName()))
+ {
+ return;
+ }
+
+ LdapContext ldapContext = getLDAPContext(ctx);
+
+ // Check posibilities
+ //TODO: Supported features should handle information from type configurations
+
+ if
(!getSupportedFeatures().isRelationshipTypeSupported(fromIdentity.getIdentityType(),
toIdentity.getIdentityType(), relationshipType))
+ {
+ throw new IdentityException("Relationship not supported");
+ }
+
+ try
+ {
+ //construct new member attribute values
+ Attributes attrs = new BasicAttributes(true);
+
+ Attribute member = new
BasicAttribute(fromTypeConfig.getMembershipAttributeName());
+
+ if (fromTypeConfig.isMembershipAttributeDN())
+ {
+ member.add(ldapToIO.getDn());
+ }
+ else
+ {
+ member.add(toIdentity.getName());
+ }
+
+ attrs.put(member);
+
+ ldapContext.modifyAttributes(ldapFromIO.getDn(), DirContext.REMOVE_ATTRIBUTE,
attrs);
+
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Failed to remove relationship", e);
+ }
+ finally
+ {
+ try
+ {
+ ldapContext.close();
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Failed to close LDAP connection", e);
+ }
+ }
+ }
+
+ public void removeRelationships(IdentityStoreInvocationContext ctx, IdentityObject
identity1, IdentityObject identity2, boolean named) throws IdentityException
+ {
+ if (log.isLoggable(Level.FINER))
+ {
+ log.finer(toString() + ".removeRelationships with "
+ + "identity1: " + identity1
+ + "; identity2: " + identity2
+ );
+ }
+
+ // as relationship type is ignored in this impl for now...
+ removeRelationship(ctx, identity1, identity2, null, null);
+ removeRelationship(ctx, identity2, identity1, null, null);
+
+ }
+
+ public Set<IdentityObjectRelationship>
resolveRelationships(IdentityStoreInvocationContext ctx, IdentityObject fromIdentity,
IdentityObject toIdentity) throws IdentityException
+ {
+ // relationshipType is ignored for now
+
+ if (log.isLoggable(Level.FINER))
+ {
+ log.finer(toString() + ".resolveRelationships with "
+ + "fromIdentity: " + fromIdentity
+ + "; toIdentity: " + toIdentity
+ );
+ }
+
+ Set<IdentityObjectRelationship> relationships = new
HashSet<IdentityObjectRelationship>();
+
+ LDAPIdentityObjectImpl ldapFromIO = getSafeLDAPIO(ctx, fromIdentity);
+ LDAPIdentityObjectImpl ldapToIO = getSafeLDAPIO(ctx, toIdentity);
+
+ LDAPIdentityObjectTypeConfiguration fromTypeConfig = getTypeConfiguration(ctx,
fromIdentity.getIdentityType());
+
+ // If relationship is not allowed return empty set
+ //TODO: use features description instead
+ if
(!Arrays.asList(fromTypeConfig.getAllowedMembershipTypes()).contains(ldapToIO.getIdentityType().getName()))
+ {
+ return relationships;
+ }
+
+ LdapContext ldapContext = getLDAPContext(ctx);
+
+ try
+ {
+ Attributes attrs = ldapContext.getAttributes(ldapFromIO.getDn());
+ Attribute member = attrs.get(fromTypeConfig.getMembershipAttributeName());
+
+ if (member != null)
+ {
+ NamingEnumeration memberValues = member.getAll();
+ while (memberValues.hasMoreElements())
+ {
+ String memberRef = memberValues.nextElement().toString();
+
+ if ((fromTypeConfig.isMembershipAttributeDN() &&
memberRef.equals(ldapToIO.getDn())) ||
+ (!fromTypeConfig.isMembershipAttributeDN() &&
memberRef.equals(ldapToIO.getName())))
+ {
+ //TODO: impl lacks support for rel type
+ relationships.add(new LDAPIdentityObjectRelationshipImpl(null,
ldapFromIO, ldapToIO));
+ }
+ break;
+ }
+ }
+
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Failed to resolve relationship", e);
+ }
+ finally
+ {
+ try
+ {
+ ldapContext.close();
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Failed to close LDAP connection", e);
+ }
+ }
+ return relationships;
+ }
+
+ public String createRelationshipName(IdentityStoreInvocationContext ctx, String name)
throws IdentityException, OperationNotSupportedException
+ {
+ throw new OperationNotSupportedException("Named relationships are not
supported by this implementation of LDAP IdentityStore");
+ }
+
+ public String removeRelationshipName(IdentityStoreInvocationContext ctx, String name)
throws IdentityException, OperationNotSupportedException
+ {
+ throw new OperationNotSupportedException("Named relationships are not
supported by this implementation of LDAP IdentityStore");
+ }
+
+ public Set<String> getRelationshipNames(IdentityStoreInvocationContext ctx, int
offset, int limit, boolean orderByName, boolean ascending) throws IdentityException,
OperationNotSupportedException
+ {
+ throw new OperationNotSupportedException("Named relationships are not
supported by this implementation of LDAP IdentityStore");
+
+ }
+
+ public Set<String> getRelationshipNames(IdentityStoreInvocationContext ctx,
IdentityObject identity, int offset, int limit, boolean orderByName, boolean ascending)
throws IdentityException, OperationNotSupportedException
+ {
+ throw new OperationNotSupportedException("Named relationships are not
supported by this implementation of LDAP IdentityStore");
+
+ }
+
+ public boolean hasPasswordAttribute(IdentityStoreInvocationContext ctx,
IdentityObjectType type) throws IdentityException
+ {
//TODO: NYI
throw new NotYetImplementedException();
}
- public void removeRelationships(IdentityStoreInvocationContext invocationCtx,
IdentityObject identity1, IdentityObject identity2) throws IdentityException
+ public boolean validatePassword(IdentityStoreInvocationContext ctx, IdentityObject
identityObject, String password) throws IdentityException
{
//TODO: NYI
throw new NotYetImplementedException();
}
- public Set<IdentityObjectRelationshipType>
resolveRelationships(IdentityStoreInvocationContext invocationCxt, IdentityObject
fromIdentity, IdentityObject toIdentity) throws IdentityException
+ public void updatePassword(IdentityStoreInvocationContext ctx, IdentityObject
identityObject, String password) throws IdentityException
{
//TODO: NYI
throw new NotYetImplementedException();
}
+
// Attributes
public Set<String> getSupportedAttributeNames(IdentityStoreInvocationContext
invocationContext, IdentityObjectType identityType) throws IdentityException
{
- //TODO: NYI
- throw new NotYetImplementedException();
+ if (log.isLoggable(Level.FINER))
+ {
+ log.finer(toString() + ".getSupportedAttributeNames with "
+ + "identityType: " + identityType
+ );
+ }
+
+ checkIOType(identityType);
+
+ return getTypeConfiguration(invocationContext,
identityType).getMappedAttributesNames();
}
- public Map<String, Set<String>>
getAttributes(IdentityStoreInvocationContext invocationContext, IdentityObject identity)
throws IdentityException
+ public Map<String, Set<String>>
getAttributes(IdentityStoreInvocationContext ctx, IdentityObject identity) throws
IdentityException
{
- //TODO: NYI
- throw new NotYetImplementedException();
+
+ if (log.isLoggable(Level.FINER))
+ {
+ log.finer(toString() + ".getAttributes with "
+ + "identity: " + identity
+ );
+ }
+
+ Map<String, Set<String>> attrsMap = new HashMap<String,
Set<String>>();
+
+ LDAPIdentityObjectImpl ldapIdentity = getSafeLDAPIO(ctx, identity);
+
+
+ LdapContext ldapContext = getLDAPContext(ctx);
+
+ try
+ {
+ Set<String> mappedNames = getTypeConfiguration(ctx,
identity.getIdentityType()).getMappedAttributesNames();
+
+ // as this is valid LDAPIdentityObjectImpl DN is obtained from the Id
+
+ String dn = ldapIdentity.getDn();
+
+ Attributes attrs = ldapContext.getAttributes(dn);
+
+ for (Iterator iterator = mappedNames.iterator(); iterator.hasNext();)
+ {
+ String name = (String)iterator.next();
+ String attrName = getTypeConfiguration(ctx,
identity.getIdentityType()).getAttributeMapping(name);
+ Attribute attr = attrs.get(attrName);
+
+ if (attr != null)
+ {
+ NamingEnumeration values = attr.getAll();
+
+ Set<String> attrValues = new HashSet<String>();
+
+ while (values.hasMoreElements())
+ {
+ String value = values.nextElement().toString();
+ attrValues.add(value);
+ }
+
+ attrsMap.put(name, attrValues);
+ }
+ else
+ {
+ log.fine("No such attribute ('" + attrName + "') in
entry: " + dn);
+ }
+ }
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Cannot get attributes value.", e);
+ }
+ finally
+ {
+ try
+ {
+ ldapContext.close();
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Failed to close LDAP connection", e);
+ }
+ }
+
+ return attrsMap;
+
}
- public void updateAttributes(IdentityStoreInvocationContext invocationCtx,
IdentityObject identity, Map<String, Set<String>> attributes) throws
IdentityException
+ public void updateAttributes(IdentityStoreInvocationContext ctx, IdentityObject
identity, Map<String, Set<String>> attributes) throws IdentityException
{
- //TODO: NYI
- throw new NotYetImplementedException();
+
+ if (log.isLoggable(Level.FINER))
+ {
+ log.finer(toString() + ".updateAttributes with "
+ + "identity: " + identity
+ + "attributes: " + attributes
+ );
+ }
+
+ if (attributes == null)
+ {
+ throw new IllegalArgumentException("attributes is null");
+ }
+
+ LDAPIdentityObjectImpl ldapIdentity = getSafeLDAPIO(ctx, identity);
+
+
+ // as this is valid LDAPIdentityObjectImpl DN is obtained from the Id
+
+ String dn = ldapIdentity.getDn();
+
+ LdapContext ldapContext = getLDAPContext(ctx);
+
+ try
+ {
+
+ for (String name : attributes.keySet())
+ {
+ String attributeName = getTypeConfiguration(ctx,
identity.getIdentityType()).getAttributeMapping(name);
+
+ if (attributeName == null)
+ {
+ log.fine("Proper LDAP attribute mapping not found for such property
name: " + name);
+ continue;
+ }
+
+ //TODO: maybe perform a schema check if this attribute is not required
+
+ Attributes attrs = new BasicAttributes(true);
+ Attribute attr = new BasicAttribute(attributeName);
+
+ Set<String> values = attributes.get(name);
+
+
+ if (values != null)
+ {
+ for (String value : values)
+ {
+ attr.add(value);
+ }
+
+ attrs.put(attr);
+
+ try
+ {
+ ldapContext.modifyAttributes(dn, DirContext.REPLACE_ATTRIBUTE, attrs);
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Cannot add attribute", e);
+ }
+ }
+
+ }
+ }
+ finally
+ {
+ try
+ {
+ ldapContext.close();
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Failed to close LDAP connection", e);
+ }
+ }
}
- public void addAttributes(IdentityStoreInvocationContext invocationCtx, IdentityObject
identity, Map<String, Set<String>> attributes) throws IdentityException
+ public void addAttributes(IdentityStoreInvocationContext ctx, IdentityObject identity,
Map<String, Set<String>> attributes) throws IdentityException
{
- //TODO: NYI
- throw new NotYetImplementedException();
+
+ if (log.isLoggable(Level.FINER))
+ {
+ log.finer(toString() + ".addAttributes with "
+ + "identity: " + identity
+ + "attributes: " + attributes
+ );
+ }
+
+
+ if (attributes == null)
+ {
+ throw new IllegalArgumentException("attributes is null");
+ }
+
+ LDAPIdentityObjectImpl ldapIdentity = getSafeLDAPIO(ctx, identity);
+
+
+ // as this is valid LDAPIdentityObjectImpl DN is obtained from the Id
+
+ String dn = ldapIdentity.getDn();
+
+ LdapContext ldapContext = getLDAPContext(ctx);
+
+ try
+ {
+ for (String name : attributes.keySet())
+ {
+ String attributeName = getTypeConfiguration(ctx,
identity.getIdentityType()).getAttributeMapping(name);
+
+ if (attributeName == null)
+ {
+ log.fine("Proper LDAP attribute mapping not found for such property
name: " + name);
+ continue;
+ }
+
+ //TODO: maybe perform a schema check if this attribute is not required
+
+ Attributes attrs = new BasicAttributes(true);
+ Attribute attr = new BasicAttribute(attributeName);
+
+ Set<String> values = attributes.get(name);
+
+
+ if (values != null)
+ {
+ for (String value : values)
+ {
+ attr.add(value);
+ }
+
+ attrs.put(attr);
+
+ try
+ {
+ ldapContext.modifyAttributes(dn, DirContext.ADD_ATTRIBUTE, attrs);
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Cannot add attribute", e);
+ }
+ }
+
+ }
+ }
+ finally
+ {
+ try
+ {
+ ldapContext.close();
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Failed to close LDAP connection", e);
+ }
+ }
}
- public void removeAttributes(IdentityStoreInvocationContext invocationCtx,
IdentityObject identity, Set<String> attributes) throws IdentityException
+ public void removeAttributes(IdentityStoreInvocationContext ctx, IdentityObject
identity, Set<String> attributes) throws IdentityException
{
- //TODO: NYI
- throw new NotYetImplementedException();
+
+ if (log.isLoggable(Level.FINER))
+ {
+ log.finer(toString() + ".removeAttributes with "
+ + "identity: " + identity
+ + "attributes: " + attributes
+ );
+ }
+
+ if (attributes == null)
+ {
+ throw new IllegalArgumentException("attributes is null");
+ }
+
+ LDAPIdentityObjectImpl ldapIdentity = getSafeLDAPIO(ctx, identity);
+
+ // as this is valid LDAPIdentityObjectImpl DN is obtained from the Id
+
+ String dn = ldapIdentity.getDn();
+
+ LdapContext ldapContext = getLDAPContext(ctx);
+
+ try
+ {
+ for (String name : attributes)
+ {
+ String attributeName = getTypeConfiguration(ctx,
identity.getIdentityType()).getAttributeMapping(name);
+
+ if (attributeName == null)
+ {
+ log.fine("Proper LDAP attribute mapping not found for such property
name: " + name);
+ continue;
+ }
+
+ //TODO: maybe perform a schema check if this attribute is not required
+
+ Attributes attrs = new BasicAttributes(true);
+ Attribute attr = new BasicAttribute(attributeName);
+ attrs.put(attr);
+
+ try
+ {
+ ldapContext.modifyAttributes(dn, DirContext.REMOVE_ATTRIBUTE, attrs);
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Cannot remove attribute", e);
+ }
+
+ }
+ }
+ finally
+ {
+ try
+ {
+ ldapContext.close();
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Failed to close LDAP connection", e);
+ }
+ }
}
//Internal
@@ -487,7 +1284,7 @@
return ldapio;
}
- public List searchIdentityObjects(IdentityStoreInvocationContext ctx,
IdentityObjectType type, String filter, Object[] filterArgs) throws NamingException,
IdentityException
+ public List<SearchResult> searchIdentityObjects(IdentityStoreInvocationContext
ctx, IdentityObjectType type, String filter, Object[] filterArgs, String[]
returningAttributes) throws NamingException, IdentityException
{
LdapContext ldapContext = getLDAPContext(ctx);
@@ -501,9 +1298,13 @@
controls.setReturningObjFlag(true);
controls.setTimeLimit(getConfiguration(ctx).getSearchTimeLimit());
- //TODO: set returning attributes to boost performance
+ if (returningAttributes != null)
+ {
+ controls.setReturningAttributes(returningAttributes);
+ }
+
String[] entryCtxs = getTypeConfiguration(ctx, type).getCtxDNs();
if (entryCtxs.length == 1)
@@ -522,11 +1323,11 @@
}
else
{
- List merged = new LinkedList();
+ List<SearchResult> merged = new LinkedList();
for (String entryCtx : entryCtxs)
{
- if (filterArgs == null)
+ if (filterArgs == null)
{
results = ldapContext.search(entryCtx, filter, controls);
}
@@ -537,7 +1338,7 @@
merged.addAll(Tools.toList(results));
results.close();
}
-
+
return merged;
}
}
@@ -551,22 +1352,31 @@
}
}
-
// HELPER
-
- private void checkIOInstance(IdentityObject io)
+ private LDAPIdentityObjectImpl getSafeLDAPIO(IdentityStoreInvocationContext ctx,
IdentityObject io) throws IdentityException
{
if (io == null)
{
throw new IllegalArgumentException("IdentityObject is null");
}
- if (!(io instanceof LDAPIdentityObjectImpl))
+ if (io instanceof LDAPIdentityObjectImpl)
{
- throw new IllegalArgumentException("IdentityObject type not supported by
this " +
- "IdentityStore implementation: " + io.getClass().getName());
+ return (LDAPIdentityObjectImpl)io;
}
+ else
+ {
+ try
+ {
+ return (LDAPIdentityObjectImpl)findIdentityObject(ctx, io.getName(),
io.getIdentityType());
+ }
+ catch (IdentityException e)
+ {
+ throw new IdentityException("Provided IdentityObject is not present in
the store. Cannot operate on not stored objects.", e);
+ }
+ }
+
}
private void checkIOType(IdentityObjectType iot) throws IdentityException
@@ -619,5 +1429,8 @@
return getConfiguration(ctx).getTypeConfiguration(type.getName());
}
-
+ public String toString()
+ {
+ return this.getClass().getName() + "[" + getId() +"]";
+ }
}
Added: trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/APITestContext.java
===================================================================
--- trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/APITestContext.java
(rev 0)
+++
trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/APITestContext.java 2008-10-15
10:59:42 UTC (rev 103)
@@ -0,0 +1,38 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, 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.jboss.identity.impl.api;
+
+import org.jboss.identity.api.IdentitySession;
+import org.jboss.identity.api.IdentitySessionFactory;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public interface APITestContext
+{
+
+
+ IdentitySessionFactory getIdentitySessionFactory();
+
+}
Added: trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/GroupTypeEnum.java
===================================================================
--- trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/GroupTypeEnum.java
(rev 0)
+++
trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/GroupTypeEnum.java 2008-10-15
10:59:42 UTC (rev 103)
@@ -0,0 +1,48 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, 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.jboss.identity.impl.api;
+
+import org.jboss.identity.api.GroupType;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public enum GroupTypeEnum implements GroupType
+{
+ ADMINISTRATION,
+ ORGANIZATION,
+ DIVISION,
+ DEPARTMENT,
+ PROJECT,
+ SECURITY,
+ COMMUNITY,
+ OFFICE,
+ CUSTOM;
+
+ public String getName()
+ {
+ return this.name();
+ }
+}
Added:
trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/OrganizationTest.java
===================================================================
--- trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/OrganizationTest.java
(rev 0)
+++
trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/OrganizationTest.java 2008-10-15
10:59:42 UTC (rev 103)
@@ -0,0 +1,333 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, 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.jboss.identity.impl.api;
+
+import org.jboss.identity.api.IdentitySession;
+import org.jboss.identity.api.Group;
+import org.jboss.identity.api.GroupType;
+import org.jboss.identity.api.Identity;
+import org.jboss.identity.api.RoleType;
+import org.jboss.identity.api.IdentitySessionFactory;
+
+import java.util.Collection;
+
+import junit.framework.Assert;
+
+/**
+ * Abstract test mapping real life structures using the API
+ *
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class OrganizationTest extends Assert
+{
+
+ APITestContext ctx;
+
+ public OrganizationTest(APITestContext ctx)
+ {
+ this.ctx = ctx;
+ }
+
+ public void setCtx(APITestContext ctx)
+ {
+ this.ctx = ctx;
+ }
+
+ public APITestContext getCtx()
+ {
+ return ctx;
+ }
+
+ public void testRedHatOrganization() throws Exception
+ {
+
+
+
+ GroupType ORGANIZATION = new SimpleGroupType("ORGANIZATION");
+ GroupType ORGANIZATION_UNIT = new SimpleGroupType("ORGANIZATION_UNIT");
+ GroupType DIVISION = new SimpleGroupType("DIVISION");
+ GroupType DEPARTMENT = new SimpleGroupType("DEPARTMENT");
+ GroupType PROJECT = new SimpleGroupType("PROJECT");
+ GroupType PEOPLE = new SimpleGroupType("PEOPLE");
+
+ IdentitySessionFactory factory = ctx.getIdentitySessionFactory();
+
+ IdentitySession session =
factory.createIdentitySession("realm://RedHat");
+
+ session.getTransaction().start();
+
+ // Organization structure
+
+ Group rhOrg = session.getPersistenceManager().createGroup("RedHat",
ORGANIZATION);
+
+ Group jbossDivision =
session.getPersistenceManager().createGroup("JBoss", DIVISION);
+ Group rhelDivision = session.getPersistenceManager().createGroup("RHEL",
DIVISION);
+
+ session.getRelationshipManager().associateGroups(rhOrg, jbossDivision);
+ session.getRelationshipManager().associateGroups(rhOrg, rhelDivision);
+
+ Group itDepartment = session.getPersistenceManager().createGroup("IT",
DEPARTMENT);
+ Group hrDepartment = session.getPersistenceManager().createGroup("HR",
DEPARTMENT);
+
+ session.getRelationshipManager().associateGroups(jbossDivision, itDepartment);
+ session.getRelationshipManager().associateGroups(jbossDivision, hrDepartment);
+
+ Group projectsDepartment =
session.getPersistenceManager().createGroup("Projects", DEPARTMENT);
+
+ session.getRelationshipManager().associateGroups(itDepartment,
projectsDepartment);
+
+ Group portalProject =
session.getPersistenceManager().createGroup("Portal", PROJECT);
+ Group soaProject = session.getPersistenceManager().createGroup("SOA",
PROJECT);
+ Group jbpmProject = session.getPersistenceManager().createGroup("jBPM",
PROJECT);
+ Group seamProject = session.getPersistenceManager().createGroup("Seam",
PROJECT);
+ Group asProject = session.getPersistenceManager().createGroup("AS",
PROJECT);
+ Group securityProject =
session.getPersistenceManager().createGroup("Security", PROJECT);
+
+ session.getRelationshipManager().associateGroups(projectsDepartment,
portalProject);
+ session.getRelationshipManager().associateGroups(projectsDepartment, soaProject);
+ session.getRelationshipManager().associateGroups(projectsDepartment, jbpmProject);
+ session.getRelationshipManager().associateGroups(projectsDepartment, asProject);
+ session.getRelationshipManager().associateGroups(projectsDepartment, seamProject);
+
+ //TODO: common frameworks for bgeorges - whats the type of group?
+
+ // People
+
+ Group employeesGroup =
session.getPersistenceManager().createGroup("Employees", PEOPLE);
+
+ // Management
+
+ Identity theuteUser =
session.getPersistenceManager().createIdentity("theute");
+ Identity mlittleUser =
session.getPersistenceManager().createIdentity("mlittle");
+ Identity bgeorgesUser =
session.getPersistenceManager().createIdentity("bgeorges");
+ Identity asaldhanaUser =
session.getPersistenceManager().createIdentity("asaldhana");
+ Identity janderseUser =
session.getPersistenceManager().createIdentity("janderse");
+
+ // Portal Team
+
+ Identity bdawidowUser =
session.getPersistenceManager().createIdentity("bdawidow");
+ Identity claprunUser =
session.getPersistenceManager().createIdentity("claprun");
+ Identity whalesUser =
session.getPersistenceManager().createIdentity("whales");
+ Identity sshahUser =
session.getPersistenceManager().createIdentity("sshah");
+ Identity mwringeUser =
session.getPersistenceManager().createIdentity("mwringe");
+
+ // Store as employees
+
+ session.getRelationshipManager().associateIdentities(employeesGroup, theuteUser);
+ session.getRelationshipManager().associateIdentities(employeesGroup, mlittleUser);
+ session.getRelationshipManager().associateIdentities(employeesGroup, theuteUser);
+ session.getRelationshipManager().associateIdentities(employeesGroup,
asaldhanaUser);
+ session.getRelationshipManager().associateIdentities(employeesGroup,
bdawidowUser);
+ session.getRelationshipManager().associateIdentities(employeesGroup, claprunUser);
+ session.getRelationshipManager().associateIdentities(employeesGroup, whalesUser);
+ session.getRelationshipManager().associateIdentities(employeesGroup, sshahUser);
+ session.getRelationshipManager().associateIdentities(employeesGroup, mwringeUser);
+
+ // Portal team for management
+
+ Group portalTeamGroup = session.getPersistenceManager().createGroup("Portal
Team", PEOPLE);
+ session.getRelationshipManager().associateIdentities(portalTeamGroup,
bdawidowUser);
+ session.getRelationshipManager().associateIdentities(portalTeamGroup,
claprunUser);
+ session.getRelationshipManager().associateIdentities(portalTeamGroup, whalesUser);
+ session.getRelationshipManager().associateIdentities(portalTeamGroup, sshahUser);
+ session.getRelationshipManager().associateIdentities(portalTeamGroup,
mwringeUser);
+
+ // Role Types
+
+ RoleType developerRT =
session.getRoleManager().createRoleType("Developer");
+ RoleType managerRT = session.getRoleManager().createRoleType("Manager");
+ RoleType leadDeveloperRT = session.getRoleManager().createRoleType("Lead
Developer");
+ RoleType productManagerRT = session.getRoleManager().createRoleType("Product
Manager");
+
+ // Assign roles
+
+ // Portal developers
+
+ session.getRoleManager().createRole(developerRT, theuteUser, portalProject);
+ session.getRoleManager().createRole(developerRT, bdawidowUser, portalProject);
+ session.getRoleManager().createRole(developerRT, claprunUser, portalProject);
+ session.getRoleManager().createRole(developerRT, whalesUser, portalProject);
+ session.getRoleManager().createRole(developerRT, sshahUser, portalProject);
+ session.getRoleManager().createRole(developerRT, mwringeUser, portalProject);
+
+ // Portal management
+ session.getRoleManager().createRole(leadDeveloperRT, theuteUser, portalProject);
+ session.getRoleManager().createRole(managerRT, theuteUser, portalTeamGroup);
+ session.getRoleManager().createRole(productManagerRT, janderseUser,
portalProject);
+
+ // SOA
+
+ session.getRoleManager().createRole(developerRT, mlittleUser, portalProject);
+ session.getRoleManager().createRole(productManagerRT, mlittleUser, portalProject);
+
+ // AS & Security
+
+ session.getRoleManager().createRole(developerRT, asaldhanaUser, asProject);
+ session.getRoleManager().createRole(developerRT, asaldhanaUser, securityProject);
+ session.getRoleManager().createRole(leadDeveloperRT, asaldhanaUser,
securityProject);
+
+
+ //TODO: Asserts for this structure
+
+
+ // Check what RoleTypes has user theute
+ Collection<RoleType> roleTypes =
session.getRoleManager().findIdentityRoleTypes(theuteUser, 0, 0, false, false);
+ assertTrue(roleTypes.contains(developerRT));
+ assertTrue(roleTypes.contains(leadDeveloperRT));
+ assertTrue(roleTypes.contains(managerRT));
+ assertFalse(roleTypes.contains(productManagerRT));
+
+ assertTrue(session.getRoleManager().hasRole(theuteUser, portalProject,
developerRT));
+ assertTrue(session.getRoleManager().hasRole(theuteUser, portalProject,
leadDeveloperRT));
+ assertTrue(session.getRoleManager().hasRole(theuteUser, portalTeamGroup,
managerRT));
+
+ //TODO: Something about profile
+
+
+ session.getTransaction().commit();
+
+ }
+
+ public void testSamplePortal() throws Exception
+ {
+ GroupType SYSTEM = new SimpleGroupType("SYSTEM");
+ GroupType ADMINISTRATION = new SimpleGroupType("ADMINISTRATION");
+ GroupType COMMUNITY = new SimpleGroupType("COMMUNITY");
+ GroupType ORGANIZATION = new SimpleGroupType("ORGANIZATION");
+ GroupType ORGANIZATION_UNIT = new SimpleGroupType("ORGANIZATION_UNIT");
+ GroupType OFFICE = new SimpleGroupType("OFFICE");
+ GroupType DIVISION = new SimpleGroupType("DIVISION");
+ GroupType DEPARTMENT = new SimpleGroupType("DEPARTMENT");
+ GroupType SECURITY = new SimpleGroupType("SECURITY");
+ GroupType PEOPLE = new SimpleGroupType("PEOPLE");
+
+ IdentitySessionFactory factory = ctx.getIdentitySessionFactory();
+
+ //TODO: alter realm policies to make ORGANIZATION, ORGANIZATION_UNIT, DIVISION,
DEPARTMENT and OFFICE hierarchical groups
+
+ IdentitySession session =
factory.createIdentitySession("realm://portal/SamplePortal");
+
+ session.getTransaction().start();
+
+ // Create all role types
+ RoleType adminRT = session.getRoleManager().createRoleType("Admin");
+ RoleType accountAdminRT = session.getRoleManager().createRoleType("Account
Admin");
+ RoleType managerRT = session.getRoleManager().createRoleType("Manager");
+ RoleType officeManagerRT = session.getRoleManager().createRoleType("Office
Manager");
+ RoleType contributorRT =
session.getRoleManager().createRoleType("Contributor");
+ RoleType communityOwnerRT = session.getRoleManager().createRoleType("Community
Owner");
+ RoleType communityMemberRT =
session.getRoleManager().createRoleType("Community Member");
+ RoleType communityForumModeratorRT =
session.getRoleManager().createRoleType("Community Forum Moderator");
+ RoleType communityCMSAdminRT =
session.getRoleManager().createRoleType("Community CMS Admin");
+
+
+ // Create system root groups - groups containing all communities, global security
groups and organization
+
+ Group communityRootGroup =
session.getPersistenceManager().createGroup("COMMUNITY_ROOT", SYSTEM);
+ Group securityRootGroup =
session.getPersistenceManager().createGroup("SECURITY_ROOT", SYSTEM);
+ Group organizationRootGroup =
session.getPersistenceManager().createGroup("ORGANIZATION_ROOT",SYSTEM);
+ Group usersROOTGroup =
session.getPersistenceManager().createGroup("ORGANIZATION_ROOT",SYSTEM);
+
+ // Communities
+
+ Group portalLoversCommunity =
session.getPersistenceManager().createGroup("Portal Lovers", COMMUNITY);
+ Group baseJumpingCommunity = session.getPersistenceManager().createGroup("BASE
Jumping", COMMUNITY);
+ Group geeksCommunity =
session.getPersistenceManager().createGroup("Geeks", COMMUNITY);
+
+ session.getRelationshipManager().associateGroups(communityRootGroup,
portalLoversCommunity);
+ session.getRelationshipManager().associateGroups(communityRootGroup,
baseJumpingCommunity);
+ session.getRelationshipManager().associateGroups(communityRootGroup,
geeksCommunity);
+
+ // Security groups - act like global portal roles
+
+ Group portalAdminGroup = session.getPersistenceManager().createGroup("Poral
Admin", SECURITY);
+ Group cmsAdminGroup = session.getPersistenceManager().createGroup("CMS
Admin", SECURITY);
+ Group userAdminGroup = session.getPersistenceManager().createGroup("User
Admin", SECURITY);
+ Group cmsEditorGroup = session.getPersistenceManager().createGroup("CMS
Editor", SECURITY);
+
+ session.getRelationshipManager().associateGroups(securityRootGroup,
portalAdminGroup);
+ session.getRelationshipManager().associateGroups(securityRootGroup,
cmsAdminGroup);
+ session.getRelationshipManager().associateGroups(securityRootGroup,
userAdminGroup);
+ session.getRelationshipManager().associateGroups(securityRootGroup,
cmsEditorGroup);
+
+ // Organization structure
+
+ Group acmeOrg = session.getPersistenceManager().createGroup("ACME",
ORGANIZATION);
+
+ Group departmentsOU =
session.getPersistenceManager().createGroup("Departments", ORGANIZATION_UNIT);
+ Group officesOU = session.getPersistenceManager().createGroup("Offices",
ORGANIZATION_UNIT);
+ Group employeesOU =
session.getPersistenceManager().createGroup("Employees", ORGANIZATION_UNIT);
+
+ session.getRelationshipManager().associateGroups(acmeOrg, departmentsOU);
+ session.getRelationshipManager().associateGroups(acmeOrg, officesOU);
+ session.getRelationshipManager().associateGroups(acmeOrg, employeesOU);
+
+ // Departments
+
+ Group hrDepart = session.getPersistenceManager().createGroup("HR",
DEPARTMENT);
+ Group financeDepart =
session.getPersistenceManager().createGroup("Finance", DEPARTMENT);
+ Group rndDepart = session.getPersistenceManager().createGroup("R&D",
DEPARTMENT);
+
+ session.getRelationshipManager().associateGroups(departmentsOU, hrDepart);
+ session.getRelationshipManager().associateGroups(departmentsOU, financeDepart);
+ session.getRelationshipManager().associateGroups(departmentsOU, rndDepart);
+
+ // Offices
+
+ Group parisOffice =session.getPersistenceManager().createGroup("Paris",
OFFICE);
+ Group londonOffice =session.getPersistenceManager().createGroup("London",
OFFICE);
+ Group nyOffice =session.getPersistenceManager().createGroup("New York",
OFFICE);
+
+ session.getRelationshipManager().associateGroups(officesOU, parisOffice);
+ session.getRelationshipManager().associateGroups(officesOU, londonOffice);
+ session.getRelationshipManager().associateGroups(officesOU, nyOffice);
+
+ // People
+
+ Identity anneUser =
session.getPersistenceManager().createIdentity("anne");
+ Identity marieUser =
session.getPersistenceManager().createIdentity("marie");
+ Identity eveUser =
session.getPersistenceManager().createIdentity("eve");
+ Identity angelinaUser =
session.getPersistenceManager().createIdentity("angelina");
+ Identity joannaUser =
session.getPersistenceManager().createIdentity("joanna");
+ Identity merilUser =
session.getPersistenceManager().createIdentity("meril");
+ Identity johnUser =
session.getPersistenceManager().createIdentity("john");
+ Identity stanUser =
session.getPersistenceManager().createIdentity("stan");
+ Identity chrisUser =
session.getPersistenceManager().createIdentity("chris");
+ Identity billUser =
session.getPersistenceManager().createIdentity("bill");
+ Identity jackUser =
session.getPersistenceManager().createIdentity("jack");
+
+ // Roles assignment
+
+
+ session.getTransaction().commit();
+
+ }
+
+
+
+
+
+
+
+}
Added: trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/SimpleGroupType.java
===================================================================
--- trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/SimpleGroupType.java
(rev 0)
+++
trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/SimpleGroupType.java 2008-10-15
10:59:42 UTC (rev 103)
@@ -0,0 +1,44 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, 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.jboss.identity.impl.api;
+
+import org.jboss.identity.api.GroupType;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class SimpleGroupType implements GroupType
+{
+ private String name;
+
+ public SimpleGroupType(String name)
+ {
+ this.name = name;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+}
Added:
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/CommonIdentityStoreTest.java
===================================================================
---
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/CommonIdentityStoreTest.java
(rev 0)
+++
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/CommonIdentityStoreTest.java 2008-10-15
10:59:42 UTC (rev 103)
@@ -0,0 +1,288 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, 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.jboss.identity.impl.store;
+
+import org.jboss.identity.spi.model.IdentityObject;
+
+import java.util.Collection;
+import java.util.Set;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.HashSet;
+
+import junit.framework.Assert;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class CommonIdentityStoreTest extends Assert
+{
+
+ IdentityStoreTestContext testContext;
+
+ public CommonIdentityStoreTest(IdentityStoreTestContext context)
+ {
+ this.testContext = context;
+ }
+
+ public void setTestContext(IdentityStoreTestContext testContext)
+ {
+ this.testContext = testContext;
+ }
+
+ public IdentityStoreTestContext getTestContext()
+ {
+ return testContext;
+ }
+
+ public void testStorePersistence() throws Exception
+ {
+
+ testContext.begin();
+
+ IdentityObject user1 =
testContext.getStore().createIdentityObject(testContext.getCtx(), "Adam",
IdentityTypeEnum.USER);
+ IdentityObject user2 =
testContext.getStore().createIdentityObject(testContext.getCtx(), "Eva",
IdentityTypeEnum.USER);
+
+ IdentityObject group1 =
testContext.getStore().createIdentityObject(testContext.getCtx(), "Devision1",
IdentityTypeEnum.ORGANIZATION);
+ IdentityObject group2 =
testContext.getStore().createIdentityObject(testContext.getCtx(), "Devision2",
IdentityTypeEnum.ORGANIZATION);
+ IdentityObject group3 =
testContext.getStore().createIdentityObject(testContext.getCtx(), "Devision3",
IdentityTypeEnum.ORGANIZATION);
+ IdentityObject group4 =
testContext.getStore().createIdentityObject(testContext.getCtx(), "Devision4",
IdentityTypeEnum.ORGANIZATION);
+
+ testContext.flush();
+
+ assertEquals(0,
testContext.getStore().getIdentityObjectsCount(testContext.getCtx(),
IdentityTypeEnum.ROLE));
+ assertEquals(2,
testContext.getStore().getIdentityObjectsCount(testContext.getCtx(),
IdentityTypeEnum.USER));
+ assertEquals(4,
testContext.getStore().getIdentityObjectsCount(testContext.getCtx(),
IdentityTypeEnum.ORGANIZATION));
+
+ testContext.flush();
+
+ testContext.getStore().removeIdentityObject(testContext.getCtx(), user1);
+ testContext.getStore().removeIdentityObject(testContext.getCtx(), group1);
+ testContext.getStore().removeIdentityObject(testContext.getCtx(), group2);
+
+ assertEquals(1,
testContext.getStore().getIdentityObjectsCount(testContext.getCtx(),
IdentityTypeEnum.USER));
+ assertEquals(2,
testContext.getStore().getIdentityObjectsCount(testContext.getCtx(),
IdentityTypeEnum.ORGANIZATION));
+
+ testContext.getStore().removeIdentityObject(testContext.getCtx(), user2);
+ testContext.getStore().removeIdentityObject(testContext.getCtx(), group3);
+ testContext.getStore().removeIdentityObject(testContext.getCtx(), group4);
+
+ assertEquals(0,
testContext.getStore().getIdentityObjectsCount(testContext.getCtx(),
IdentityTypeEnum.USER));
+ assertEquals(0,
testContext.getStore().getIdentityObjectsCount(testContext.getCtx(),
IdentityTypeEnum.ORGANIZATION));
+
+ testContext.commit();
+
+ }
+
+ public void testFindMethods() throws Exception
+ {
+
+ testContext.begin();
+
+ IdentityObject user1 =
testContext.getStore().createIdentityObject(testContext.getCtx(), "Adam",
IdentityTypeEnum.USER);
+ IdentityObject user2 =
testContext.getStore().createIdentityObject(testContext.getCtx(), "Eva",
IdentityTypeEnum.USER);
+
+ IdentityObject group1 =
testContext.getStore().createIdentityObject(testContext.getCtx(), "Devision1",
IdentityTypeEnum.ORGANIZATION);
+ IdentityObject group2 =
testContext.getStore().createIdentityObject(testContext.getCtx(), "Devision2",
IdentityTypeEnum.ORGANIZATION);
+ IdentityObject group3 =
testContext.getStore().createIdentityObject(testContext.getCtx(), "Devision3",
IdentityTypeEnum.ORGANIZATION);
+ IdentityObject group4 =
testContext.getStore().createIdentityObject(testContext.getCtx(), "Devision4",
IdentityTypeEnum.ORGANIZATION);
+
+ testContext.flush();
+
+ IdentityObject xx = testContext.getStore().findIdentityObject(testContext.getCtx(),
"Adam", IdentityTypeEnum.USER);
+ assertEquals(xx.getId(), user1.getId());
+
+ xx = testContext.getStore().findIdentityObject(testContext.getCtx(),
user2.getId());
+ assertEquals(xx.getId(), user2.getId());
+
+ Collection results =
testContext.getStore().findIdentityObject(testContext.getCtx(), IdentityTypeEnum.USER,
"*", 0, 0, true, true);
+ assertEquals(2, results.size());
+
+ results = testContext.getStore().findIdentityObject(testContext.getCtx(),
IdentityTypeEnum.ORGANIZATION, "*", 0, 0, true, true);
+ assertEquals(4, results.size());
+
+ results = testContext.getStore().findIdentityObject(testContext.getCtx(),
IdentityTypeEnum.ROLE, "*", 0, 0, true, true);
+ assertEquals(0, results.size());
+
+
+ testContext.commit();
+
+ }
+
+ public void testAttributes() throws Exception
+ {
+
+ testContext.begin();
+
+ IdentityObject user1 =
testContext.getStore().createIdentityObject(testContext.getCtx(), "Adam",
IdentityTypeEnum.USER);
+ IdentityObject user2 =
testContext.getStore().createIdentityObject(testContext.getCtx(), "Eva",
IdentityTypeEnum.USER);
+
+ testContext.flush();
+
+ Map<String, Set<String>> attrs = new HashMap<String,
Set<String>>();
+ HashSet<String> vals = new HashSet<String>();
+ vals.add("val1");
+ vals.add("val2");
+ vals.add("val3");
+
+ attrs.put("key1", vals);
+
+ vals = new HashSet<String>();
+ vals.add("val1");
+ vals.add("val2");
+ vals.add("val3");
+ vals.add("val4");
+ attrs.put("key2", vals);
+
+ testContext.getStore().addAttributes(testContext.getCtx(), user1, attrs);
+
+ testContext.flush();
+
+ Map<String, Set<String>> persistedAttrs =
testContext.getStore().getAttributes(testContext.getCtx(), user1);
+
+ assertEquals(2, persistedAttrs.keySet().size());
+
+ assertTrue(persistedAttrs.containsKey("key1"));
+ assertEquals(3, persistedAttrs.get("key1").size());
+
+ assertTrue(persistedAttrs.containsKey("key2"));
+ assertEquals(4, persistedAttrs.get("key2").size());
+
+ testContext.flush();
+
+ attrs = new HashMap<String, Set<String>>();
+ vals = new HashSet<String>();
+ vals.add("val1");
+ attrs.put("key3", vals);
+
+ testContext.getStore().addAttributes(testContext.getCtx(), user1, attrs);
+
+ testContext.flush();
+
+ persistedAttrs = testContext.getStore().getAttributes(testContext.getCtx(),
user1);
+
+ assertEquals(3, persistedAttrs.keySet().size());
+
+ assertTrue(persistedAttrs.containsKey("key1"));
+ assertEquals(3, persistedAttrs.get("key1").size());
+
+ assertTrue(persistedAttrs.containsKey("key2"));
+ assertEquals(4, persistedAttrs.get("key2").size());
+
+ assertTrue(persistedAttrs.containsKey("key3"));
+ assertEquals(1, persistedAttrs.get("key3").size());
+
+ testContext.flush();
+
+ vals = new HashSet<String>();
+ vals.add("val2");
+ attrs.put("key3", vals);
+
+ testContext.getStore().addAttributes(testContext.getCtx(), user1, attrs);
+
+ testContext.flush();
+
+ persistedAttrs = testContext.getStore().getAttributes(testContext.getCtx(),
user1);
+
+ assertEquals(3, persistedAttrs.keySet().size());
+
+ assertTrue(persistedAttrs.containsKey("key3"));
+ assertEquals(2, persistedAttrs.get("key3").size());
+
+ testContext.flush();
+
+ testContext.getStore().updateAttributes(testContext.getCtx(), user1, attrs);
+
+ testContext.flush();
+
+ persistedAttrs = testContext.getStore().getAttributes(testContext.getCtx(),
user1);
+
+ assertEquals(3, persistedAttrs.keySet().size());
+
+ assertTrue(persistedAttrs.containsKey("key3"));
+ assertEquals(1, persistedAttrs.get("key3").size());
+
+ testContext.flush();
+
+ Set<String> names = new HashSet<String>();
+ names.add("key3");
+ testContext.getStore().removeAttributes(testContext.getCtx(), user1, names);
+
+ testContext.flush();
+
+ persistedAttrs = testContext.getStore().getAttributes(testContext.getCtx(),
user1);
+
+ assertEquals(2, persistedAttrs.keySet().size());
+
+
+ testContext.commit();
+
+ }
+
+ public void testRelationships() throws Exception
+ {
+
+ testContext.begin();
+
+ IdentityObject user1 =
testContext.getStore().createIdentityObject(testContext.getCtx(), "Adam",
IdentityTypeEnum.USER);
+ IdentityObject user2 =
testContext.getStore().createIdentityObject(testContext.getCtx(), "Eva",
IdentityTypeEnum.USER);
+
+ IdentityObject group1 =
testContext.getStore().createIdentityObject(testContext.getCtx(), "Devision1",
IdentityTypeEnum.ORGANIZATION);
+ IdentityObject group2 =
testContext.getStore().createIdentityObject(testContext.getCtx(), "Devision2",
IdentityTypeEnum.ORGANIZATION);
+ IdentityObject group3 =
testContext.getStore().createIdentityObject(testContext.getCtx(), "Devision3",
IdentityTypeEnum.ORGANIZATION);
+ IdentityObject group4 =
testContext.getStore().createIdentityObject(testContext.getCtx(), "Devision4",
IdentityTypeEnum.ORGANIZATION);
+
+ testContext.flush();
+
+ testContext.getStore().createRelationship(testContext.getCtx(), group1, user1,
RelationshipTypeEnum.MEMBER, null, false);
+ testContext.getStore().createRelationship(testContext.getCtx(), group2, user1,
RelationshipTypeEnum.MEMBER, null, false);
+
+ testContext.flush();
+
+ assertEquals(1, testContext.getStore().resolveRelationships(testContext.getCtx(),
group1, user1).size());
+ assertEquals(0, testContext.getStore().resolveRelationships(testContext.getCtx(),
user1, group1).size());
+ assertEquals(1, testContext.getStore().resolveRelationships(testContext.getCtx(),
group2, user1).size());
+ assertEquals(0, testContext.getStore().resolveRelationships(testContext.getCtx(),
user1, group2).size());
+
+ testContext.getStore().removeRelationship(testContext.getCtx(), group2, user1,
RelationshipTypeEnum.MEMBER, null);
+
+ testContext.flush();
+
+ assertEquals(1, testContext.getStore().resolveRelationships(testContext.getCtx(),
group1, user1).size());
+ assertEquals(0, testContext.getStore().resolveRelationships(testContext.getCtx(),
user1, group1).size());
+ assertEquals(0, testContext.getStore().resolveRelationships(testContext.getCtx(),
group2, user1).size());
+ assertEquals(0, testContext.getStore().resolveRelationships(testContext.getCtx(),
user1, group2).size());
+
+ testContext.getStore().removeRelationships(testContext.getCtx(), user1, group1,
false);
+
+ assertEquals(0, testContext.getStore().resolveRelationships(testContext.getCtx(),
group1, user1).size());
+ assertEquals(0, testContext.getStore().resolveRelationships(testContext.getCtx(),
user1, group1).size());
+ assertEquals(0, testContext.getStore().resolveRelationships(testContext.getCtx(),
group2, user1).size());
+ assertEquals(0, testContext.getStore().resolveRelationships(testContext.getCtx(),
user1, group2).size());
+
+
+ testContext.commit();
+
+ }
+}
Added:
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/IdentityStoreTestContext.java
===================================================================
---
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/IdentityStoreTestContext.java
(rev 0)
+++
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/IdentityStoreTestContext.java 2008-10-15
10:59:42 UTC (rev 103)
@@ -0,0 +1,47 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, 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.jboss.identity.impl.store;
+
+import org.jboss.identity.spi.store.IdentityStore;
+import org.jboss.identity.spi.store.IdentityStoreInvocationContext;
+import junit.framework.TestCase;
+import junit.framework.Assert;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public interface IdentityStoreTestContext
+{
+
+ void begin() throws Exception;
+
+ void commit() throws Exception;
+
+ void flush() throws Exception;
+
+ IdentityStore getStore();
+
+ IdentityStoreInvocationContext getCtx();
+
+}
Modified:
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/hibernate/HibernateIdentityStoreTestCase.java
===================================================================
---
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/hibernate/HibernateIdentityStoreTestCase.java 2008-09-20
20:24:55 UTC (rev 102)
+++
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/hibernate/HibernateIdentityStoreTestCase.java 2008-10-15
10:59:42 UTC (rev 103)
@@ -24,10 +24,13 @@
import org.jboss.identity.spi.model.IdentityObject;
import org.jboss.identity.spi.store.IdentityStoreInvocationContext;
+import org.jboss.identity.spi.store.IdentityStore;
import org.jboss.identity.impl.store.hibernate.HibernateIdentityStoreImpl;
import org.jboss.identity.impl.store.hibernate.HibernateTestBase;
import org.jboss.identity.impl.store.RelationshipTypeEnum;
import org.jboss.identity.impl.store.IdentityTypeEnum;
+import org.jboss.identity.impl.store.CommonIdentityStoreTest;
+import org.jboss.identity.impl.store.IdentityStoreTestContext;
import org.hibernate.ejb.HibernateEntityManager;
import java.util.Collection;
@@ -40,14 +43,17 @@
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
* @version : 0.1 $
*/
-public class HibernateIdentityStoreTestCase extends HibernateTestBase
+public class HibernateIdentityStoreTestCase extends HibernateTestBase implements
IdentityStoreTestContext
{
protected HibernateIdentityStoreImpl store;
+ protected CommonIdentityStoreTest commonTest;
+
public HibernateIdentityStoreTestCase(String testName)
{
super(testName);
+ commonTest = new CommonIdentityStoreTest(this);
}
@Override
@@ -55,7 +61,8 @@
{
super.setUp();
- store = new HibernateIdentityStoreImpl(){
+ store = new HibernateIdentityStoreImpl()
+ {
protected HibernateEntityManager
getHibernateEntityManager(IdentityStoreInvocationContext ctx)
{
@@ -100,79 +107,50 @@
em.getTransaction().commit();
}
- public void testStorePersistence() throws Exception{
-
+ public void begin() throws Exception
+ {
em.getTransaction().begin();
- IdentityObject user1 = store.createIdentityObject(null, "Adam",
IdentityTypeEnum.USER);
- IdentityObject user2 = store.createIdentityObject(null, "Eva",
IdentityTypeEnum.USER);
+ }
- IdentityObject group1 = store.createIdentityObject(null, "Devision1",
IdentityTypeEnum.ORGANIZATION);
- IdentityObject group2 = store.createIdentityObject(null, "Devision2",
IdentityTypeEnum.ORGANIZATION);
- IdentityObject group3 = store.createIdentityObject(null, "Devision3",
IdentityTypeEnum.ORGANIZATION);
- IdentityObject group4 = store.createIdentityObject(null, "Devision4",
IdentityTypeEnum.ORGANIZATION);
-
- em.flush();
-
- assertEquals(0, store.getIdentityObjectsCount(null, IdentityTypeEnum.ROLE));
- assertEquals(2, store.getIdentityObjectsCount(null, IdentityTypeEnum.USER));
- assertEquals(4, store.getIdentityObjectsCount(null,
IdentityTypeEnum.ORGANIZATION));
-
- em.flush();
-
- store.removeIdentityObject(null, user1);
- store.removeIdentityObject(null, group1);
- store.removeIdentityObject(null, group2);
-
- assertEquals(1, store.getIdentityObjectsCount(null, IdentityTypeEnum.USER));
- assertEquals(2, store.getIdentityObjectsCount(null,
IdentityTypeEnum.ORGANIZATION));
-
- store.removeIdentityObject(null, user2);
- store.removeIdentityObject(null, group3);
- store.removeIdentityObject(null, group4);
-
- assertEquals(0, store.getIdentityObjectsCount(null, IdentityTypeEnum.USER));
- assertEquals(0, store.getIdentityObjectsCount(null,
IdentityTypeEnum.ORGANIZATION));
-
+ public void commit() throws Exception
+ {
em.getTransaction().commit();
+ }
+ public void flush() throws Exception
+ {
+ em.flush();
}
- public void testFindMethods() throws Exception{
+ public IdentityStore getStore()
+ {
+ return store;
+ }
- em.getTransaction().begin();
+ public IdentityStoreInvocationContext getCtx()
+ {
+ return null;
+ }
- IdentityObject user1 = store.createIdentityObject(null, "Adam",
IdentityTypeEnum.USER);
- IdentityObject user2 = store.createIdentityObject(null, "Eva",
IdentityTypeEnum.USER);
+ // Tests
- IdentityObject group1 = store.createIdentityObject(null, "Devision1",
IdentityTypeEnum.ORGANIZATION);
- IdentityObject group2 = store.createIdentityObject(null, "Devision2",
IdentityTypeEnum.ORGANIZATION);
- IdentityObject group3 = store.createIdentityObject(null, "Devision3",
IdentityTypeEnum.ORGANIZATION);
- IdentityObject group4 = store.createIdentityObject(null, "Devision4",
IdentityTypeEnum.ORGANIZATION);
+ public void testStorePersistence() throws Exception
+ {
- em.flush();
+ commonTest.testStorePersistence();
- IdentityObject xx = store.findIdentityObject(null, "Adam",
IdentityTypeEnum.USER);
- assertEquals(xx.getId(), user1.getId());
+ }
- xx = store.findIdentityObject(null, user2.getId());
- assertEquals(xx.getId(), user2.getId());
+ public void testFindMethods() throws Exception
+ {
- Collection results = store.findIdentityObject(null, IdentityTypeEnum.USER, 0, 0,
true, true);
- assertEquals(2, results.size());
+ commonTest.testFindMethods();
- results = store.findIdentityObject(null, IdentityTypeEnum.ORGANIZATION, 0, 0,
true, true);
- assertEquals(4, results.size());
-
- results = store.findIdentityObject(null, IdentityTypeEnum.ROLE, 0, 0, true,
true);
- assertEquals(0, results.size());
-
-
- em.getTransaction().commit();
-
}
- public void testAttributes() throws Exception{
+ public void testAttributes() throws Exception
+ {
em.getTransaction().begin();
@@ -236,82 +214,57 @@
em.flush();
- store.updateAttributes(null, user1, attrs);
+ vals = new HashSet<String>();
+ vals.add("val2");
+ attrs.put("key3", vals);
+ store.addAttributes(null, user1, attrs);
+
em.flush();
persistedAttrs = store.getAttributes(null, user1);
- assertEquals(1, persistedAttrs.keySet().size());
+ assertEquals(3, persistedAttrs.keySet().size());
assertTrue(persistedAttrs.containsKey("key3"));
- assertEquals(1, persistedAttrs.get("key3").size());
+ assertEquals(2, persistedAttrs.get("key3").size());
em.flush();
- Set<String> names = new HashSet<String>();
- names.add("key3");
- store.removeAttributes(null, user1, names);
+ store.updateAttributes(null, user1, attrs);
em.flush();
persistedAttrs = store.getAttributes(null, user1);
- assertEquals(0, persistedAttrs.keySet().size());
+ assertEquals(3, persistedAttrs.keySet().size());
+ assertTrue(persistedAttrs.containsKey("key3"));
+ assertEquals(1, persistedAttrs.get("key3").size());
- em.getTransaction().commit();
-
- }
-
- public void testRelationships() throws Exception{
-
- em.getTransaction().begin();
-
- IdentityObject user1 = store.createIdentityObject(null, "Adam",
IdentityTypeEnum.USER);
- IdentityObject user2 = store.createIdentityObject(null, "Eva",
IdentityTypeEnum.USER);
-
- IdentityObject group1 = store.createIdentityObject(null, "Devision1",
IdentityTypeEnum.ORGANIZATION);
- IdentityObject group2 = store.createIdentityObject(null, "Devision2",
IdentityTypeEnum.ORGANIZATION);
- IdentityObject group3 = store.createIdentityObject(null, "Devision3",
IdentityTypeEnum.ORGANIZATION);
- IdentityObject group4 = store.createIdentityObject(null, "Devision4",
IdentityTypeEnum.ORGANIZATION);
-
em.flush();
- store.createRelationship(null, group1, user1, RelationshipTypeEnum.MEMBER);
- store.createRelationship(null, group2, user1, RelationshipTypeEnum.MEMBER);
+ Set<String> names = new HashSet<String>();
+ names.add("key3");
+ store.removeAttributes(null, user1, names);
em.flush();
- assertEquals(1, store.resolveRelationships(null, group1, user1).size());
- assertEquals(0, store.resolveRelationships(null, user1, group1).size());
- assertEquals(1, store.resolveRelationships(null, group2, user1).size());
- assertEquals(0, store.resolveRelationships(null, user1, group2).size());
+ persistedAttrs = store.getAttributes(null, user1);
- store.removeRelationship(null, group2, user1, RelationshipTypeEnum.MEMBER);
+ assertEquals(2, persistedAttrs.keySet().size());
- em.flush();
- assertEquals(1, store.resolveRelationships(null, group1, user1).size());
- assertEquals(0, store.resolveRelationships(null, user1, group1).size());
- assertEquals(0, store.resolveRelationships(null, group2, user1).size());
- assertEquals(0, store.resolveRelationships(null, user1, group2).size());
-
- store.removeRelationships(null, user1, group1);
-
- assertEquals(0, store.resolveRelationships(null, group1, user1).size());
- assertEquals(0, store.resolveRelationships(null, user1, group1).size());
- assertEquals(0, store.resolveRelationships(null, group2, user1).size());
- assertEquals(0, store.resolveRelationships(null, user1, group2).size());
-
-
em.getTransaction().commit();
}
+ public void testRelationships() throws Exception
+ {
+ commonTest.testRelationships();
+ }
-
}
Modified:
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/ldap/LDAPIdentityStoreTestCase.java
===================================================================
---
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/ldap/LDAPIdentityStoreTestCase.java 2008-09-20
20:24:55 UTC (rev 102)
+++
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/ldap/LDAPIdentityStoreTestCase.java 2008-10-15
10:59:42 UTC (rev 103)
@@ -25,8 +25,11 @@
import junit.framework.TestCase;
import org.jboss.identity.opends.OpenDSService;
import org.jboss.identity.spi.store.IdentityStore;
+import org.jboss.identity.spi.store.IdentityStoreInvocationContext;
import org.jboss.identity.spi.model.IdentityObject;
import org.jboss.identity.impl.store.IdentityTypeEnum;
+import org.jboss.identity.impl.store.CommonIdentityStoreTest;
+import org.jboss.identity.impl.store.IdentityStoreTestContext;
import org.opends.server.tools.LDAPModify;
import javax.naming.Context;
@@ -40,15 +43,19 @@
import java.util.Hashtable;
import java.util.Map;
import java.util.HashMap;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.logging.Logger;
+import java.util.logging.Level;
import java.io.File;
/**
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
* @version : 0.1 $
*/
-public class LDAPIdentityStoreTestCase extends TestCase
+public class LDAPIdentityStoreTestCase extends TestCase implements
IdentityStoreTestContext
{
-
+
public static final String LDAP_HOST = "localhost";
public static final String LDAP_PORT = "10389";
@@ -63,8 +70,15 @@
IdentityStore store;
+ CommonIdentityStoreTest commonTest;
+
LDAPIdentityStoreInvocationContext ctx;
+ public LDAPIdentityStoreTestCase(String s)
+ {
+ super(s);
+ commonTest = new CommonIdentityStoreTest(this);
+ }
protected void setUp() throws Exception
{
@@ -75,16 +89,14 @@
// Initiate invocation context with simple configuration
initiateCtx();
- populate();
+// populate();
- store = new LDAPIdentityStore();
+ store = new LDAPIdentityStore("simpleTestLDAPStore");
}
-
-
protected void tearDown() throws Exception
{
super.tearDown();
@@ -94,92 +106,49 @@
openDSService.stop();
}
- // Just test if OpenDS is running and was populated...
- public void testSimple() throws Exception
+ public void begin() throws Exception
{
- Hashtable<String,String> env = new Hashtable<String,String>();
- env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
- env.put(Context.PROVIDER_URL, LDAP_PROVIDER_URL);
- env.put(Context.SECURITY_AUTHENTICATION, "simple");
- env.put(Context.SECURITY_PRINCIPAL, LDAP_PRINCIPAL);
- env.put(Context.SECURITY_CREDENTIALS, LDAP_CREDENTIALS);
+ //nothing
+ }
- LdapContext ldapCtx = null;
- try
- {
- ldapCtx = new InitialLdapContext(env, null);
+ public void commit() throws Exception
+ {
+ //nothing
+ }
-// Do something ...
- System.out.println("Attributes: " +
ldapCtx.getAttributes("o=test,dc=portal,dc=example,dc=com"));
-
- }
- catch (NamingException e)
- {
- e.printStackTrace();
- }
- finally
- {
- try
- {
- if (ldapCtx != null)
- {
- ldapCtx.close();
- }
- }
- catch (NamingException e)
- {
- e.printStackTrace();
- }
- }
+ public void flush() throws Exception
+ {
+ //nothing
}
- public void testIdentityObjectCount() throws Exception
+ public IdentityStore getStore()
{
- assertEquals(7, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.USER));
- assertEquals(5, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.ROLE));
- assertEquals(2, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.GROUP));
+ return store;
}
- public void testFindCreateRemove() throws Exception
+ public IdentityStoreInvocationContext getCtx()
{
- assertEquals(7, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.USER));
+ return ctx;
+ }
- IdentityObject io = store.findIdentityObject(ctx, "admin",
IdentityTypeEnum.USER);
- assertEquals("admin", io.getName());
- assertEquals("uid=admin,ou=People,o=test,dc=portal,dc=example,dc=com",
io.getId().toString());
- //
- store.removeIdentityObject(ctx, io);
- assertEquals(6, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.USER));
- store.createIdentityObject(ctx, "newUserA", IdentityTypeEnum.USER);
+ public void populate() throws Exception
+ {
+ populateLDIF("target/test-classes/ldap/initial-opends.ldif");
+ }
- assertEquals(7, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.USER));
-
- //
-
- assertEquals(2, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.GROUP));
-
- store.createIdentityObject(ctx, "newGroupA", IdentityTypeEnum.GROUP);
-
- assertEquals(3, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.GROUP));
-
- //
-
- io = store.findIdentityObject(ctx,
"cn=newGroupA,ou=Groups,o=test,dc=portal,dc=example,dc=com");
- assertEquals("newGroupA", io.getName());
-
+ public void populateClean() throws Exception
+ {
+ populateLDIF("target/test-classes/ldap/initial-empty-opends.ldif");
}
-
- public void populate() throws Exception
+ public void populateLDIF(String ldifRelativePath) throws Exception
{
- ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+ File ldif = new File(ldifRelativePath);
- File ldif = new File("target/test-classes/ldap/initial-opends.ldif");
-
System.out.println("LDIF: " + ldif.getAbsolutePath());
String[] cmd = new String[] {"-h", LDAP_HOST,
@@ -238,7 +207,9 @@
tc.setAllowedMembershipTypes(new String[] {});
tc.setAllowEmptyMemberships(true);
Map<String, String> attrs = new HashMap<String, String>();
- //attrs.put();
+ attrs.put("phone", "telephoneNumber");
+ attrs.put("description", "description");
+ attrs.put("carLicense", "carLicense");
tc.setAttributeNames(attrs);
Map<String, String[]> newAttrs = new HashMap<String, String[]>();
newAttrs.put("objectClass", new String[]{"top",
"inetOrgPerson"});
@@ -253,10 +224,11 @@
tc.setMembershipAttributeName(null);
typesMap.put(IdentityTypeEnum.USER.getName(), tc);
+
// ROLE
tc = new SimpleLDAPIdentityObjectTypeConfiguration();
tc.setAllowCreateEntry(true);
- tc.setAllowedMembershipTypes(new String[] {});
+ tc.setAllowedMembershipTypes(new String[] {IdentityTypeEnum.USER.getName()});
tc.setAllowEmptyMemberships(true);
attrs = new HashMap<String, String>();
//attrs.put();
@@ -274,7 +246,7 @@
// GROUP
tc = new SimpleLDAPIdentityObjectTypeConfiguration();
tc.setAllowCreateEntry(true);
- tc.setAllowedMembershipTypes(new String[] {});
+ tc.setAllowedMembershipTypes(new String[] {IdentityTypeEnum.USER.getName(),
IdentityTypeEnum.ROLE.getName(), IdentityTypeEnum.GROUP.getName()});
tc.setAllowEmptyMemberships(true);
attrs = new HashMap<String, String>();
//attrs.put();
@@ -290,7 +262,26 @@
tc.setMembershipAttributeName("member");
typesMap.put(IdentityTypeEnum.GROUP.getName(), tc);
+ // ORGANIZATION
+ tc = new SimpleLDAPIdentityObjectTypeConfiguration();
+ tc.setAllowCreateEntry(true);
+ tc.setAllowedMembershipTypes(new String[] {IdentityTypeEnum.USER.getName(),
IdentityTypeEnum.ROLE.getName(), IdentityTypeEnum.GROUP.getName()});
+ tc.setAllowEmptyMemberships(true);
+ attrs = new HashMap<String, String>();
+ //attrs.put();
+ tc.setAttributeNames(attrs);
+ newAttrs = new HashMap<String, String[]>();
+ newAttrs.put("objectClass", new String[]{"top",
"groupOfNames"});
+ tc.setCreateEntryAttributeValues(newAttrs);
+ tc.setCtxDNs(new String[]
{"ou=Organizations,o=test,dc=portal,dc=example,dc=com"});
+ tc.setEntrySearchFilter(null);
+ tc.setIdAttributeName("cn");
+ tc.setMembershipAttributeDN(true);
+ tc.setMembershipAttributeName("member");
+ typesMap.put(IdentityTypeEnum.ORGANIZATION.getName(), tc);
+
+
SimpleLDAPIdentityStoreConfiguration configuration =
new SimpleLDAPIdentityStoreConfiguration(
LDAP_PROVIDER_URL,
@@ -302,4 +293,222 @@
ctx = new SimpleLDAPIdentityStoreInvocationContext(configuration);
}
+
+ // Tests
+
+ // Just test if OpenDS is running and was populated...
+// public void testSimple() throws Exception
+// {
+// populate();
+//
+// Hashtable<String,String> env = new Hashtable<String,String>();
+// env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
+// env.put(Context.PROVIDER_URL, LDAP_PROVIDER_URL);
+// env.put(Context.SECURITY_AUTHENTICATION, "simple");
+// env.put(Context.SECURITY_PRINCIPAL, LDAP_PRINCIPAL);
+// env.put(Context.SECURITY_CREDENTIALS, LDAP_CREDENTIALS);
+//
+// LdapContext ldapCtx = null;
+// try
+// {
+// ldapCtx = new InitialLdapContext(env, null);
+//
+//// Do something ...
+// System.out.println("Attributes: " +
ldapCtx.getAttributes("o=test,dc=portal,dc=example,dc=com"));
+//
+// }
+// catch (NamingException e)
+// {
+// e.printStackTrace();
+// }
+// finally
+// {
+// try
+// {
+// if (ldapCtx != null)
+// {
+// ldapCtx.close();
+// }
+// }
+// catch (NamingException e)
+// {
+// e.printStackTrace();
+// }
+// }
+// }
+//
+// public void testIdentityObjectCount() throws Exception
+// {
+// populate();
+//
+// assertEquals(7, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.USER));
+// assertEquals(5, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.ROLE));
+// assertEquals(2, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.GROUP));
+// }
+//
+// public void testFindCreateRemove() throws Exception
+// {
+// populate();
+//
+// assertEquals(7, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.USER));
+//
+// IdentityObject io = store.findIdentityObject(ctx, "admin",
IdentityTypeEnum.USER);
+// assertEquals("admin", io.getName());
+// assertEquals("uid=admin,ou=People,o=test,dc=portal,dc=example,dc=com",
io.getId().toString());
+//
+// //
+//
+// store.removeIdentityObject(ctx, io);
+//
+// assertEquals(6, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.USER));
+//
+// store.createIdentityObject(ctx, "newUserA", IdentityTypeEnum.USER);
+//
+// assertEquals(7, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.USER));
+//
+// //
+//
+// assertEquals(2, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.GROUP));
+//
+// store.createIdentityObject(ctx, "newGroupA", IdentityTypeEnum.GROUP);
+//
+// assertEquals(3, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.GROUP));
+//
+// //
+//
+// io = store.findIdentityObject(ctx,
"cn=newGroupA,ou=Groups,o=test,dc=portal,dc=example,dc=com");
+// assertEquals("newGroupA", io.getName());
+//
+// }
+//
+// public void testAttributes() throws Exception{
+//
+// populate();
+//
+// IdentityObject user1 = store.createIdentityObject(ctx, "Adam",
IdentityTypeEnum.USER);
+// IdentityObject user2 = store.createIdentityObject(ctx, "Eva",
IdentityTypeEnum.USER);
+//
+// //
+//
+// Map<String, Set<String>> attrs = new HashMap<String,
Set<String>>();
+// HashSet<String> vals = new HashSet<String>();
+// vals.add("val1");
+// vals.add("val2");
+// vals.add("val3");
+//
+// attrs.put("phone", vals);
+//
+// vals = new HashSet<String>();
+// vals.add("val1");
+// vals.add("val2");
+// vals.add("val3");
+// vals.add("val4");
+// attrs.put("description", vals);
+//
+// store.addAttributes(ctx, user1, attrs);
+//
+// //
+//
+// Map<String, Set<String>> persistedAttrs = store.getAttributes(ctx,
user1);
+//
+// assertEquals(2, persistedAttrs.keySet().size());
+//
+// assertTrue(persistedAttrs.containsKey("phone"));
+// assertEquals(3, persistedAttrs.get("phone").size());
+//
+// assertTrue(persistedAttrs.containsKey("description"));
+// assertEquals(4, persistedAttrs.get("description").size());
+//
+// //
+//
+// attrs = new HashMap<String, Set<String>>();
+// vals = new HashSet<String>();
+// vals.add("val1");
+// attrs.put("carLicense", vals);
+//
+// store.addAttributes(ctx, user1, attrs);
+//
+// //
+//
+// persistedAttrs = store.getAttributes(ctx, user1);
+//
+// assertEquals(3, persistedAttrs.keySet().size());
+//
+// assertTrue(persistedAttrs.containsKey("phone"));
+// assertEquals(3, persistedAttrs.get("phone").size());
+//
+// assertTrue(persistedAttrs.containsKey("description"));
+// assertEquals(4, persistedAttrs.get("description").size());
+//
+// assertTrue(persistedAttrs.containsKey("carLicense"));
+// assertEquals(1, persistedAttrs.get("carLicense").size());
+//
+// //
+//
+// vals = new HashSet<String>();
+// vals.add("val2");
+// attrs.put("carLicense", vals);
+//
+// store.addAttributes(ctx, user1, attrs);
+//
+// //
+//
+// persistedAttrs = store.getAttributes(ctx, user1);
+//
+// assertEquals(3, persistedAttrs.keySet().size());
+//
+// assertTrue(persistedAttrs.containsKey("carLicense"));
+// assertEquals(2, persistedAttrs.get("carLicense").size());
+//
+// //
+//
+// store.updateAttributes(ctx, user1, attrs);
+//
+// //
+//
+// persistedAttrs = store.getAttributes(ctx, user1);
+//
+// assertEquals(3, persistedAttrs.keySet().size());
+//
+// assertTrue(persistedAttrs.containsKey("carLicense"));
+// assertEquals(1, persistedAttrs.get("carLicense").size());
+//
+// //
+//
+// Set<String> names = new HashSet<String>();
+// names.add("carLicense");
+// store.removeAttributes(ctx, user1, names);
+//
+// //
+//
+// persistedAttrs = store.getAttributes(ctx, user1);
+//
+// assertEquals(2, persistedAttrs.keySet().size());
+//
+// }
+
+ public void testRelationships() throws Exception
+ {
+ populateClean();
+
+ commonTest.testRelationships();
+
+ }
+
+// public void testStorePersistence() throws Exception
+// {
+// populateClean();
+//
+// commonTest.testStorePersistence();
+//
+// }
+//
+// public void testFindMethods() throws Exception
+// {
+// populateClean();
+//
+// commonTest.testFindMethods();
+//
+// }
+
}
Modified:
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/ldap/SimpleLDAPIdentityObjectTypeConfiguration.java
===================================================================
---
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/ldap/SimpleLDAPIdentityObjectTypeConfiguration.java 2008-09-20
20:24:55 UTC (rev 102)
+++
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/ldap/SimpleLDAPIdentityObjectTypeConfiguration.java 2008-10-15
10:59:42 UTC (rev 103)
@@ -23,6 +23,8 @@
package org.jboss.identity.impl.store.ldap;
import java.util.Map;
+import java.util.Set;
+import java.util.Collections;
/**
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
@@ -122,7 +124,7 @@
return allowEmptyMemberships;
}
- public String getAttributeName(String name)
+ public String getAttributeMapping(String name)
{
return attributeNames.get(name);
}
@@ -176,4 +178,9 @@
{
this.attributeNames = attributeNames;
}
+
+ public Set<String> getMappedAttributesNames()
+ {
+ return Collections.unmodifiableSet(attributeNames.keySet());
+ }
}
Modified: trunk/identity-impl/src/test/resources/META-INF/persistence.xml
===================================================================
--- trunk/identity-impl/src/test/resources/META-INF/persistence.xml 2008-09-20 20:24:55
UTC (rev 102)
+++ trunk/identity-impl/src/test/resources/META-INF/persistence.xml 2008-10-15 10:59:42
UTC (rev 103)
@@ -14,6 +14,7 @@
<class>org.jboss.identity.impl.model.hibernate.HibernateIdentityObjectType</class>
<class>org.jboss.identity.impl.model.hibernate.HibernateIdentityObjectRelationship</class>
<class>org.jboss.identity.impl.model.hibernate.HibernateIdentityObjectRelationshipType</class>
+
<class>org.jboss.identity.impl.model.hibernate.HibernateIdentityObjectRelationshipName</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
Modified: trunk/identity-impl/src/test/resources/ldap/initial-empty-opends.ldif
===================================================================
--- trunk/identity-impl/src/test/resources/ldap/initial-empty-opends.ldif 2008-09-20
20:24:55 UTC (rev 102)
+++ trunk/identity-impl/src/test/resources/ldap/initial-empty-opends.ldif 2008-10-15
10:59:42 UTC (rev 103)
@@ -1,9 +1,9 @@
-#dn: dc=portal,dc=example,dc=com
-#objectclass: top
-#objectclass: dcObject
-#objectclass: organization
-#o: portal
-#dc: portal
+dn: dc=portal,dc=example,dc=com
+objectclass: top
+objectclass: dcObject
+objectclass: organization
+o: portal
+dc: portal
dn: o=test,dc=portal,dc=example,dc=com
objectclass: top
@@ -25,4 +25,8 @@
objectclass: organizationalUnit
ou: Groups
+dn: ou=Organizations,o=test,dc=portal,dc=example,dc=com
+objectclass: top
+objectclass: organizationalUnit
+ou: Groups
Added:
trunk/identity-spi/src/main/java/org/jboss/identity/spi/exception/OperationNotSupportedException.java
===================================================================
---
trunk/identity-spi/src/main/java/org/jboss/identity/spi/exception/OperationNotSupportedException.java
(rev 0)
+++
trunk/identity-spi/src/main/java/org/jboss/identity/spi/exception/OperationNotSupportedException.java 2008-10-15
10:59:42 UTC (rev 103)
@@ -0,0 +1,47 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, 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.jboss.identity.spi.exception;
+
+import org.jboss.identity.exception.IdentityException;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class OperationNotSupportedException extends Exception
+{
+ public OperationNotSupportedException(String message)
+ {
+ super(message);
+ }
+
+ public OperationNotSupportedException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public OperationNotSupportedException(Throwable cause)
+ {
+ super(cause);
+ }
+}
Modified:
trunk/identity-spi/src/main/java/org/jboss/identity/spi/model/IdentityObjectRelationship.java
===================================================================
---
trunk/identity-spi/src/main/java/org/jboss/identity/spi/model/IdentityObjectRelationship.java 2008-09-20
20:24:55 UTC (rev 102)
+++
trunk/identity-spi/src/main/java/org/jboss/identity/spi/model/IdentityObjectRelationship.java 2008-10-15
10:59:42 UTC (rev 103)
@@ -30,10 +30,19 @@
{
/**
+ * @return Relationship name or null if this relationship is not named
+ */
+ String getName();
+
+ /**
*
* @return
*/
IdentityObjectRelationshipType getType();
- //TODO: Does it make sense to add a name?
+ IdentityObject getFromIdentityObject();
+
+ IdentityObject getToIdentityObject();
+
+
}
Modified:
trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/AttributeStore.java
===================================================================
---
trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/AttributeStore.java 2008-09-20
20:24:55 UTC (rev 102)
+++
trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/AttributeStore.java 2008-10-15
10:59:42 UTC (rev 103)
@@ -30,7 +30,7 @@
import java.util.Map;
/**
- * Store for identity related attributes. Its separat interface as there is possible need
to store profiles in a
+ * Store for identity related attributes. Its separate interface as there is possible
need to store profiles in a
* distributted way (part in LDAP part in DB).
*
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
@@ -58,7 +58,7 @@
Map<String, Set<String>> getAttributes(IdentityStoreInvocationContext
invocationContext, IdentityObject identity) throws IdentityException;
/**
- * Update attributes with new values - previous values will be overwritten
+ * Update attributes with new values - previous values will be overwritten. Attributes
not specified in the map are not changed.
* @param invocationCtx
*@param identity
* @param attributes @throws IdentityException
Modified:
trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/IdentityStore.java
===================================================================
---
trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/IdentityStore.java 2008-09-20
20:24:55 UTC (rev 102)
+++
trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/IdentityStore.java 2008-10-15
10:59:42 UTC (rev 103)
@@ -29,10 +29,13 @@
import org.jboss.identity.spi.model.IdentityObject;
import org.jboss.identity.spi.model.IdentityObjectType;
import org.jboss.identity.spi.model.IdentityObjectRelationshipType;
+import org.jboss.identity.spi.model.IdentityObjectRelationship;
+import org.jboss.identity.spi.exception.OperationNotSupportedException;
import org.jboss.identity.exception.IdentityException;
/**
* Represents an Identity Store
+ *
* @author boleslaw dot dawidowicz at redhat anotherdot com
* @author Anil.Saldhana(a)redhat.com
* @since Jul 10, 2008
@@ -43,7 +46,7 @@
* Set up the store
*/
void bootstrap() throws IOException;
-
+
/**
* @return id of this identity store
*/
@@ -51,12 +54,11 @@
/**
- * @return FeaturesDescription object describing what
- * operation are supported by this store
+ * @return FeaturesDescription object describing what
+ * operation are supported by this store
*/
FeaturesDescription getSupportedFeatures();
-
// Operations
/**
@@ -87,7 +89,7 @@
* @throws IdentityException
*/
int getIdentityObjectsCount(IdentityStoreInvocationContext invocationCtx,
IdentityObjectType identityType)
- throws IdentityException;
+ throws IdentityException;
/**
* Find identity with a given name
@@ -111,27 +113,29 @@
IdentityObject findIdentityObject(IdentityStoreInvocationContext invocationContext,
Object id) throws IdentityException;
/**
- * Find identities with a given type paginated and ordered.
+ * Find identities with a given type paginated and ordered.
* If the paginatedSearch or orderedSearch operations
- * are not supported in this store implementation, dedicated
+ * are not supported in this store implementation, dedicated
* parameters will take no effect
*
* @param invocationCtx
* @param identityType
+ * @param nameFilter may be null
* @param offset
- * @param limit 0 means unlimited page size
+ * @param limit 0 means unlimited page size
* @param orderByName
- * @param ascending default true
+ * @param ascending default true
* @return
* @throws IdentityException
*/
Collection<IdentityObject> findIdentityObject(IdentityStoreInvocationContext
invocationCtx, IdentityObjectType identityType,
+ String nameFilter,
int offset, int limit,
boolean orderByName,
boolean ascending) throws
IdentityException;
/**
- * Find identities with a given attributes values. If the paginatedSearch or
+ * Find identities with a given attributes values. If the paginatedSearch or
* orderedSearch operations
* are not supported in this store implementation, dedicated parameters will take no
effect
*
@@ -139,9 +143,9 @@
* @param identityType
* @param attributes
* @param offset
- * @param limit 0 means unlimited page size
+ * @param limit 0 means unlimited page size
* @param orderByName
- * @param ascending default true
+ * @param ascending
* @return
* @throws IdentityException
*/
@@ -153,18 +157,18 @@
/**
* Find identites that have relationship with given identity. Relationships are
directional (from parent to child).
* If the paginatedSearch or orderedSearch operations
- * are not supported in this store implementation, dedicated parameters will
+ * are not supported in this store implementation, dedicated parameters will
* take no effect
*
* @param invocationCxt
* @param identity
* @param relationshipType
- * @param parent defines if given identity is parent or child side in the
- * relationship - default is true (parent)
+ * @param parent defines if given identity is parent or child side in the
+ * relationship - default is true (parent)
* @param offset
- * @param limit 0 means unlimited page size
+ * @param limit 0 means unlimited page size
* @param orderByName
- * @param ascending default true
+ * @param ascending
* @return
* @throws IdentityException
*/
@@ -175,7 +179,6 @@
boolean orderByName,
boolean ascending) throws
IdentityException;
-
/**
* Create directional relationship of a given type between identities
@@ -184,42 +187,46 @@
* @param fromIdentity
* @param toIdentity
* @param relationshipType
+ * @param relationshipName
+ * @param createNames
* @throws IdentityException
*/
void createRelationship(IdentityStoreInvocationContext invocationCxt, IdentityObject
fromIdentity,
IdentityObject toIdentity,
- IdentityObjectRelationshipType relationshipType) throws
IdentityException;
+ IdentityObjectRelationshipType relationshipType, String
relationshipName, boolean createNames) throws IdentityException;
/**
- * Remove relationship between identities. Relationships can be directional so
- * order of parameters matters
+ * Remove relationship between identities. Relationships can be directional so
+ * order of parameters matters
*
* @param invocationCxt
* @param fromIdentity
* @param toIdentity
* @param relationshipType
+ * @param relationshipName
* @throws IdentityException
*/
void removeRelationship(IdentityStoreInvocationContext invocationCxt, IdentityObject
fromIdentity,
IdentityObject toIdentity,
- IdentityObjectRelationshipType relationshipType) throws
IdentityException;
+ IdentityObjectRelationshipType relationshipType, String
relationshipName) throws IdentityException;
/**
- * Remove all relationships between identities. Direction of relationships doesn't
+ * Remove all relationships between identities. Direction of relationships
doesn't
* matter - all active relationships
* will be removed
- *
+ *
* @param invocationCtx
* @param identity1
* @param identity2
- * @return
+ * @param named if false method will remove only relationship withot names. Default is
true
+ * @return
* @throws IdentityException
*/
- void removeRelationships(IdentityStoreInvocationContext invocationCtx, IdentityObject
identity1, IdentityObject identity2)
- throws IdentityException;
+ void removeRelationships(IdentityStoreInvocationContext invocationCtx, IdentityObject
identity1, IdentityObject identity2, boolean named)
+ throws IdentityException;
/**
- * Resolve relationship types between two identities. Relationships can be directional
+ * Resolve relationship types between two identities. Relationships can be
directional
* so order of parameters matters
*
* @param invocationCxt
@@ -228,7 +235,89 @@
* @return
* @throws IdentityException
*/
- Set<IdentityObjectRelationshipType>
resolveRelationships(IdentityStoreInvocationContext invocationCxt, IdentityObject
fromIdentity, IdentityObject toIdentity)
- throws IdentityException;
-
+ Set<IdentityObjectRelationship>
resolveRelationships(IdentityStoreInvocationContext invocationCxt, IdentityObject
fromIdentity, IdentityObject toIdentity)
+ throws IdentityException;
+
+
+ // Named relationships
+
+ /**
+ *
+ * @param ctx
+ * @param name
+ * @return
+ */
+ String createRelationshipName(IdentityStoreInvocationContext ctx, String name) throws
IdentityException, OperationNotSupportedException;
+
+ /**
+ *
+ * @param ctx
+ * @param name
+ * @return
+ */
+ String removeRelationshipName(IdentityStoreInvocationContext ctx, String name) throws
IdentityException, OperationNotSupportedException;
+
+
+ /**
+ *
+ * @param ctx
+ * @param offset
+ * @param limit
+ * @param orderByName
+ * @param ascending
+ * @return
+ * @throws IdentityException
+ */
+ Set<String> getRelationshipNames(IdentityStoreInvocationContext ctx,
+ int offset, int limit,
+ boolean orderByName,
+ boolean ascending) throws
IdentityException, OperationNotSupportedException;
+
+ /**
+ *
+ * @param ctx
+ * @param identity
+ * @param offset
+ * @param limit
+ * @param orderByName
+ * @param ascending
+ * @return
+ * @throws IdentityException
+ */
+ Set<String> getRelationshipNames(IdentityStoreInvocationContext ctx,
IdentityObject identity,
+ int offset, int limit,
+ boolean orderByName,
+ boolean ascending) throws
IdentityException, OperationNotSupportedException;
+
+
+ // Passwords
+
+ /**
+ *
+ * @param ctx
+ * @param type
+ * @return
+ * @throws IdentityException
+ */
+ boolean hasPasswordAttribute(IdentityStoreInvocationContext ctx, IdentityObjectType
type) throws IdentityException;
+
+ /**
+ *
+ * @param ctx
+ * @param identityObject
+ * @param password
+ * @return
+ * @throws IdentityException
+ */
+ boolean validatePassword(IdentityStoreInvocationContext ctx, IdentityObject
identityObject, String password) throws IdentityException;
+
+ /**
+ *
+ * @param ctx
+ * @param identityObject
+ * @param password
+ * @throws IdentityException
+ */
+ void updatePassword(IdentityStoreInvocationContext ctx, IdentityObject identityObject,
String password) throws IdentityException;
+
}
\ No newline at end of file
Modified:
trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/OperationType.java
===================================================================
---
trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/OperationType.java 2008-09-20
20:24:55 UTC (rev 102)
+++
trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/OperationType.java 2008-10-15
10:59:42 UTC (rev 103)
@@ -48,9 +48,12 @@
paginatedSearch,
// ordering in findIdentities
- orderedSearch;
+ orderedSearch,
+ // names of relationships;
+ namedRelationships;
+
public String getName()
{
return this.name();
Modified: trunk/parent/pom.xml
===================================================================
--- trunk/parent/pom.xml 2008-09-20 20:24:55 UTC (rev 102)
+++ trunk/parent/pom.xml 2008-10-15 10:59:42 UTC (rev 103)
@@ -45,7 +45,7 @@
<disableXmlReport>false</disableXmlReport>
<testFailureIgnore>false</testFailureIgnore>
<includes>
- <include>**/**TestCase.java</include>
+ <include>**/*TestCase.java</include>
</includes>
<forkMode>pertest</forkMode>
<argLine>${surefire.jvm.args}</argLine>