JBoss Identity SVN: r107 - trunk/identity-impl/src/main/java/org/jboss/identity/impl/api.
by jboss-identity-commits@lists.jboss.org
Author: bdaw
Date: 2008-10-21 07:05:46 -0400 (Tue, 21 Oct 2008)
New Revision: 107
Removed:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/ProfileManagerImpl.java
Log:
Cleanup
Deleted: trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/ProfileManagerImpl.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/ProfileManagerImpl.java 2008-10-21 10:51:41 UTC (rev 106)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/ProfileManagerImpl.java 2008-10-21 11:05:46 UTC (rev 107)
@@ -1,111 +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.impl.api;
-
-import org.jboss.identity.api.IdentitySession;
-import org.jboss.identity.api.ProfileManager;
-import org.jboss.identity.api.IdentityType;
-import org.jboss.identity.exception.IdentityException;
-
-import java.util.Set;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.HashSet;
-import java.util.Collections;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
- * @version : 0.1 $
- */
-public class ProfileManagerImpl extends AbstractManager implements ProfileManager
-{
- public ProfileManagerImpl(IdentitySession session)
- {
- super(session);
- }
-
- //TODO: fix to have similar signatures in API/SPI for String[] and avoid unnesesary iterations
-
- public Set<String> getSupportedAttributeNames(IdentityType identityType) throws IdentityException
- {
- return getRepository().getSupportedAttributeNames(getInvocationContext(), createIdentityObject(identityType).getIdentityType());
- }
-
- public Map<String, String[]> getAttributes(IdentityType identity) throws IdentityException
- {
- Map<String, Set<String>> attributes = getRepository().getAttributes(getInvocationContext(), createIdentityObject(identity));
-
- Map<String, String[]> attrs = new HashMap<String, String[]>();
-
- for (Map.Entry<String, Set<String>> entry : attributes.entrySet())
- {
- attrs.put(entry.getKey(), entry.getValue().toArray(new String[entry.getValue().size()]));
- }
-
- return attrs;
- }
-
- public void updateAttributes(IdentityType identity, Map<String, String[]> attributes) throws IdentityException
- {
- Map<String, Set<String>> attrs = new HashMap<String, Set<String>>();
-
- for (Map.Entry<String, String[]> entry : attributes.entrySet())
- {
- Set<String> vals = new HashSet<String>();
- for (String s : entry.getValue())
- {
- vals.add(s);
- }
-
- attrs.put(entry.getKey(),vals);
- }
-
- getRepository().updateAttributes(getInvocationContext(), createIdentityObject(identity), attrs);
-
- }
-
- public void addAttributes(IdentityType identity, Map<String, String[]> attributes) throws IdentityException
- {
- Map<String, Set<String>> attrs = new HashMap<String, Set<String>>();
-
- for (Map.Entry<String, String[]> entry : attributes.entrySet())
- {
- Set<String> vals = new HashSet<String>();
- for (String s : entry.getValue())
- {
- vals.add(s);
- }
-
- attrs.put(entry.getKey(),vals);
- }
-
- getRepository().addAttributes(getInvocationContext(), createIdentityObject(identity), attrs);
- }
-
- public void removeAttributes(IdentityType identity, Set<String> attributes) throws IdentityException
- {
- getRepository().removeAttributes(getInvocationContext(), createIdentityObject(identity), attributes);
-
- }
-}
16 years, 2 months
JBoss Identity SVN: r106 - in trunk: identity-api/src/main/java/org/jboss/identity/api/exception and 11 other directories.
by jboss-identity-commits@lists.jboss.org
Author: bdaw
Date: 2008-10-21 06:51:41 -0400 (Tue, 21 Oct 2008)
New Revision: 106
Added:
trunk/identity-api/src/main/java/org/jboss/identity/api/AttributesManager.java
trunk/identity-common/src/main/java/org/jboss/identity/exception/FeatureNotSupportedException.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/AttributesManagerImpl.java
Removed:
trunk/identity-api/src/main/java/org/jboss/identity/api/ProfileManager.java
trunk/identity-api/src/main/java/org/jboss/identity/api/SessionState.java
trunk/identity-api/src/main/java/org/jboss/identity/api/exception/PersistenceManagerNotFoundException.java
trunk/identity-api/src/main/java/org/jboss/identity/api/exception/SessionNotOpenException.java
trunk/identity-spi/src/main/java/org/jboss/identity/spi/attribute/PasswordAttribute.java
Modified:
trunk/identity-api/src/main/java/org/jboss/identity/api/Group.java
trunk/identity-api/src/main/java/org/jboss/identity/api/GroupType.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/IdentitySessionFactory.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/Realm.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-api/src/main/java/org/jboss/identity/api/RoleManager.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentitySessionImpl.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/PersistenceManagerImpl.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/helper/LDAPTools.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/hibernate/HibernateIdentityObjectAttribute.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/ldap/LDAPIdentityObjectRelationshipImpl.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/HibernateTestSupport.java
trunk/identity-spi/src/main/java/org/jboss/identity/spi/exception/OperationNotSupportedException.java
trunk/identity-spi/src/main/java/org/jboss/identity/spi/repository/IdentityStoreRepository.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/IdentityStoreInvocationContext.java
Log:
Cleanup
Copied: trunk/identity-api/src/main/java/org/jboss/identity/api/AttributesManager.java (from rev 101, trunk/identity-api/src/main/java/org/jboss/identity/api/ProfileManager.java)
===================================================================
--- trunk/identity-api/src/main/java/org/jboss/identity/api/AttributesManager.java (rev 0)
+++ trunk/identity-api/src/main/java/org/jboss/identity/api/AttributesManager.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -0,0 +1,117 @@
+/*
+* 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.Set;
+import java.util.Map;
+
+/**
+ * All operations on attributes
+ *
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public interface AttributesManager
+{
+
+ /**
+ * @return Session associated with this object instance
+ */
+ IdentitySession getIdentitySession();
+
+ //TODO: Add FeaturesDescription
+
+ /**
+ * @param identityType
+ * @return names of supported attributes
+ * @throws org.jboss.identity.exception.IdentityException
+ */
+ Set<String> getSupportedAttributeNames(IdentityType identityType)
+ throws IdentityException;
+
+ /**
+ * Get attributes for the given IdentityType
+ *
+ * @param identity
+ * @return
+ * @throws org.jboss.identity.exception.IdentityException
+ */
+ Map<String, String[]> getAttributes(IdentityType identity) throws IdentityException;
+
+ /**
+ * Update attributes with new values - previous values will be overwritten. All the other attributes are not changed -
+ * method doesn't overwrite whole attribute set connected with a given IdentityType object.
+ * @param identity
+ * @param attributes
+ * @throws org.jboss.identity.exception.IdentityException
+ */
+ void updateAttributes(IdentityType identity, Map<String, String[]> attributes)
+ throws IdentityException;
+
+ /**
+ * Add new attributes - if attribute with given name already exists the values
+ * will be appended
+ *
+ * @param identity
+ * @param attributes
+ * @throws org.jboss.identity.exception.IdentityException
+ */
+ void addAttributes(IdentityType identity, Map<String, String[]> attributes)
+ throws IdentityException;
+
+ /**
+ * Remove attributes
+ *
+ * @param identity
+ * @param attributes
+ */
+ void removeAttributes(IdentityType identity, Set<String> attributes)
+ throws IdentityException;
+
+ /**
+ * @param identity
+ * @return
+ * @throws IdentityException
+ */
+ boolean hasPasswordAttribute(Identity identity) throws IdentityException;
+
+ /**
+ *
+ * @param identity
+ * @param password
+ * @return
+ * @throws IdentityException
+ */
+ boolean validatePasswordAttribute(Identity identity, String password) throws IdentityException;
+
+ /**
+ *
+ * @param identity
+ * @param password
+ * @throws IdentityException
+ */
+ void updatePasswordAttribute(Identity identity, String password) throws IdentityException;
+
+}
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-10-18 21:35:12 UTC (rev 105)
+++ trunk/identity-api/src/main/java/org/jboss/identity/api/Group.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -26,6 +26,7 @@
/**
* Represents a Group
+ *
* @author Anil.Saldhana(a)redhat.com
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
* @since Jul 9, 2008
Modified: trunk/identity-api/src/main/java/org/jboss/identity/api/GroupType.java
===================================================================
--- trunk/identity-api/src/main/java/org/jboss/identity/api/GroupType.java 2008-10-18 21:35:12 UTC (rev 105)
+++ trunk/identity-api/src/main/java/org/jboss/identity/api/GroupType.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -23,6 +23,7 @@
/**
* Type of Group
+ *
* @author Anil.Saldhana(a)redhat.com
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
* @since Jul 11, 2008
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-10-18 21:35:12 UTC (rev 105)
+++ trunk/identity-api/src/main/java/org/jboss/identity/api/Identity.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -23,6 +23,7 @@
/**
* Represents an Identity
+ *
* @author Anil.Saldhana(a)redhat.com
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
* @since Jun 30, 2008
@@ -30,16 +31,4 @@
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)
- */
- boolean isVirtual();
}
\ No newline at end of file
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-10-18 21:35:12 UTC (rev 105)
+++ trunk/identity-api/src/main/java/org/jboss/identity/api/IdentitySession.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -23,6 +23,7 @@
import org.jboss.identity.exception.IdentityException;
+import org.jboss.identity.exception.FeatureNotSupportedException;
/**
* Expose all identity management operations within a given realm
@@ -69,32 +70,37 @@
/**
* @return
+ * @throws IdentityException
*/
- Transaction beginTransaction();
+ Transaction beginTransaction() throws IdentityException;
/**
* Transaction instance assosiated with this session
* @return
*/
- Transaction getTransaction();
+ Transaction getTransaction() throws IdentityException;
/**
+ * PersistenceManager exposes management operations on Group and Identity objects
* @return
*/
PersistenceManager getPersistenceManager();
/**
+ * RelationshipManager enables to associate and disassociate Group and Identity objects
* @return
*/
RelationshipManager getRelationshipManager();
/**
+ * RoleManager exposes operation on Role objects. This is optional feature that may be not supported
* @return
+ * @throws FeatureNotSupportedException
*/
- ProfileManager getProfileManager();
+ AttributesManager getProfileManager();
//TODO: proper exception if roles are not supported
- RoleManager getRoleManager();
+ RoleManager getRoleManager() throws FeatureNotSupportedException ;
}
\ No newline at end of file
Modified: trunk/identity-api/src/main/java/org/jboss/identity/api/IdentitySessionFactory.java
===================================================================
--- trunk/identity-api/src/main/java/org/jboss/identity/api/IdentitySessionFactory.java 2008-10-18 21:35:12 UTC (rev 105)
+++ trunk/identity-api/src/main/java/org/jboss/identity/api/IdentitySessionFactory.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -23,6 +23,8 @@
package org.jboss.identity.api;
/**
+ * Creates IdentitySession objects for a given Realm.
+ *
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
* @version : 0.1 $
*/
@@ -39,7 +41,7 @@
boolean isClosed();
/**
- * Create a Session
+ * Create IdentitySession
* @return
*/
IdentitySession createIdentitySession(String realmName);
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-10-18 21:35:12 UTC (rev 105)
+++ trunk/identity-api/src/main/java/org/jboss/identity/api/IdentityType.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -34,13 +34,18 @@
public interface IdentityType
{
/**
- * @return id of this identity object
+ * @return id of this IdentityType object
*/
Object getId();
/**
- * @return description
+ * @return the name of the IdentityType
*/
+ String getName();
+
+ /**
+ * @return description of the IdentityType
+ */
String getDescription();
}
\ 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-10-18 21:35:12 UTC (rev 105)
+++ trunk/identity-api/src/main/java/org/jboss/identity/api/PersistenceManager.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -28,6 +28,8 @@
import java.util.Map;
/**
+ * Exposes all management operations on Group and Identity objects.
+ *
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
* @version : 0.1 $
*/
@@ -39,17 +41,21 @@
*/
IdentitySession getIdentitySession();
+
+ //TODO: Add FeaturesDescription
+
// Create
/**
* <p>Create an identity in the realm</p>
* @param identityName
+ * @throws IdentityException
* @return
*/
Identity createIdentity(String identityName) throws IdentityException;
/**
- * Create a group of a particular type
+ * <p>Create a group of a particular type</p>
* @param groupName
* @param groupType
* @return
@@ -79,18 +85,6 @@
*/
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
/**
@@ -129,14 +123,14 @@
/**
* 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, dedicated
* parameters will take no effect
*
* @param filterName can be null
* @param offset
* @param limit 0 means unlimited page size
* @param orderedByName
- * @param ascending default true
+ * @param ascending
* @return
* @throws org.jboss.identity.exception.IdentityException
*/
@@ -147,14 +141,14 @@
/**
* 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
+ * are not supported, dedicated parameters will take no effect
*
* @param filterName can be null
* @param attributes
* @param offset
* @param limit 0 means unlimited page size
* @param orderedByName
- * @param ascending default true
+ * @param ascending
* @return
* @throws org.jboss.identity.exception.IdentityException
*/
@@ -165,7 +159,7 @@
// Search Groups
/**
- * Find group with a given name
+ * Find group with a given name and type
*
* @param name
* @param groupType
@@ -186,7 +180,7 @@
/**
* Find group with a given type paginated and ordered.
* If the paginatedSearch or orderedSearch operations
- * are not supported in this store implementation, dedicated
+ * are not supported, dedicated
* parameters will take no effect
*
* @param groupType
@@ -194,7 +188,7 @@
* @param offset
* @param limit 0 means unlimited page size
* @param orderedByName can be null
- * @param ascending default true
+ * @param ascending
* @return
* @throws org.jboss.identity.exception.IdentityException
*/
@@ -206,14 +200,14 @@
/**
* Find group with a given attributes values. If the paginatedSearch or
* orderedSearch operations
- * are not supported in this store implementation, dedicated parameters will take no effect
+ * are not supported, dedicated parameters will take no effect
*
* @param groupType
* @param attributes
* @param offset
* @param limit 0 means unlimited page size
* @param orderedByName can be null
- * @param ascending default true
+ * @param ascending
* @return
* @throws org.jboss.identity.exception.IdentityException
*/
@@ -221,4 +215,15 @@
int offset, int limit,
boolean orderedByName, boolean ascending) throws IdentityException;
+ /**
+ * Whether Identity is a virtual
+ * (such as a pseudonym)
+ * @return true (virtual identity)
+ */
+ boolean isVirtual(Identity identity);
+
+
+
+
+
}
Deleted: trunk/identity-api/src/main/java/org/jboss/identity/api/ProfileManager.java
===================================================================
--- trunk/identity-api/src/main/java/org/jboss/identity/api/ProfileManager.java 2008-10-18 21:35:12 UTC (rev 105)
+++ trunk/identity-api/src/main/java/org/jboss/identity/api/ProfileManager.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -1,87 +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;
-
-import org.jboss.identity.exception.IdentityException;
-
-import java.util.Set;
-import java.util.Map;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
- * @version : 0.1 $
- */
-public interface ProfileManager
-{
-
- /**
- * @return Session associated with this object instance
- */
- IdentitySession getIdentitySession();
-
- /**
- * @param identityType
- * @return names of supported attributes
- * @throws org.jboss.identity.exception.IdentityException
- */
- Set<String> getSupportedAttributeNames(IdentityType identityType)
- throws IdentityException;
-
- /**
- * Get attributes for the given identity
- *
- * @param identity
- * @return
- * @throws org.jboss.identity.exception.IdentityException
- */
- Map<String, String[]> getAttributes(IdentityType identity) throws IdentityException;
-
- /**
- * Update attributes with new values - previous values will be overwritten
- * @param identity
- * @param attributes
- * @throws org.jboss.identity.exception.IdentityException
- */
- void updateAttributes(IdentityType identity, Map<String, String[]> attributes)
- throws IdentityException;
-
- /**
- * Add new attributes - if attribute with given name already exists the values
- * will be appended
- *
- * @param identity
- * @param attributes
- * @throws org.jboss.identity.exception.IdentityException
- */
- void addAttributes(IdentityType identity, Map<String, String[]> attributes)
- throws IdentityException;
-
- /**
- * Remove attributes
- *
- * @param identity
- * @param attributes
- */
- void removeAttributes(IdentityType identity, Set<String> attributes)
- throws IdentityException;
-}
Modified: trunk/identity-api/src/main/java/org/jboss/identity/api/Realm.java
===================================================================
--- trunk/identity-api/src/main/java/org/jboss/identity/api/Realm.java 2008-10-18 21:35:12 UTC (rev 105)
+++ trunk/identity-api/src/main/java/org/jboss/identity/api/Realm.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -22,8 +22,7 @@
package org.jboss.identity.api;
/**
- * <p>The <b>realm</b> under which the various models and policies
- * are applicable.</p>
+ * <p>The <b>realm</b> contain configuration of a set of identity data providers</p>
* @author Anil.Saldhana(a)redhat.com
* @since Jul 9, 2008
*/
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-10-18 21:35:12 UTC (rev 105)
+++ trunk/identity-api/src/main/java/org/jboss/identity/api/RealmManager.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -22,13 +22,13 @@
package org.jboss.identity.api;
-import org.jboss.identity.api.exception.PersistenceManagerNotFoundException;
-import org.jboss.identity.api.exception.SessionNotOpenException;
+import org.jboss.identity.exception.IdentityException;
import java.io.InputStream;
/**
- * All operations connected with realms. Because operations on realms are not often there is no transaction support.
+ * All operations connected with realms.
+ * Because operations on realms are not often there is no transaction or session support.
*
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
* @version : 0.1 $
@@ -44,7 +44,7 @@
* @param realmName
* @return
*/
- Realm bootstrap(String realmName);
+ Realm bootstrap(String realmName) throws IdentityException;
/**
* <p>Bootstrap a realm given a configuration</p>
@@ -52,34 +52,29 @@
* @param config
* @return
*/
- Realm bootstrap(String realmName, InputStream config);
+ Realm bootstrap(String realmName, InputStream config) throws IdentityException;
/**
* <p>Associate a relationship between two realms</p>
* @param realmA
* @param realmB
- * @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)
- throws PersistenceManagerNotFoundException, SessionNotOpenException;
+ */
+ void associate(Realm realmA, Realm realmB) throws IdentityException;
+
/**
* <p>Disassociate a relationship between two realms</p>
* @param realmA
* @param realmB
- * @throws PersistenceManagerNotFoundException PM not set
- * @throws SessionNotOpenException session is not open
*/
- void disassociate(Realm realmA, Realm realmB)
- throws PersistenceManagerNotFoundException,SessionNotOpenException;
+ void disassociate(Realm realmA, Realm realmB) throws IdentityException;
/**
* @param fromRealm
* @param toRealm
* @return returns a relationship type between this and given Realm.
*/
- boolean isAssosiated(Realm fromRealm, Realm toRealm);
+ boolean isAssosiated(Realm fromRealm, Realm toRealm) throws IdentityException;
/**
* <p>Return a realm</p>
@@ -87,6 +82,6 @@
* @param shouldBootstrap Should we bootstrap if a realm does not exist?
* @return
*/
- Realm getRealm(String realmName, boolean shouldBootstrap);
+ Realm getRealm(String realmName, boolean shouldBootstrap) throws IdentityException;
}
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-10-18 21:35:12 UTC (rev 105)
+++ trunk/identity-api/src/main/java/org/jboss/identity/api/RelationshipManager.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -27,6 +27,8 @@
import java.util.Collection;
/**
+ * Management of relationships between Identity and Group objects.
+ *
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
* @version : 0.1 $
*/
@@ -38,6 +40,8 @@
*/
IdentitySession getIdentitySession();
+ //TODO: Add FeaturesDescription
+
// Assignation
/**
@@ -109,9 +113,9 @@
/**
* Find groups that are associated with given group.
* If the paginatedSearch or orderedSearch operations
- * are not supported in this store implementation, dedicated parameters will
+ * are not supported, 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.
+ * set to true and 'inherited' is set to true all nested subgroubs will be returned.
*
* @param group parent group
* @param groupType can be null
@@ -122,7 +126,7 @@
* @param offset
* @param limit 0 means unlimited page size
* @param orderedByAttributeName can be null
- * @param ascending default true
+ * @param ascending
* @return
* @throws org.jboss.identity.exception.IdentityException
*/
@@ -137,7 +141,7 @@
/**
* 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
+ * are not supported, dedicated parameters will
* take no effect
*
* @param identity child identity
@@ -145,7 +149,7 @@
* @param offset
* @param limit 0 means unlimited page size
* @param orderedByAttributeName can be null
- * @param ascending default true
+ * @param ascending
* @return
* @throws org.jboss.identity.exception.IdentityException
*/
@@ -162,11 +166,11 @@
* take no effect
*
* @param group parent group
- * @param inherited if true also identities from subgroubs will be retreived. Default is false
+ * @param inherited if true also identities from subgroubs will be retrieved. Default is false
* @param offset
* @param limit 0 means unlimited page size
* @param orderedByAttributeName can be null
- * @param ascending default true
+ * @param ascending
* @return
* @throws org.jboss.identity.exception.IdentityException
*/
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-10-18 21:35:12 UTC (rev 105)
+++ trunk/identity-api/src/main/java/org/jboss/identity/api/Role.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -23,8 +23,9 @@
/**
- * Marker Interface represents a role
- * @author Anil.Saldhana(a)redhat.com
+ * Marker Interface represents a role. Role is a direct one-to-one typed relationship between Identity and Group objects.
+ * Each Identity and Group object pair can have several Role objects associated with them with different RoleType specified.
+ *
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
* @since Jun 30, 2008
*/
Modified: trunk/identity-api/src/main/java/org/jboss/identity/api/RoleManager.java
===================================================================
--- trunk/identity-api/src/main/java/org/jboss/identity/api/RoleManager.java 2008-10-18 21:35:12 UTC (rev 105)
+++ trunk/identity-api/src/main/java/org/jboss/identity/api/RoleManager.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -29,6 +29,9 @@
import java.util.List;
/**
+ * Management operations on Role objects. Role support is optional and depends on the capabilities of the underlying
+ * configured identity stores capabilities.
+ *
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
* @version : 0.1 $
*/
@@ -40,6 +43,8 @@
*/
IdentitySession getIdentitySession();
+ //TODO: Add FeaturesDescription
+
// RoleType
/**
Deleted: trunk/identity-api/src/main/java/org/jboss/identity/api/SessionState.java
===================================================================
--- trunk/identity-api/src/main/java/org/jboss/identity/api/SessionState.java 2008-10-18 21:35:12 UTC (rev 105)
+++ trunk/identity-api/src/main/java/org/jboss/identity/api/SessionState.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -1,32 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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;
-
-/**
- * Current State of the Session
- * @author Anil.Saldhana(a)redhat.com
- * @since Jul 22, 2008
- */
-public enum SessionState
-{
- OPEN, CLOSED, ACTIVE;
-}
\ No newline at end of file
Deleted: trunk/identity-api/src/main/java/org/jboss/identity/api/exception/PersistenceManagerNotFoundException.java
===================================================================
--- trunk/identity-api/src/main/java/org/jboss/identity/api/exception/PersistenceManagerNotFoundException.java 2008-10-18 21:35:12 UTC (rev 105)
+++ trunk/identity-api/src/main/java/org/jboss/identity/api/exception/PersistenceManagerNotFoundException.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -1,35 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.exception;
-
-import org.jboss.identity.exception.IdentityException;
-
-/**
- * Exception indicating the non-availability
- * of a Persistence Manager
- * @author Anil.Saldhana(a)redhat.com
- * @since Jul 10, 2008
- */
-public class PersistenceManagerNotFoundException extends IdentityException
-{
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
Deleted: trunk/identity-api/src/main/java/org/jboss/identity/api/exception/SessionNotOpenException.java
===================================================================
--- trunk/identity-api/src/main/java/org/jboss/identity/api/exception/SessionNotOpenException.java 2008-10-18 21:35:12 UTC (rev 105)
+++ trunk/identity-api/src/main/java/org/jboss/identity/api/exception/SessionNotOpenException.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -1,35 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.exception;
-
-import org.jboss.identity.exception.IdentityException;
-
-/**
- * Exception indicating that no session
- * is open
- * @author Anil.Saldhana(a)redhat.com
- * @since Jul 10, 2008
- */
-public class SessionNotOpenException extends IdentityException
-{
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
Added: trunk/identity-common/src/main/java/org/jboss/identity/exception/FeatureNotSupportedException.java
===================================================================
--- trunk/identity-common/src/main/java/org/jboss/identity/exception/FeatureNotSupportedException.java (rev 0)
+++ trunk/identity-common/src/main/java/org/jboss/identity/exception/FeatureNotSupportedException.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -0,0 +1,50 @@
+/*
+* 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.exception;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class FeatureNotSupportedException extends Exception
+{
+ public FeatureNotSupportedException()
+ {
+ super();
+ }
+
+ public FeatureNotSupportedException(String message)
+ {
+ super(message);
+ }
+
+ public FeatureNotSupportedException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public FeatureNotSupportedException(Throwable cause)
+ {
+ super(cause);
+ }
+}
Copied: trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/AttributesManagerImpl.java (from rev 105, trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/ProfileManagerImpl.java)
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/AttributesManagerImpl.java (rev 0)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/AttributesManagerImpl.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -0,0 +1,129 @@
+/*
+* 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.AttributesManager;
+import org.jboss.identity.api.IdentityType;
+import org.jboss.identity.api.Identity;
+import org.jboss.identity.exception.IdentityException;
+import org.jboss.identity.impl.NotYetImplementedException;
+
+import java.util.Set;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.HashSet;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class AttributesManagerImpl extends AbstractManager implements AttributesManager
+{
+ public AttributesManagerImpl(IdentitySession session)
+ {
+ super(session);
+ }
+
+ //TODO: fix to have similar signatures in API/SPI for String[] and avoid unnesesary iterations
+
+ public Set<String> getSupportedAttributeNames(IdentityType identityType) throws IdentityException
+ {
+ return getRepository().getSupportedAttributeNames(getInvocationContext(), createIdentityObject(identityType).getIdentityType());
+ }
+
+ public Map<String, String[]> getAttributes(IdentityType identity) throws IdentityException
+ {
+ Map<String, Set<String>> attributes = getRepository().getAttributes(getInvocationContext(), createIdentityObject(identity));
+
+ Map<String, String[]> attrs = new HashMap<String, String[]>();
+
+ for (Map.Entry<String, Set<String>> entry : attributes.entrySet())
+ {
+ attrs.put(entry.getKey(), entry.getValue().toArray(new String[entry.getValue().size()]));
+ }
+
+ return attrs;
+ }
+
+ public void updateAttributes(IdentityType identity, Map<String, String[]> attributes) throws IdentityException
+ {
+ Map<String, Set<String>> attrs = new HashMap<String, Set<String>>();
+
+ for (Map.Entry<String, String[]> entry : attributes.entrySet())
+ {
+ Set<String> vals = new HashSet<String>();
+ for (String s : entry.getValue())
+ {
+ vals.add(s);
+ }
+
+ attrs.put(entry.getKey(),vals);
+ }
+
+ getRepository().updateAttributes(getInvocationContext(), createIdentityObject(identity), attrs);
+
+ }
+
+ public void addAttributes(IdentityType identity, Map<String, String[]> attributes) throws IdentityException
+ {
+ Map<String, Set<String>> attrs = new HashMap<String, Set<String>>();
+
+ for (Map.Entry<String, String[]> entry : attributes.entrySet())
+ {
+ Set<String> vals = new HashSet<String>();
+ for (String s : entry.getValue())
+ {
+ vals.add(s);
+ }
+
+ attrs.put(entry.getKey(),vals);
+ }
+
+ getRepository().addAttributes(getInvocationContext(), createIdentityObject(identity), attrs);
+ }
+
+ public void removeAttributes(IdentityType identity, Set<String> attributes) throws IdentityException
+ {
+ getRepository().removeAttributes(getInvocationContext(), createIdentityObject(identity), attributes);
+
+ }
+
+ public boolean hasPasswordAttribute(Identity identity) throws IdentityException
+ {
+ //TODO:NYI
+ throw new NotYetImplementedException();
+ }
+
+ public boolean validatePasswordAttribute(Identity identity, String password) throws IdentityException
+ {
+ //TODO:NYI
+ throw new NotYetImplementedException();
+ }
+
+ public void updatePasswordAttribute(Identity identity, String password) throws IdentityException
+ {
+ //TODO:NYI
+ throw new NotYetImplementedException();
+ }
+}
Modified: trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentitySessionImpl.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentitySessionImpl.java 2008-10-18 21:35:12 UTC (rev 105)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentitySessionImpl.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -26,7 +26,7 @@
import org.jboss.identity.api.Transaction;
import org.jboss.identity.api.PersistenceManager;
import org.jboss.identity.api.RelationshipManager;
-import org.jboss.identity.api.ProfileManager;
+import org.jboss.identity.api.AttributesManager;
import org.jboss.identity.api.RoleManager;
import org.jboss.identity.exception.IdentityException;
@@ -46,7 +46,7 @@
private final RelationshipManager relationshipManager;
- private final ProfileManager profileManager;
+ private final AttributesManager profileManager;
private final RoleManager roleManager;
@@ -65,7 +65,7 @@
this.sessionWrappers = sessionWrappers;
this.persistenceManager = new PersistenceManagerImpl(this);
this.relationshipManager = new RelationshipManagerImpl(this);
- this.profileManager = new ProfileManagerImpl(this);
+ this.profileManager = new AttributesManagerImpl(this);
this.roleManager = new RoleManagerImpl(this);
@@ -134,7 +134,7 @@
return relationshipManager;
}
- public ProfileManager getProfileManager()
+ public AttributesManager getProfileManager()
{
return profileManager;
}
Modified: trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/PersistenceManagerImpl.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/PersistenceManagerImpl.java 2008-10-18 21:35:12 UTC (rev 105)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/PersistenceManagerImpl.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -32,6 +32,7 @@
import org.jboss.identity.spi.model.IdentityObjectType;
import org.jboss.identity.spi.model.IdentityObject;
import org.jboss.identity.impl.types.SimpleIdentityObject;
+import org.jboss.identity.impl.NotYetImplementedException;
import java.util.Collection;
import java.util.Map;
@@ -84,11 +85,6 @@
getRepository().removeIdentityObject(getInvocationContext(), createIdentityObject(group));
}
- public void refreshIdentityType(IdentityType it) throws IdentityException
- {
- //TODO: remove this method from the interface
- }
-
public int getIdentityCount() throws IdentityException
{
IdentityObjectType iot = getIdentityObjectType();
@@ -179,4 +175,10 @@
return groups;
}
+
+ public boolean isVirtual(Identity identity)
+ {
+ //TODO:NYI
+ throw new NotYetImplementedException();
+ }
}
Modified: trunk/identity-impl/src/main/java/org/jboss/identity/impl/helper/LDAPTools.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/helper/LDAPTools.java 2008-10-18 21:35:12 UTC (rev 105)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/helper/LDAPTools.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -42,8 +42,6 @@
{
throw new IllegalArgumentException("Cannot process empty dn");
}
- String name = null;
-
String[] parts = dn.split(",");
parts = parts[0].split("=");
@@ -55,24 +53,4 @@
return parts[1];
}
- /**
- * Simple encoding to make a name rfc 2253 compiliant. For now it just escapes the special chars listed in rfc
- * with backslash.
- * @param name
- * @return
- */
- public static String encodeRfc2253Name(String name)
- {
- //TODO: fully cover 2253 encoding
-
- //TODO: backslash
- //name = name.replaceAll("\\","");
- name = name.replaceAll(",","\\\\\\,");
- name = name.replaceAll("\\+","\\\\\\+");
- name = name.replaceAll("\"","\\\\\"");
- name = name.replaceAll("<","\\\\\\<");
- name = name.replaceAll(">","\\\\\\>");
- name = name.replaceAll(";","\\\\\\;");
- return name;
- }
}
Modified: trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/hibernate/HibernateIdentityObjectAttribute.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/hibernate/HibernateIdentityObjectAttribute.java 2008-10-18 21:35:12 UTC (rev 105)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/hibernate/HibernateIdentityObjectAttribute.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -23,6 +23,7 @@
package org.jboss.identity.impl.model.hibernate;
import org.hibernate.annotations.CollectionOfElements;
+import org.jboss.identity.spi.model.IdentityObjectAttribute;
import javax.persistence.Entity;
import javax.persistence.Table;
@@ -39,7 +40,7 @@
*/
@Entity
@Table(name = "identity_obj_attrs")
-public class HibernateIdentityObjectAttribute
+public class HibernateIdentityObjectAttribute implements IdentityObjectAttribute
{
@Id
@GeneratedValue
Modified: 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 2008-10-18 21:35:12 UTC (rev 105)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/ldap/LDAPIdentityObjectRelationshipImpl.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -52,7 +52,7 @@
public String getName()
{
- return null;
+ return name;
}
public IdentityObjectRelationshipType getType()
@@ -69,11 +69,11 @@
public IdentityObject getFromIdentityObject()
{
- return null;
+ return from;
}
public IdentityObject getToIdentityObject()
{
- return null;
+ return to;
}
}
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-10-18 21:35:12 UTC (rev 105)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/ldap/LDAPIdentityStore.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -150,8 +150,6 @@
// Make it RFC 2253 compliant
LdapName validLDAPName = new LdapName(getTypeConfiguration(invocationCtx, type).getIdAttributeName().concat("=").concat(name));
- //String rdn = getTypeConfiguration(invocationCtx, type).getIdAttributeName().concat("=").concat(validLDAPName.toString());
-
log.finer("creating ldap entry for: " + validLDAPName + "; " + attrs);
ctx.createSubcontext(validLDAPName, attrs);
}
Modified: trunk/identity-impl/src/test/java/org/jboss/identity/impl/HibernateTestSupport.java
===================================================================
--- trunk/identity-impl/src/test/java/org/jboss/identity/impl/HibernateTestSupport.java 2008-10-18 21:35:12 UTC (rev 105)
+++ trunk/identity-impl/src/test/java/org/jboss/identity/impl/HibernateTestSupport.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -38,7 +38,7 @@
*/
public class HibernateTestSupport
{
- private static Logger logger = Logger.getLogger(HibernateTestSupport.class.getName());
+ private static Logger logger = Logger.getLogger(HibernateTestSupport.class.getName());
private HibernateEntityManagerFactory emFactory;
@@ -66,7 +66,7 @@
try {
logger.info("Starting in-memory HSQL database for unit tests");
Class.forName("org.hsqldb.jdbcDriver");
- connection = DriverManager.getConnection("jdbc:hsqldb:mem:unit-testing-jpa", "sa", "");
+ connection = DriverManager.getConnection("jdbc:hsqldb:mem:" + databaseName, "sa", "");
}
catch (Exception ex)
{
@@ -77,7 +77,7 @@
try
{
logger.info("Building JPA EntityManager for unit tests");
- emFactory = (HibernateEntityManagerFactory)Persistence.createEntityManagerFactory("jboss-identity-model");
+ emFactory = (HibernateEntityManagerFactory)Persistence.createEntityManagerFactory(persistenceUnit);
em = (HibernateEntityManager)emFactory.createEntityManager();
}
catch (Exception ex)
Deleted: trunk/identity-spi/src/main/java/org/jboss/identity/spi/attribute/PasswordAttribute.java
===================================================================
--- trunk/identity-spi/src/main/java/org/jboss/identity/spi/attribute/PasswordAttribute.java 2008-10-18 21:35:12 UTC (rev 105)
+++ trunk/identity-spi/src/main/java/org/jboss/identity/spi/attribute/PasswordAttribute.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -1,70 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.attribute;
-
-import java.util.Date;
-
-import org.jboss.identity.spi.model.IdentityObjectType;
-import org.jboss.identity.spi.model.IdentityObjectAttribute;
-import org.jboss.identity.spi.policy.PasswordExpirationPolicy;
-
-/**
- * Represents a password
- * @author Anil.Saldhana(a)redhat.com
- * @since Jul 13, 2008
- */
-public class PasswordAttribute<T extends IdentityObjectType>
-implements IdentityObjectAttribute
-{
- /**
- * Password policy governing this attribute.
- * A null value indicates that there is no policy.
- */
- protected PasswordExpirationPolicy<T> passwordPolicy;
-
- /**
- * Get the date time when the password was last updated.
- * The update can be based on password expiration.
- */
- protected Date lastUpdated = new Date();
-
- public PasswordAttribute()
- {
- }
-
- public PasswordAttribute(PasswordExpirationPolicy<T> aPasswordPolicy)
- {
- this.passwordPolicy = aPasswordPolicy;
- }
-
- public PasswordExpirationPolicy<T> getPasswordPolicy()
- {
- return passwordPolicy;
- }
-
- public void setPasswordPolicy(PasswordExpirationPolicy<T> passwordPolicy)
- {
- this.passwordPolicy = passwordPolicy;
- }
-
-
-}
\ No newline at end of file
Modified: 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 2008-10-18 21:35:12 UTC (rev 105)
+++ trunk/identity-spi/src/main/java/org/jboss/identity/spi/exception/OperationNotSupportedException.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -22,8 +22,6 @@
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 $
Modified: trunk/identity-spi/src/main/java/org/jboss/identity/spi/repository/IdentityStoreRepository.java
===================================================================
--- trunk/identity-spi/src/main/java/org/jboss/identity/spi/repository/IdentityStoreRepository.java 2008-10-18 21:35:12 UTC (rev 105)
+++ trunk/identity-spi/src/main/java/org/jboss/identity/spi/repository/IdentityStoreRepository.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -34,7 +34,9 @@
* IdentityStoreRepository exposes identity object management
* operations and act as an entry point to many underlying data stores.
* Its responsibility is to map identity objects, their state and relations
- * between them across different identity stores.
+ * between them across different identity stores. By extending IdentityStore
+ * interface it exposes unified entry point
+ * for all identity related operations in the SPI
* @author boleslaw dot dawidowicz at redhat anotherdot com
* @author Anil.Saldhana(a)redhat.com
* @since Jul 10, 2008
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-10-18 21:35:12 UTC (rev 105)
+++ trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/AttributeStore.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -31,7 +31,7 @@
/**
* 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).
+ * distributted way (part in LDAP part in DB).
*
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
* @version : 0.1 $
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-10-18 21:35:12 UTC (rev 105)
+++ trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/IdentityStore.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -34,7 +34,7 @@
import org.jboss.identity.exception.IdentityException;
/**
- * Represents an Identity Store
+ * Represents an Identity Store. Implementation of this interface perform operations on real identity storage like DB or LDAP
*
* @author boleslaw dot dawidowicz at redhat anotherdot com
* @author Anil.Saldhana(a)redhat.com
Modified: trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/IdentityStoreInvocationContext.java
===================================================================
--- trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/IdentityStoreInvocationContext.java 2008-10-18 21:35:12 UTC (rev 105)
+++ trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/IdentityStoreInvocationContext.java 2008-10-21 10:51:41 UTC (rev 106)
@@ -23,6 +23,9 @@
package org.jboss.identity.spi.store;
/**
+ * IdentityStoreInvocationContext is passed to the IdentityStore methods. It enables IdentityStore to not be aware
+ * about current session connected with method invocation.
+ *
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
* @version : 0.1 $
*/
16 years, 2 months
JBoss Identity SVN: r105 - in trunk/identity-impl/src: main/java/org/jboss/identity/impl/repository and 5 other directories.
by jboss-identity-commits@lists.jboss.org
Author: bdaw
Date: 2008-10-18 17:35:12 -0400 (Sat, 18 Oct 2008)
New Revision: 105
Added:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/repository/FallbackIdentityStoreRepository.java
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/ProfileManagerImpl.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/repository/AbstractIdentityStoreRepository.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/hibernate/HibernateIdentityStoreInvocationContext.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/HibernateTestSupport.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/APITestCase.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/hibernate/HibernateTestBase.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/ldap/LDAPIdentityStoreTestCase.java
Log:
very dummy impl of mixed LDAP/DB scenario. Just to pass initial tests.
Modified: trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/ProfileManagerImpl.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/ProfileManagerImpl.java 2008-10-17 20:52:50 UTC (rev 104)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/ProfileManagerImpl.java 2008-10-18 21:35:12 UTC (rev 105)
@@ -45,7 +45,7 @@
super(session);
}
- //TODO: fix to have similar signatures in API/SPI for String[]
+ //TODO: fix to have similar signatures in API/SPI for String[] and avoid unnesesary iterations
public Set<String> getSupportedAttributeNames(IdentityType identityType) throws IdentityException
{
Modified: trunk/identity-impl/src/main/java/org/jboss/identity/impl/repository/AbstractIdentityStoreRepository.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/repository/AbstractIdentityStoreRepository.java 2008-10-17 20:52:50 UTC (rev 104)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/repository/AbstractIdentityStoreRepository.java 2008-10-18 21:35:12 UTC (rev 105)
@@ -25,7 +25,10 @@
import org.jboss.identity.spi.repository.IdentityStoreRepository;
import org.jboss.identity.spi.store.IdentityStore;
import org.jboss.identity.spi.store.AttributeStore;
+import org.jboss.identity.spi.store.IdentityStoreInvocationContext;
import org.jboss.identity.spi.model.IdentityObjectType;
+import org.jboss.identity.spi.model.IdentityObject;
+import org.jboss.identity.exception.IdentityException;
import java.util.Set;
import java.util.Map;
@@ -94,4 +97,22 @@
{
return attributeStoreMappings.get(identityObjectType.getName());
}
+
+ public boolean hasIdentityObject(IdentityStoreInvocationContext ctx, IdentityStore is, IdentityObject io) throws IdentityException
+ {
+ try
+ {
+ if (is.findIdentityObject(ctx, io.getName(), io.getIdentityType()) != null)
+ {
+ return true;
+ }
+ }
+ catch (IdentityException e)
+ {
+ //store may throw exception if there is no identity so do nothing
+ //TODO: this behaviour sucks...
+
+ }
+ return false;
+ }
}
Added: trunk/identity-impl/src/main/java/org/jboss/identity/impl/repository/FallbackIdentityStoreRepository.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/repository/FallbackIdentityStoreRepository.java (rev 0)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/repository/FallbackIdentityStoreRepository.java 2008-10-18 21:35:12 UTC (rev 105)
@@ -0,0 +1,332 @@
+/*
+* 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.repository;
+
+import org.jboss.identity.spi.store.IdentityStore;
+import org.jboss.identity.spi.store.AttributeStore;
+import org.jboss.identity.spi.store.FeaturesDescription;
+import org.jboss.identity.spi.store.IdentityStoreInvocationContext;
+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.NotYetImplementedException;
+
+import java.util.Map;
+import java.util.Collection;
+import java.util.Set;
+import java.io.IOException;
+
+/**
+ * LADP + DB
+ *
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class FallbackIdentityStoreRepository extends AbstractIdentityStoreRepository
+{
+
+ private final IdentityStore defaultIdentityStore;
+
+ private final AttributeStore defaultAttributeStore;
+
+ public FallbackIdentityStoreRepository(IdentityStore identityStore, AttributeStore attributeStore,
+ Map<String, IdentityStore> identityStoreMappings, Map<String, AttributeStore> attributeStoreMappings)
+ {
+ super(identityStoreMappings, attributeStoreMappings);
+
+ this.defaultIdentityStore = identityStore;
+ this.defaultAttributeStore = attributeStore;
+ }
+
+ public void bootstrap() throws IOException
+ {
+
+ }
+
+ public String getId()
+ {
+ return null;
+ }
+
+ public FeaturesDescription getSupportedFeatures()
+ {
+ return null;
+ }
+
+ IdentityStore resolveIdentityStore(IdentityObject io)
+ {
+ return resolveIdentityStore(io.getIdentityType());
+ }
+
+ IdentityStore resolveIdentityStore(IdentityObjectType iot)
+ {
+ IdentityStore ids = getIdentityStore(iot);
+ if (ids == null)
+ {
+ ids = defaultIdentityStore;
+ }
+ return ids;
+ }
+
+ AttributeStore resolveAttributeStore(IdentityObjectType iot)
+ {
+ AttributeStore ads = getAttributeStore(iot);
+ if (ads == null)
+ {
+ ads = defaultIdentityStore;
+ }
+ return ads;
+ }
+
+ public IdentityObject createIdentityObject(IdentityStoreInvocationContext invocationCtx, String name, IdentityObjectType identityObjectType) throws IdentityException
+ {
+ return resolveIdentityStore(identityObjectType).createIdentityObject(invocationCtx, name, identityObjectType);
+ }
+
+ public void removeIdentityObject(IdentityStoreInvocationContext invocationCtx, IdentityObject identity) throws IdentityException
+ {
+ resolveIdentityStore(identity).removeIdentityObject(invocationCtx, identity);
+ }
+
+ public int getIdentityObjectsCount(IdentityStoreInvocationContext invocationCtx, IdentityObjectType identityType) throws IdentityException
+ {
+ return resolveIdentityStore(identityType).getIdentityObjectsCount(invocationCtx, identityType);
+ }
+
+ public IdentityObject findIdentityObject(IdentityStoreInvocationContext invocationContext, String name, IdentityObjectType identityObjectType) throws IdentityException
+ {
+ return resolveIdentityStore(identityObjectType).findIdentityObject(invocationContext, name, identityObjectType);
+ }
+
+ public IdentityObject findIdentityObject(IdentityStoreInvocationContext invocationContext, Object id) throws IdentityException
+ {
+
+ for (IdentityStore identityStore : getIdentityStoreMappings().values())
+ {
+ IdentityObject io = identityStore.findIdentityObject(invocationContext, id);
+ if (io != null)
+ {
+ return io;
+ }
+ }
+
+ return defaultIdentityStore.findIdentityObject(invocationContext, id);
+ }
+
+ public Collection<IdentityObject> findIdentityObject(IdentityStoreInvocationContext invocationCtx, IdentityObjectType identityType, String nameFilter, int offset, int limit, boolean orderByName, boolean ascending) throws IdentityException
+ {
+ return resolveIdentityStore(identityType).findIdentityObject(invocationCtx, identityType, nameFilter, offset, limit, orderByName, ascending);
+ }
+
+ public Collection<IdentityObject> findIdentityObject(IdentityStoreInvocationContext invocationCtx, IdentityObjectType identityType, Map<String, String[]> attributes, int offset, int limit, boolean orderByName, boolean ascending) throws IdentityException
+ {
+ return resolveIdentityStore(identityType).findIdentityObject(invocationCtx, identityType, attributes, offset, limit, orderByName, ascending);
+ }
+
+ public Collection<IdentityObject> findIdentityObject(IdentityStoreInvocationContext invocationCxt, IdentityObject identity, IdentityObjectRelationshipType relationshipType, boolean parent, int offset, int limit, boolean orderByName, boolean ascending) throws IdentityException
+ {
+ //TODO:!!!!!!
+ //return defaultIdentityStore.findIdentityObject(invocationCxt, identity, relationshipType, parent, offset, limit, orderByName, ascending);
+ throw new NotYetImplementedException();
+ }
+
+ public IdentityObjectRelationship createRelationship(IdentityStoreInvocationContext invocationCxt, IdentityObject fromIdentity, IdentityObject toIdentity, IdentityObjectRelationshipType relationshipType, String relationshipName, boolean createNames) throws IdentityException
+ {
+ IdentityStore fromStore = resolveIdentityStore(fromIdentity);
+ IdentityStore toStore = resolveIdentityStore(toIdentity);
+
+ if (fromStore == toStore)
+ {
+ return fromStore.createRelationship(invocationCxt, fromIdentity, toIdentity, relationshipType, relationshipName, createNames);
+ }
+
+ if (!hasIdentityObject(invocationCxt, defaultIdentityStore, fromIdentity))
+ {
+ defaultIdentityStore.createIdentityObject(invocationCxt, fromIdentity.getName(), fromIdentity.getIdentityType());
+ }
+
+ if (!hasIdentityObject(invocationCxt, defaultIdentityStore, toIdentity))
+ {
+ defaultIdentityStore.createIdentityObject(invocationCxt, toIdentity.getName(), toIdentity.getIdentityType());
+ }
+
+ return defaultIdentityStore.createRelationship(invocationCxt, fromIdentity, toIdentity, relationshipType, relationshipName, createNames);
+ }
+
+ public void removeRelationship(IdentityStoreInvocationContext invocationCxt, IdentityObject fromIdentity, IdentityObject toIdentity, IdentityObjectRelationshipType relationshipType, String relationshipName) throws IdentityException
+ {
+ IdentityStore fromStore = resolveIdentityStore(fromIdentity);
+ IdentityStore toStore = resolveIdentityStore(toIdentity);
+
+ if (fromStore == toStore)
+ {
+ fromStore.removeRelationship(invocationCxt, fromIdentity, toIdentity, relationshipType, relationshipName);
+ return;
+ }
+
+ if (!hasIdentityObject(invocationCxt, defaultIdentityStore, fromIdentity))
+ {
+ defaultIdentityStore.createIdentityObject(invocationCxt, fromIdentity.getName(), fromIdentity.getIdentityType());
+ }
+
+ if (!hasIdentityObject(invocationCxt, defaultIdentityStore, toIdentity))
+ {
+ defaultIdentityStore.createIdentityObject(invocationCxt, toIdentity.getName(), toIdentity.getIdentityType());
+ }
+
+ defaultIdentityStore.removeRelationship(invocationCxt, fromIdentity, toIdentity, relationshipType, relationshipName);
+ }
+
+ public void removeRelationships(IdentityStoreInvocationContext invocationCtx, IdentityObject identity1, IdentityObject identity2, boolean named) throws IdentityException
+ {
+ IdentityStore fromStore = resolveIdentityStore(identity1);
+ IdentityStore toStore = resolveIdentityStore(identity2);
+
+ if (fromStore == toStore)
+ {
+ fromStore.removeRelationships(invocationCtx, identity1, identity2, named);
+ return;
+ }
+
+ if (!hasIdentityObject(invocationCtx, defaultIdentityStore, identity1))
+ {
+ defaultIdentityStore.createIdentityObject(invocationCtx, identity1.getName(), identity1.getIdentityType());
+ }
+
+ if (!hasIdentityObject(invocationCtx, defaultIdentityStore, identity2))
+ {
+ defaultIdentityStore.createIdentityObject(invocationCtx, identity2.getName(), identity2.getIdentityType());
+ }
+
+ defaultIdentityStore.removeRelationships(invocationCtx, identity1, identity2, named);
+ }
+
+ public Set<IdentityObjectRelationship> resolveRelationships(IdentityStoreInvocationContext invocationCxt, IdentityObject fromIdentity, IdentityObject toIdentity) throws IdentityException
+ {
+ IdentityStore fromStore = resolveIdentityStore(fromIdentity);
+ IdentityStore toStore = resolveIdentityStore(toIdentity);
+
+ if (fromStore == toStore)
+ {
+ return fromStore.resolveRelationships(invocationCxt, fromIdentity, toIdentity);
+
+ }
+
+ if (!hasIdentityObject(invocationCxt, defaultIdentityStore, fromIdentity))
+ {
+ defaultIdentityStore.createIdentityObject(invocationCxt, fromIdentity.getName(), fromIdentity.getIdentityType());
+ }
+
+ if (!hasIdentityObject(invocationCxt, defaultIdentityStore, toIdentity))
+ {
+ defaultIdentityStore.createIdentityObject(invocationCxt, toIdentity.getName(), toIdentity.getIdentityType());
+ }
+
+ return defaultIdentityStore.resolveRelationships(invocationCxt, fromIdentity, toIdentity);
+ }
+
+ public String createRelationshipName(IdentityStoreInvocationContext ctx, String name) throws IdentityException, OperationNotSupportedException
+ {
+ //TODO: For now just assume that named relationships are in default one
+ return defaultIdentityStore.createRelationshipName(ctx, name);
+ }
+
+ public String removeRelationshipName(IdentityStoreInvocationContext ctx, String name) throws IdentityException, OperationNotSupportedException
+ {
+ //TODO: For now just assume that named relationships are in default one
+ return defaultIdentityStore.removeRelationshipName(ctx, name);
+ }
+
+ public Set<String> getRelationshipNames(IdentityStoreInvocationContext ctx, int offset, int limit, boolean orderByName, boolean ascending) throws IdentityException, OperationNotSupportedException
+ {
+ //TODO: For now just assume that named relationships are in default one
+ return defaultIdentityStore.getRelationshipNames(ctx, offset, limit, orderByName, ascending);
+ }
+
+ public Set<String> getRelationshipNames(IdentityStoreInvocationContext ctx, IdentityObject identity, int offset, int limit, boolean orderByName, boolean ascending) throws IdentityException, OperationNotSupportedException
+ {
+ //TODO: For now just assume that named relationships are in default one
+ return defaultIdentityStore.getRelationshipNames(ctx, identity, offset, limit, orderByName, ascending);
+ }
+
+ public boolean hasPasswordAttribute(IdentityStoreInvocationContext ctx, IdentityObjectType type) throws IdentityException
+ {
+ return resolveIdentityStore(type).hasPasswordAttribute(ctx, type);
+ }
+
+ public boolean validatePassword(IdentityStoreInvocationContext ctx, IdentityObject identityObject, String password) throws IdentityException
+ {
+ return resolveIdentityStore(identityObject).validatePassword(ctx, identityObject, password);
+ }
+
+ public void updatePassword(IdentityStoreInvocationContext ctx, IdentityObject identityObject, String password) throws IdentityException
+ {
+ resolveIdentityStore(identityObject).updatePassword(ctx, identityObject, password);
+ }
+
+
+ public <T extends IdentityObjectType> Set<String> getSupportedAttributeNames(IdentityStoreInvocationContext invocationContext, T identityType) throws IdentityException
+ {
+ //TODO: for profile stored in two stores this need to be merged with results from defaultAttributeStore. For now just use the default one.
+
+ return defaultAttributeStore.getSupportedAttributeNames(invocationContext, identityType);
+ //return resolveIdentityStore(identityType).getSupportedAttributeNames(invocationContext, identityType);
+ }
+
+ public Map<String, Set<String>> getAttributes(IdentityStoreInvocationContext invocationContext, IdentityObject identity) throws IdentityException
+ {
+ //TODO: for profile stored in two stores this need to be merged with results from defaultAttributeStore. For now just use the default one.
+
+ return defaultAttributeStore.getAttributes(invocationContext, identity);
+ //return resolveIdentityStore(identity).getAttributes(invocationContext, identity);
+ }
+
+ public void updateAttributes(IdentityStoreInvocationContext invocationCtx, IdentityObject identity, Map<String, Set<String>> attributes) throws IdentityException
+ {
+ //TODO: for profile stored in two stores this need to be merged with results from defaultAttributeStore. For now just use the default one.
+
+ defaultAttributeStore.updateAttributes(invocationCtx, identity, attributes);
+ //resolveIdentityStore(identity).updateAttributes(invocationCtx, identity, attributes);
+ }
+
+ public void addAttributes(IdentityStoreInvocationContext invocationCtx, IdentityObject identity, Map<String, Set<String>> attributes) throws IdentityException
+ {
+ //TODO: for profile stored in two stores this need to be merged with results from defaultAttributeStore. For now just use the default one.
+
+ defaultAttributeStore.addAttributes(invocationCtx, identity, attributes);
+ //resolveIdentityStore(identity).addAttributes(invocationCtx, identity, attributes);
+ }
+
+ public void removeAttributes(IdentityStoreInvocationContext invocationCtx, IdentityObject identity, Set<String> attributes) throws IdentityException
+ {
+ //TODO: for profile stored in two stores this need to be merged with results from defaultAttributeStore. For now just use the default one.
+
+ defaultAttributeStore.removeAttributes(invocationCtx, identity, attributes);
+ //resolveIdentityStore(identity).removeAttributes(invocationCtx, identity, attributes);
+ }
+
+
+}
\ No newline at end of file
Modified: trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/hibernate/HibernateIdentityStoreInvocationContext.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/hibernate/HibernateIdentityStoreInvocationContext.java 2008-10-17 20:52:50 UTC (rev 104)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/hibernate/HibernateIdentityStoreInvocationContext.java 2008-10-18 21:35:12 UTC (rev 105)
@@ -29,12 +29,9 @@
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
* @version : 0.1 $
*/
-public class HibernateIdentityStoreInvocationContext implements IdentityStoreInvocationContext
+public interface HibernateIdentityStoreInvocationContext extends IdentityStoreInvocationContext
{
- public HibernateEntityManager getHibernateEntityManager()
- {
- return null;
- }
+ public HibernateEntityManager getHibernateEntityManager();
}
Modified: trunk/identity-impl/src/test/java/org/jboss/identity/impl/HibernateTestSupport.java
===================================================================
--- trunk/identity-impl/src/test/java/org/jboss/identity/impl/HibernateTestSupport.java 2008-10-17 20:52:50 UTC (rev 104)
+++ trunk/identity-impl/src/test/java/org/jboss/identity/impl/HibernateTestSupport.java 2008-10-18 21:35:12 UTC (rev 105)
@@ -46,6 +46,16 @@
private Connection connection;
+ private final String databaseName;
+
+ private final String persistenceUnit;
+
+ public HibernateTestSupport(String databaseName, String persistenceUnit)
+ {
+ this.databaseName = databaseName;
+ this.persistenceUnit = persistenceUnit;
+ }
+
public HibernateEntityManager getHibernateEntityManager()
{
return em;
Modified: trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/APITestCase.java
===================================================================
--- trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/APITestCase.java 2008-10-17 20:52:50 UTC (rev 104)
+++ trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/APITestCase.java 2008-10-18 21:35:12 UTC (rev 105)
@@ -26,17 +26,38 @@
import org.jboss.identity.impl.HibernateTestSupport;
import org.jboss.identity.impl.store.hibernate.HibernateIdentityStoreImpl;
import org.jboss.identity.impl.store.hibernate.HibernateIdentityStoreInvocationContext;
+import org.jboss.identity.impl.store.ldap.LDAPIdentityObjectTypeConfiguration;
+import org.jboss.identity.impl.store.ldap.SimpleLDAPIdentityObjectTypeConfiguration;
+import org.jboss.identity.impl.store.ldap.SimpleLDAPIdentityStoreConfiguration;
+import org.jboss.identity.impl.store.ldap.SimpleLDAPIdentityStoreInvocationContext;
+import org.jboss.identity.impl.store.ldap.LDAPIdentityStoreInvocationContext;
+import org.jboss.identity.impl.store.ldap.LDAPIdentityStoreConfiguration;
+import org.jboss.identity.impl.store.ldap.LDAPIdentityStore;
+import org.jboss.identity.impl.store.IdentityTypeEnum;
import org.jboss.identity.impl.repository.WrapperIdentityStoreRepository;
+import org.jboss.identity.impl.repository.FallbackIdentityStoreRepository;
import org.jboss.identity.api.IdentitySessionFactory;
import org.jboss.identity.api.IdentitySession;
import org.jboss.identity.spi.repository.IdentityStoreRepository;
import org.jboss.identity.spi.store.IdentityStoreInvocationContext;
+import org.jboss.identity.spi.store.IdentityStore;
+import org.jboss.identity.spi.store.AttributeStore;
+import org.jboss.identity.opends.OpenDSService;
import org.hibernate.ejb.HibernateEntityManager;
+import org.opends.server.tools.LDAPModify;
+import javax.naming.directory.DirContext;
+import javax.naming.Context;
+import javax.naming.NamingEnumeration;
+import javax.naming.Binding;
+import javax.naming.ldap.LdapContext;
+import javax.naming.ldap.InitialLdapContext;
import java.util.Set;
import java.util.HashSet;
import java.util.Map;
import java.util.HashMap;
+import java.util.Hashtable;
+import java.io.File;
/**
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
@@ -44,67 +65,231 @@
*/
public class APITestCase extends TestCase implements APITestContext
{
- HibernateTestSupport hibernateSupport = new HibernateTestSupport();
+ //TODO: Code below is hardly readable mess... just made it quickly for prototyping. Testing bits will be cleanly initialized
+ //TODO: once I make XML configuration for all services
+
+ HibernateTestSupport hibernateSupport = new HibernateTestSupport("unit-testing-jpa", "jboss-identity-model");
+
+ LDAPIdentityStoreInvocationContext ctx;
+
OrganizationTest orgTest;
IdentitySessionFactory identitySessionFactory;
+ public static final String LDAP_HOST = "localhost";
+
+ public static final String LDAP_PORT = "10389";
+
+ public static final String LDAP_PROVIDER_URL = "ldap://" + LDAP_HOST + ":" + LDAP_PORT;
+
+ public static final String LDAP_PRINCIPAL = "cn=Directory Manager";
+
+ public static final String LDAP_CREDENTIALS = "password";
+
+ static Hashtable<String,String> env = new Hashtable<String,String>();
+
+ static
+ {
+ 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);
+ }
+
+ OpenDSService openDSService = new OpenDSService("target/test-classes/opends");
+
protected void setUp() throws Exception
{
super.setUp();
hibernateSupport.start();
orgTest = new OrganizationTest(this);
+ openDSService.start();
}
protected void tearDown() throws Exception
{
hibernateSupport.stop();
+
+ cleanUp(new InitialLdapContext(env, null));
+
+ openDSService.stop();
}
- public void testOrganization() throws Exception
+ public void testDBOrganization() throws Exception
{
- prepareRealm(OrganizationTest.RED_HAT_REALM, new String[]{"IDENTITY", "ORGANIZATION", "ORGANIZATION_UNIT", "DIVISION", "DEPARTMENT", "PROJECT", "PEOPLE"});
+ IdentityStore store = new HibernateIdentityStoreImpl();
+ IdentityStoreRepository repository = new WrapperIdentityStoreRepository(store, store, null, null);
+ final IdentityStoreInvocationContext invocationContext = new HibernateIdentityStoreInvocationContext()
+ {
+ public HibernateEntityManager getHibernateEntityManager()
+ {
+ return hibernateSupport.getHibernateEntityManager();
+ }
+ };
+ prepareRealm(repository, invocationContext, OrganizationTest.RED_HAT_REALM,
+ new String[]{"IDENTITY", "ORGANIZATION", "ORGANIZATION_UNIT", "DIVISION", "DEPARTMENT", "PROJECT", "PEOPLE"});
orgTest.testRedHatOrganization();
}
- public void testSamplePortal() throws Exception
+ public void testDBSamplePortal() throws Exception
{
- prepareRealm(OrganizationTest.PORTAL_REALM, new String[]{"IDENTITY", "SYSTEM", "ADMINISTRATION", "COMMUNITY", "ORGANIZATION", "ORGANIZATION_UNIT", "OFFICE", "DIVISION", "DEPARTMENT", "SECURITY", "PEOPLE"});
+ IdentityStore store = new HibernateIdentityStoreImpl();
+ IdentityStoreRepository repository = new WrapperIdentityStoreRepository(store, store, null, null);
+ final IdentityStoreInvocationContext invocationContext = new HibernateIdentityStoreInvocationContext()
+ {
+ public HibernateEntityManager getHibernateEntityManager()
+ {
+ return hibernateSupport.getHibernateEntityManager();
+ }
+ };
+ prepareRealm(repository, invocationContext, OrganizationTest.PORTAL_REALM,
+ new String[]{"IDENTITY", "SYSTEM", "ADMINISTRATION", "COMMUNITY", "ORGANIZATION", "ORGANIZATION_UNIT",
+ "OFFICE", "DIVISION", "DEPARTMENT", "SECURITY", "PEOPLE"});
orgTest.testSamplePortal();
}
- private void prepareRealm(String realmName, String[] objectTypes) throws Exception
+ public void testLDAPMixedOrganization() throws Exception
{
+ populateClean();
- Set<SessionWrapper> sessionWrappers = new HashSet<SessionWrapper>();
- sessionWrappers.add(new EntityManagerWrapper(hibernateSupport.getHibernateEntityManager()));
+ IdentityStore hibernateStore = new HibernateIdentityStoreImpl();
- hibernateSupport.populateObjectTypes(objectTypes);
- hibernateSupport.populateRelationshipTypes(new String[]{"JBOSS_IDENTITY_MEMBERSHIP", "JBOSS_IDENTITY_ROLE"});
+ final LDAPIdentityStoreConfiguration ldapConfig = createLDAPConfig("IDENTITY", null, null);
- HibernateIdentityStoreImpl store = new HibernateIdentityStoreImpl();
+
- ;
+ IdentityStore ldapStore = new LDAPIdentityStore("LDAPStore");
- IdentityStoreRepository repository = new WrapperIdentityStoreRepository(store, store, null, null);
+ Map<String, IdentityStore> isMap = new HashMap<String, IdentityStore>();
+ isMap.put("IDENTITY",ldapStore);
+ isMap.put("ORGANIZATION",hibernateStore);
+ isMap.put("ORGANIZATION_UNIT",hibernateStore);
+ isMap.put("DIVISION",hibernateStore);
+ isMap.put("DEPARTMENT",hibernateStore);
+ isMap.put("PROJECT",hibernateStore);
+ isMap.put("PEOPLE",hibernateStore);
- IdentityObjectTypeMapper iotMapper = new DirectIdentityObjectTypeMapperImpl("IDENTITY");
+ Map<String, AttributeStore> asMap = new HashMap<String, AttributeStore>();
+ isMap.put("IDENTITY",ldapStore);
+ isMap.put("ORGANIZATION",hibernateStore);
+ isMap.put("ORGANIZATION_UNIT",hibernateStore);
+ isMap.put("DIVISION",hibernateStore);
+ isMap.put("DEPARTMENT",hibernateStore);
+ isMap.put("PROJECT",hibernateStore);
+ isMap.put("PEOPLE",hibernateStore);
- final HibernateIdentityStoreInvocationContext hibernateInvocationContext = new HibernateIdentityStoreInvocationContext()
+ IdentityStoreRepository repository = new FallbackIdentityStoreRepository(hibernateStore, hibernateStore, isMap, asMap);
+
+ final IdentityStoreInvocationContext invocationContext = new TestInvocationContext()
{
+ public LdapContext getLdapContext() throws Exception
+ {
+
+
+ return new InitialLdapContext(env, null);
+ }
+
+ public LDAPIdentityStoreConfiguration getConfiguration()
+ {
+ return ldapConfig;
+ }
+
public HibernateEntityManager getHibernateEntityManager()
{
return hibernateSupport.getHibernateEntityManager();
}
};
+ prepareRealm(repository, invocationContext, OrganizationTest.RED_HAT_REALM,
+ new String[]{"IDENTITY", "ORGANIZATION", "ORGANIZATION_UNIT", "DIVISION", "DEPARTMENT", "PROJECT", "PEOPLE"});
+ orgTest.testRedHatOrganization();
+ }
+
+ public void testLDAPMixedSamplePortal() throws Exception
+ {
+ populateClean();
+
+ IdentityStore hibernateStore = new HibernateIdentityStoreImpl();
+
+ final LDAPIdentityStoreConfiguration ldapConfig = createLDAPConfig("IDENTITY", null, null);
+
+ IdentityStore ldapStore = new LDAPIdentityStore("LDAPStore");
+
+ Map<String, IdentityStore> isMap = new HashMap<String, IdentityStore>();
+ isMap.put("IDENTITY",ldapStore);
+ isMap.put("SYSTEM",hibernateStore);
+ isMap.put("ADMINISTRATION",hibernateStore);
+ isMap.put("COMMUNITY",hibernateStore);
+ isMap.put("ORGANIZATION",hibernateStore);
+ isMap.put("ORGANIZATION_UNIT",hibernateStore);
+ isMap.put("OFFICE",hibernateStore);
+ isMap.put("DIVISION",hibernateStore);
+ isMap.put("DEPARTMENT",hibernateStore);
+ isMap.put("SECURITY",hibernateStore);
+ isMap.put("PEOPLE",hibernateStore);
+
+ Map<String, AttributeStore> asMap = new HashMap<String, AttributeStore>();
+ asMap.put("IDENTITY",ldapStore);
+ asMap.put("SYSTEM",hibernateStore);
+ asMap.put("ADMINISTRATION",hibernateStore);
+ asMap.put("COMMUNITY",hibernateStore);
+ asMap.put("ORGANIZATION",hibernateStore);
+ asMap.put("ORGANIZATION_UNIT",hibernateStore);
+ asMap.put("OFFICE",hibernateStore);
+ asMap.put("DIVISION",hibernateStore);
+ asMap.put("DEPARTMENT",hibernateStore);
+ asMap.put("SECURITY",hibernateStore);
+ asMap.put("PEOPLE",hibernateStore);
+
+ IdentityStoreRepository repository = new FallbackIdentityStoreRepository(hibernateStore, hibernateStore, isMap, asMap);
+
+ final IdentityStoreInvocationContext invocationContext = new TestInvocationContext()
+ {
+ public LdapContext getLdapContext() throws Exception
+ {
+ return new InitialLdapContext(env, null);
+ }
+
+ public LDAPIdentityStoreConfiguration getConfiguration()
+ {
+ return ldapConfig;
+ }
+
+ public HibernateEntityManager getHibernateEntityManager()
+ {
+ return hibernateSupport.getHibernateEntityManager();
+ }
+ };
+
+ prepareRealm(repository, invocationContext, OrganizationTest.PORTAL_REALM,
+ new String[]{"IDENTITY", "SYSTEM", "ADMINISTRATION", "COMMUNITY", "ORGANIZATION", "ORGANIZATION_UNIT",
+ "OFFICE", "DIVISION", "DEPARTMENT", "SECURITY", "PEOPLE"});
+ orgTest.testSamplePortal();
+ }
+
+ // Helper
+
+ private void prepareRealm(IdentityStoreRepository repository, final IdentityStoreInvocationContext invocationContext, String realmName, String[] objectTypes) throws Exception
+ {
+
+ Set<SessionWrapper> sessionWrappers = new HashSet<SessionWrapper>();
+ sessionWrappers.add(new EntityManagerWrapper(hibernateSupport.getHibernateEntityManager()));
+
+ hibernateSupport.populateObjectTypes(objectTypes);
+ hibernateSupport.populateRelationshipTypes(new String[]{"JBOSS_IDENTITY_MEMBERSHIP", "JBOSS_IDENTITY_ROLE"});
+
+ IdentityObjectTypeMapper iotMapper = new DirectIdentityObjectTypeMapperImpl("IDENTITY");
+
+
+
IdentityStoreInvocationContextResolver contextResolver = new IdentityStoreInvocationContextResolver()
{
public IdentityStoreInvocationContext resolveInvocationContext()
{
- return hibernateInvocationContext;
+ return invocationContext;
}
};
@@ -127,6 +312,149 @@
return identitySessionFactory;
}
+ public void populate() throws Exception
+ {
+ populateLDIF("target/test-classes/ldap/initial-opends.ldif");
+ }
+ public void populateClean() throws Exception
+ {
+ populateLDIF("target/test-classes/ldap/initial-empty-opends.ldif");
+ }
+
+ public void populateLDIF(String ldifRelativePath) throws Exception
+ {
+ File ldif = new File(ldifRelativePath);
+
+ System.out.println("LDIF: " + ldif.getAbsolutePath());
+
+ String[] cmd = new String[] {"-h", LDAP_HOST,
+ "-p", LDAP_PORT,
+ "-D", LDAP_PRINCIPAL,
+ "-w", LDAP_CREDENTIALS,
+ "-a", "-f", ldif.getPath()};
+
+ System.out.println("Populate success: " + (LDAPModify.mainModify(cmd, false, System.out, System.err) == 0));
+
+ }
+
+ protected void cleanUp(DirContext ldapCtx) throws Exception
+ {
+ try
+ {
+ String dn = "dc=portal,dc=example,dc=com";
+
+ System.out.println("Removing: " + dn);
+
+ removeContext(ldapCtx, dn);
+ }
+ catch (Exception e)
+ {
+ //
+ }
+ }
+
+ //subsequent remove of javax.naming.Context
+ protected void removeContext(Context mainCtx, String name) throws Exception
+ {
+ Context deleteCtx = (Context)mainCtx.lookup(name);
+ NamingEnumeration subDirs = mainCtx.listBindings(name);
+
+ while (subDirs.hasMoreElements())
+ {
+ Binding binding = (Binding)subDirs.nextElement();
+ String subName = binding.getName();
+
+ removeContext(deleteCtx, subName);
+ }
+
+ mainCtx.unbind(name);
+ }
+
+ private SimpleLDAPIdentityStoreConfiguration createLDAPConfig(String peopleTypeName, String rolesTypeName, String groupsTypeName)
+ {
+
+ Map<String, LDAPIdentityObjectTypeConfiguration> typesMap = new HashMap<String, LDAPIdentityObjectTypeConfiguration>();
+
+ //People
+ SimpleLDAPIdentityObjectTypeConfiguration tc = new SimpleLDAPIdentityObjectTypeConfiguration();
+ tc.setAllowCreateEntry(true);
+ tc.setAllowedMembershipTypes(new String[] {});
+ tc.setAllowEmptyMemberships(true);
+ Map<String, String> attrs = new HashMap<String, String>();
+ 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"});
+ newAttrs.put("sn", new String[]{" "});
+ newAttrs.put("cn", new String[]{" "});
+
+ tc.setCreateEntryAttributeValues(newAttrs);
+ tc.setCtxDNs(new String[] {"ou=People,o=test,dc=portal,dc=example,dc=com"});
+ tc.setEntrySearchFilter(null);
+ tc.setIdAttributeName("uid");
+ tc.setMembershipAttributeDN(true);
+ tc.setMembershipAttributeName(null);
+ typesMap.put(peopleTypeName, tc);
+
+
+ if (rolesTypeName != null)
+ {
+ // ROLE
+ tc = new SimpleLDAPIdentityObjectTypeConfiguration();
+ tc.setAllowCreateEntry(true);
+ tc.setAllowedMembershipTypes(new String[] {IdentityTypeEnum.USER.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=Roles,o=test,dc=portal,dc=example,dc=com"});
+ tc.setEntrySearchFilter(null);
+ tc.setIdAttributeName("cn");
+ tc.setMembershipAttributeDN(true);
+ tc.setMembershipAttributeName("member");
+ typesMap.put(rolesTypeName, tc);
+ }
+
+ if (groupsTypeName != null)
+ {
+ // GROUP
+ 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=Groups,o=test,dc=portal,dc=example,dc=com"});
+ tc.setEntrySearchFilter(null);
+ tc.setIdAttributeName("cn");
+ tc.setMembershipAttributeDN(true);
+ tc.setMembershipAttributeName("member");
+ typesMap.put(groupsTypeName, tc);
+ }
+
+ return new SimpleLDAPIdentityStoreConfiguration(
+ LDAP_PROVIDER_URL,
+ LDAP_PRINCIPAL,
+ LDAP_CREDENTIALS,
+ 10000,
+ typesMap);
+ }
+
+ private interface TestInvocationContext extends HibernateIdentityStoreInvocationContext, LDAPIdentityStoreInvocationContext
+ {
+
+ }
+
}
Modified: trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/hibernate/HibernateTestBase.java
===================================================================
--- trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/hibernate/HibernateTestBase.java 2008-10-17 20:52:50 UTC (rev 104)
+++ trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/hibernate/HibernateTestBase.java 2008-10-18 21:35:12 UTC (rev 105)
@@ -42,7 +42,7 @@
{
private static Logger logger = Logger.getLogger(HibernateModelTestCase.class.getName());
- private HibernateTestSupport hibernateSupport = new HibernateTestSupport();
+ private HibernateTestSupport hibernateSupport = new HibernateTestSupport("unit-testing-jpa", "jboss-identity-model");
protected HibernateEntityManager em;
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-10-17 20:52:50 UTC (rev 104)
+++ trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/ldap/LDAPIdentityStoreTestCase.java 2008-10-18 21:35:12 UTC (rev 105)
@@ -226,7 +226,7 @@
// ROLE
- tc = new SimpleLDAPIdentityObjectTypeConfiguration();
+ tc = new SimpleLDAPIdentityObjectTypeConfiguration();
tc.setAllowCreateEntry(true);
tc.setAllowedMembershipTypes(new String[] {IdentityTypeEnum.USER.getName()});
tc.setAllowEmptyMemberships(true);
@@ -296,197 +296,197 @@
// 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());
-//
-// }
+// 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();
@@ -495,20 +495,20 @@
}
-// public void testStorePersistence() throws Exception
-// {
-// populateClean();
-//
-// commonTest.testStorePersistence();
-//
-// }
-//
-// public void testFindMethods() throws Exception
-// {
-// populateClean();
-//
-// commonTest.testFindMethods();
-//
-// }
+ public void testStorePersistence() throws Exception
+ {
+ populateClean();
+ commonTest.testStorePersistence();
+
+ }
+
+ public void testFindMethods() throws Exception
+ {
+ populateClean();
+
+ commonTest.testFindMethods();
+
+ }
+
}
16 years, 3 months
JBoss Identity SVN: r104 - in trunk: identity-impl and 12 other directories.
by jboss-identity-commits@lists.jboss.org
Author: bdaw
Date: 2008-10-17 16:52:50 -0400 (Fri, 17 Oct 2008)
New Revision: 104
Added:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/AbstractManager.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/DirectIdentityObjectTypeMapperImpl.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/EntityManagerWrapper.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentityObjectTypeMapper.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentityObjectTypeMapperImpl.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentitySessionContext.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentitySessionContextImpl.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentitySessionFactoryImpl.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentitySessionImpl.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentityStoreInvocationContextResolver.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/PersistenceManagerImpl.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/ProfileManagerImpl.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/RelationshipManagerImpl.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/RoleHandler.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/RoleManagerImpl.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SessionWrapper.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleGroupImpl.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleGroupType.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleIdentityImpl.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleRoleImpl.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleRoleType.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleTransactionImpl.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/repository/
trunk/identity-impl/src/main/java/org/jboss/identity/impl/repository/AbstractIdentityStoreRepository.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/repository/WrapperIdentityStoreRepository.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/HibernateTestSupport.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/APITestCase.java
Removed:
trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/SimpleGroupType.java
Modified:
trunk/identity-api/src/main/java/org/jboss/identity/api/IdentitySession.java
trunk/identity-api/src/main/java/org/jboss/identity/api/PersistenceManager.java
trunk/identity-api/src/main/java/org/jboss/identity/api/RoleManager.java
trunk/identity-impl/pom.xml
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/hibernate/HibernateIdentityObjectRelationshipName.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/LDAPIdentityStore.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/types/SimpleIdentityObject.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/OrganizationTest.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/hibernate/HibernateTestBase.java
trunk/identity-spi/src/main/java/org/jboss/identity/spi/repository/IdentityStoreRepository.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
Log:
code backup
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-10-15 10:59:42 UTC (rev 103)
+++ trunk/identity-api/src/main/java/org/jboss/identity/api/IdentitySession.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -41,12 +41,6 @@
String getRealmName();
/**
- * Open the session
- * @throws org.jboss.identity.exception.IdentityException
- */
- void open() throws IdentityException;
-
- /**
* Close this session
* @throws org.jboss.identity.exception.IdentityException
*/
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-10-15 10:59:42 UTC (rev 103)
+++ trunk/identity-api/src/main/java/org/jboss/identity/api/PersistenceManager.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -135,13 +135,13 @@
* @param filterName can be null
* @param offset
* @param limit 0 means unlimited page size
- * @param orderedByAttributeName can be null
+ * @param orderedByName
* @param ascending default true
* @return
* @throws org.jboss.identity.exception.IdentityException
*/
Collection<Identity> findIdentity(String filterName, int offset, int limit,
- String orderedByAttributeName,
+ boolean orderedByName,
boolean ascending) throws IdentityException;
/**
@@ -153,14 +153,14 @@
* @param attributes
* @param offset
* @param limit 0 means unlimited page size
- * @param orderedByAttributeName can be null
+ * @param orderedByName
* @param ascending default true
* @return
* @throws org.jboss.identity.exception.IdentityException
*/
Collection<Identity> findIdentity(String filterName, Map<String, String[]> attributes,
int offset, int limit,
- String orderedByAttributeName, boolean ascending) throws IdentityException;
+ boolean orderedByName, boolean ascending) throws IdentityException;
// Search Groups
@@ -193,14 +193,14 @@
* @param filterName can be null
* @param offset
* @param limit 0 means unlimited page size
- * @param orderedByAttributeName can be null
+ * @param orderedByName can be null
* @param ascending default true
* @return
* @throws org.jboss.identity.exception.IdentityException
*/
- Collection<Group> findRole(GroupType groupType, String filterName,
+ Collection<Group> findGroup(GroupType groupType, String filterName,
int offset, int limit,
- String orderedByAttributeName,
+ boolean orderedByName,
boolean ascending) throws IdentityException;
/**
@@ -209,18 +209,16 @@
* 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
- * @param orderedByAttributeName can be null
+ * @param orderedByName can be null
* @param ascending default true
* @return
* @throws org.jboss.identity.exception.IdentityException
*/
- Collection<Group> findGroup(GroupType groupType, String filterName,
- Map<String, String[]> attributes,
+ Collection<Group> findGroup(GroupType groupType, Map<String, String[]> attributes,
int offset, int limit,
- String orderedByAttributeName, boolean ascending) throws IdentityException;
+ boolean orderedByName, boolean ascending) throws IdentityException;
}
Modified: trunk/identity-api/src/main/java/org/jboss/identity/api/RoleManager.java
===================================================================
--- trunk/identity-api/src/main/java/org/jboss/identity/api/RoleManager.java 2008-10-15 10:59:42 UTC (rev 103)
+++ trunk/identity-api/src/main/java/org/jboss/identity/api/RoleManager.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -74,7 +74,6 @@
/**
* Find all RoleType objects stored
- * @param filterName
* @param offset
* @param limit
* @param orderedByName
@@ -82,9 +81,8 @@
* @return
* @throws IdentityException
*/
- Collection<RoleType> findRoleTypes(String filterName,
- int offset, int limit,
- String orderedByName,
+ Collection<RoleType> findRoleTypes(int offset, int limit,
+ boolean orderedByName,
boolean ascending) throws IdentityException;
@@ -160,7 +158,7 @@
/**
* Find RoleType objects for roles associated with a given Group
- * @param identity
+ * @param group
* @param offset
* @param limit
* @param orderedByName
@@ -168,7 +166,7 @@
* @return
* @throws IdentityException
*/
- Collection<RoleType> findGroupRoleTypes(Identity identity,
+ Collection<RoleType> findGroupRoleTypes(Group group,
int offset, int limit,
boolean orderedByName,
boolean ascending) throws IdentityException;
Modified: trunk/identity-impl/pom.xml
===================================================================
--- trunk/identity-impl/pom.xml 2008-10-15 10:59:42 UTC (rev 103)
+++ trunk/identity-impl/pom.xml 2008-10-17 20:52:50 UTC (rev 104)
@@ -27,7 +27,6 @@
<url>http://viewvc.jboss.org/cgi-bin/viewvc.cgi/jbossidentity/trunk</url>
</scm>
-
<dependencies>
<dependency>
<groupId>org.jboss.identity</groupId>
Added: trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/AbstractManager.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/AbstractManager.java (rev 0)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/AbstractManager.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -0,0 +1,125 @@
+/*
+* 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.Identity;
+import org.jboss.identity.api.Group;
+import org.jboss.identity.api.GroupType;
+import org.jboss.identity.api.IdentityType;
+import org.jboss.identity.spi.repository.IdentityStoreRepository;
+import org.jboss.identity.spi.store.IdentityStoreInvocationContext;
+import org.jboss.identity.spi.model.IdentityObject;
+import org.jboss.identity.spi.model.IdentityObjectType;
+import org.jboss.identity.impl.types.SimpleIdentityObject;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public abstract class AbstractManager
+{
+ protected final IdentitySession identitySession;
+
+ protected AbstractManager(IdentitySession session)
+ {
+ this.identitySession = session;
+ }
+
+ public IdentitySession getIdentitySession()
+ {
+ return identitySession;
+ }
+
+ protected IdentitySessionContext getSessionContext()
+ {
+ if (identitySession instanceof IdentitySessionImpl)
+ {
+ return ((IdentitySessionImpl)identitySession).getSessionContext();
+ }
+ return null;
+ }
+
+ protected IdentityStoreRepository getRepository()
+ {
+ return getSessionContext().getIdentityStoreRepository();
+ }
+
+ protected IdentityStoreInvocationContext getInvocationContext()
+ {
+ return getSessionContext().resolveStoreInvocationContext();
+ }
+
+ protected Identity createIdentity(IdentityObject identityObject)
+ {
+ return new SimpleIdentityImpl(identityObject.getName(), identityObject.getId());
+ }
+
+ protected Group createGroup(IdentityObject identityObject)
+ {
+ GroupType groupType = getSessionContext().getIdentityObjectTypeMapper().getGroupType(identityObject.getIdentityType());
+ return new SimpleGroupImpl(identityObject.getName(), identityObject.getId(), groupType);
+ }
+
+ protected IdentityObject createIdentityObject(Identity identity)
+ {
+ IdentityObjectType iot = getSessionContext().getIdentityObjectTypeMapper().getIdentityObjectType();
+
+ return new SimpleIdentityObject(identity.getName(), identity.getId(), iot);
+ }
+
+ protected IdentityObject createIdentityObject(Group group)
+ {
+ IdentityObjectType iot = getSessionContext().getIdentityObjectTypeMapper().getIdentityObjectType(group.getGroupType());
+
+ return new SimpleIdentityObject(group.getName(), group.getId(), iot);
+ }
+
+ protected IdentityObject createIdentityObject(IdentityType identityType)
+ {
+ if (identityType instanceof Identity)
+ {
+ return createIdentityObject((Identity)identityType);
+ }
+ else if (identityType instanceof Group)
+ {
+ return createIdentityObject((Group)identityType);
+ }
+
+ throw new IllegalStateException("Not supported IdentityType extension: " + identityType.getClass());
+
+ }
+
+ protected IdentityObjectType getIdentityObjectType()
+ {
+ return getSessionContext().getIdentityObjectTypeMapper().getIdentityObjectType();
+ }
+
+ protected IdentityObjectType getIdentityObjectType(GroupType groupType)
+ {
+ return getSessionContext().getIdentityObjectTypeMapper().getIdentityObjectType(groupType);
+ }
+
+
+
+}
Added: trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/DirectIdentityObjectTypeMapperImpl.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/DirectIdentityObjectTypeMapperImpl.java (rev 0)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/DirectIdentityObjectTypeMapperImpl.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -0,0 +1,101 @@
+/*
+* 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.spi.model.IdentityObjectType;
+import org.jboss.identity.impl.types.SimpleIdentityObjectType;
+import org.jboss.identity.api.GroupType;
+
+import java.util.Map;
+import java.util.Collections;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class DirectIdentityObjectTypeMapperImpl implements IdentityObjectTypeMapper
+{
+
+ private final String identityTypeName;
+
+ public DirectIdentityObjectTypeMapperImpl(String identityTypeName)
+ {
+ this.identityTypeName = identityTypeName;
+ }
+
+ public IdentityObjectType getIdentityObjectType()
+ {
+ return new SimpleIdentityObjectType(identityTypeName);
+ }
+
+ public IdentityObjectType getIdentityObjectType(GroupType groupType)
+ {
+ if (groupType == null)
+ {
+ throw new IllegalArgumentException("groupType is null");
+ }
+
+ return new SimpleIdentityObjectType(groupType.getName());
+ }
+
+ public GroupType getGroupType(IdentityObjectType identityObjectType)
+ {
+ if (identityObjectType == null)
+ {
+ throw new IllegalArgumentException("identityObjectType is null");
+ }
+
+ return new SimpleGroupType(identityObjectType.getName());
+
+ }
+
+ public boolean isGroupType(IdentityObjectType identityObjectType)
+ {
+ if (identityObjectType == null)
+ {
+ throw new IllegalArgumentException("identityObjectType is null");
+ }
+
+ if (isIdentity(identityObjectType))
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+
+ public boolean isIdentity(IdentityObjectType identityObjectType)
+ {
+ if (identityObjectType == null)
+ {
+ throw new IllegalArgumentException("identityObjectType is null");
+ }
+
+ if (identityObjectType.getName().equals(identityTypeName))
+ {
+ return true;
+ }
+ return false;
+ }
+}
Added: trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/EntityManagerWrapper.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/EntityManagerWrapper.java (rev 0)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/EntityManagerWrapper.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -0,0 +1,86 @@
+/*
+* 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.exception.IdentityException;
+
+import javax.persistence.EntityManager;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class EntityManagerWrapper implements SessionWrapper
+{
+ private final EntityManager em;
+
+ public EntityManagerWrapper(EntityManager entityManager)
+ {
+ this.em = entityManager;
+ }
+
+ public void close() throws IdentityException
+ {
+ em.close();
+ }
+
+ public void save() throws IdentityException
+ {
+ em.flush();
+ }
+
+ public void clear() throws IdentityException
+ {
+ em.clear();
+ }
+
+ public boolean isOpen()
+ {
+ return em.isOpen();
+ }
+
+ public boolean isTransactionSupported()
+ {
+ return true;
+ }
+
+ public void startTransaction()
+ {
+ em.getTransaction().begin();
+ }
+
+ public void commitTransaction()
+ {
+ em.getTransaction().commit();
+ }
+
+ public void rollbackTransaction()
+ {
+ em.getTransaction().rollback();
+ }
+
+ public boolean isTransactionActive()
+ {
+ return em.getTransaction().isActive();
+ }
+}
Added: trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentityObjectTypeMapper.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentityObjectTypeMapper.java (rev 0)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentityObjectTypeMapper.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -0,0 +1,51 @@
+/*
+* 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.spi.model.IdentityObject;
+import org.jboss.identity.spi.model.IdentityObjectType;
+import org.jboss.identity.api.Identity;
+import org.jboss.identity.api.GroupType;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public interface IdentityObjectTypeMapper
+{
+
+ IdentityObjectType getIdentityObjectType();
+
+
+ IdentityObjectType getIdentityObjectType(GroupType groupType);
+
+
+ GroupType getGroupType(IdentityObjectType identityObjectType);
+
+
+ boolean isGroupType(IdentityObjectType identityObjectType);
+
+
+ boolean isIdentity(IdentityObjectType identityObjectType);
+
+}
Added: trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentityObjectTypeMapperImpl.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentityObjectTypeMapperImpl.java (rev 0)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentityObjectTypeMapperImpl.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -0,0 +1,128 @@
+/*
+* 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.spi.model.IdentityObjectType;
+import org.jboss.identity.api.Identity;
+import org.jboss.identity.api.GroupType;
+import org.jboss.identity.impl.types.SimpleIdentityObjectType;
+
+import java.util.Map;
+import java.util.Collections;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class IdentityObjectTypeMapperImpl implements IdentityObjectTypeMapper
+{
+
+ /**
+ * IdentityObjectType --> GroupType
+ */
+ private final Map<String, String> groupTypeMap;
+
+ private final String identityTypeName;
+
+ public IdentityObjectTypeMapperImpl(Map<String, String> map, String identityTypeName)
+ {
+ groupTypeMap = Collections.unmodifiableMap(map);
+ this.identityTypeName = identityTypeName;
+ }
+
+ public IdentityObjectType getIdentityObjectType()
+ {
+ return new SimpleIdentityObjectType(identityTypeName);
+ }
+
+ public IdentityObjectType getIdentityObjectType(GroupType groupType)
+ {
+ if (groupType == null)
+ {
+ throw new IllegalArgumentException("groupType is null");
+ }
+
+ for (Map.Entry<String, String> entry : groupTypeMap.entrySet())
+ {
+ if (entry.getValue().equals(groupType.getName()))
+ {
+ return new SimpleIdentityObjectType(entry.getKey());
+ }
+ }
+
+ return null;
+ }
+
+ public GroupType getGroupType(IdentityObjectType identityObjectType)
+ {
+ if (identityObjectType == null)
+ {
+ throw new IllegalArgumentException("identityObjectType is null");
+ }
+
+ String name = groupTypeMap.get(identityObjectType.getName());
+
+ if (name != null)
+ {
+ return new SimpleGroupType(name);
+ }
+
+ return null;
+
+ }
+
+ public boolean isGroupType(IdentityObjectType identityObjectType)
+ {
+ if (identityObjectType == null)
+ {
+ throw new IllegalArgumentException("identityObjectType is null");
+ }
+
+ if (isIdentity(identityObjectType))
+ {
+ return false;
+ }
+
+ if (groupTypeMap.containsKey(identityObjectType.getName()))
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+
+ public boolean isIdentity(IdentityObjectType identityObjectType)
+ {
+ if (identityObjectType == null)
+ {
+ throw new IllegalArgumentException("identityObjectType is null");
+ }
+
+ if (identityObjectType.getName().equals(identityTypeName))
+ {
+ return true;
+ }
+ return false;
+ }
+}
Added: trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentitySessionContext.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentitySessionContext.java (rev 0)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentitySessionContext.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -0,0 +1,41 @@
+/*
+* 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.spi.repository.IdentityStoreRepository;
+import org.jboss.identity.spi.store.IdentityStoreInvocationContext;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public interface IdentitySessionContext
+{
+
+ IdentityStoreRepository getIdentityStoreRepository();
+
+ IdentityObjectTypeMapper getIdentityObjectTypeMapper();
+
+ IdentityStoreInvocationContext resolveStoreInvocationContext();
+
+}
Added: trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentitySessionContextImpl.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentitySessionContextImpl.java (rev 0)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentitySessionContextImpl.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -0,0 +1,62 @@
+/*
+* 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.spi.repository.IdentityStoreRepository;
+import org.jboss.identity.spi.store.IdentityStoreInvocationContext;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class IdentitySessionContextImpl implements IdentitySessionContext
+{
+ private final IdentityStoreRepository identityStoreRepository;
+
+ private final IdentityObjectTypeMapper identityObjectTypeMapper;
+
+ private final IdentityStoreInvocationContextResolver contextResolver;
+
+
+ public IdentitySessionContextImpl(IdentityStoreRepository identityStoreRepository, IdentityObjectTypeMapper identityObjectTypeMapper, IdentityStoreInvocationContextResolver contextResolver)
+ {
+ this.identityStoreRepository = identityStoreRepository;
+ this.identityObjectTypeMapper = identityObjectTypeMapper;
+ this.contextResolver = contextResolver;
+ }
+
+ public IdentityStoreRepository getIdentityStoreRepository()
+ {
+ return identityStoreRepository;
+ }
+
+ public IdentityObjectTypeMapper getIdentityObjectTypeMapper()
+ {
+ return identityObjectTypeMapper;
+ }
+
+ public IdentityStoreInvocationContext resolveStoreInvocationContext()
+ {
+ return contextResolver.resolveInvocationContext();
+ }
+}
Added: trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentitySessionFactoryImpl.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentitySessionFactoryImpl.java (rev 0)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentitySessionFactoryImpl.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -0,0 +1,63 @@
+/*
+* 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.IdentitySessionFactory;
+import org.jboss.identity.api.IdentitySession;
+
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class IdentitySessionFactoryImpl implements IdentitySessionFactory
+{
+
+ private Map<String, IdentitySession> realmMap;
+
+ public IdentitySessionFactoryImpl(Map<String, IdentitySession> realmMap)
+ {
+ this.realmMap = realmMap;
+ }
+
+ public void close()
+ {
+
+ }
+
+ public boolean isClosed()
+ {
+ return false;
+ }
+
+ public IdentitySession createIdentitySession(String realmName)
+ {
+ return realmMap.get(realmName);
+ }
+
+ public IdentitySession getCurrentIdentitySession(String realmName)
+ {
+ return realmMap.get(realmName);
+ }
+}
Added: trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentitySessionImpl.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentitySessionImpl.java (rev 0)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentitySessionImpl.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -0,0 +1,148 @@
+/*
+* 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.Transaction;
+import org.jboss.identity.api.PersistenceManager;
+import org.jboss.identity.api.RelationshipManager;
+import org.jboss.identity.api.ProfileManager;
+import org.jboss.identity.api.RoleManager;
+import org.jboss.identity.exception.IdentityException;
+
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class IdentitySessionImpl implements IdentitySession
+{
+ private final String realmName;
+
+ private final IdentitySessionContext sessionContext;
+
+ private final PersistenceManager persistenceManager;
+
+ private final RelationshipManager relationshipManager;
+
+ private final ProfileManager profileManager;
+
+ private final RoleManager roleManager;
+
+ private final Set<SessionWrapper> sessionWrappers;
+
+ public IdentitySessionContext getSessionContext()
+ {
+ return sessionContext;
+ }
+
+ public IdentitySessionImpl(String realmName, IdentitySessionContext sessionContext,
+ Set<SessionWrapper> sessionWrappers)
+ {
+ this.realmName = realmName;
+ this.sessionContext = sessionContext;
+ this.sessionWrappers = sessionWrappers;
+ this.persistenceManager = new PersistenceManagerImpl(this);
+ this.relationshipManager = new RelationshipManagerImpl(this);
+ this.profileManager = new ProfileManagerImpl(this);
+ this.roleManager = new RoleManagerImpl(this);
+
+
+ }
+
+ public String getRealmName()
+ {
+ return realmName;
+ }
+
+ public void close() throws IdentityException
+ {
+ for (SessionWrapper sessionWrapper : sessionWrappers)
+ {
+ sessionWrapper.close();
+ }
+ }
+
+ public void save() throws IdentityException
+ {
+ for (SessionWrapper sessionWrapper : sessionWrappers)
+ {
+ sessionWrapper.save();
+ }
+ }
+
+ public void clear() throws IdentityException
+ {
+ for (SessionWrapper sessionWrapper : sessionWrappers)
+ {
+ sessionWrapper.clear();
+ }
+ }
+
+ public boolean isOpen()
+ {
+
+ for (SessionWrapper sessionWrapper : sessionWrappers)
+ {
+ if (sessionWrapper.isOpen())
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public Transaction beginTransaction()
+ {
+ return new SimpleTransactionImpl(sessionWrappers);
+ }
+
+ public Transaction getTransaction()
+ {
+ return new SimpleTransactionImpl(sessionWrappers);
+ }
+
+ public PersistenceManager getPersistenceManager()
+ {
+ return persistenceManager;
+ }
+
+ public RelationshipManager getRelationshipManager()
+ {
+ return relationshipManager;
+ }
+
+ public ProfileManager getProfileManager()
+ {
+ return profileManager;
+ }
+
+ //TODO: proper exception if roles are not supported
+
+ public RoleManager getRoleManager()
+ {
+ return roleManager;
+ }
+}
Added: trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentityStoreInvocationContextResolver.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentityStoreInvocationContextResolver.java (rev 0)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/IdentityStoreInvocationContextResolver.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -0,0 +1,36 @@
+/*
+* 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.spi.store.IdentityStoreInvocationContext;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public interface IdentityStoreInvocationContextResolver
+{
+
+ IdentityStoreInvocationContext resolveInvocationContext();
+
+}
Added: trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/PersistenceManagerImpl.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/PersistenceManagerImpl.java (rev 0)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/PersistenceManagerImpl.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -0,0 +1,182 @@
+/*
+* 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.PersistenceManager;
+import org.jboss.identity.api.Identity;
+import org.jboss.identity.api.Group;
+import org.jboss.identity.api.GroupType;
+import org.jboss.identity.api.IdentityType;
+import org.jboss.identity.api.IdentitySession;
+import org.jboss.identity.exception.IdentityException;
+import org.jboss.identity.spi.model.IdentityObjectType;
+import org.jboss.identity.spi.model.IdentityObject;
+import org.jboss.identity.impl.types.SimpleIdentityObject;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.List;
+import java.util.LinkedList;
+import java.util.Iterator;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class PersistenceManagerImpl extends AbstractManager implements PersistenceManager
+{
+
+ public PersistenceManagerImpl(IdentitySession session)
+ {
+ super(session);
+ }
+
+ public Identity createIdentity(String identityName) throws IdentityException
+ {
+ IdentityObjectType iot = getIdentityObjectType();
+
+ IdentityObject identityObject = getRepository().createIdentityObject(getInvocationContext(), identityName, iot);
+
+ return createIdentity(identityObject);
+ }
+
+ public Group createGroup(String groupName, GroupType groupType) throws IdentityException
+ {
+ IdentityObjectType iot = getIdentityObjectType(groupType);
+
+ IdentityObject identityObject = getRepository().createIdentityObject(getInvocationContext(), groupName, iot);
+
+ return createGroup(identityObject);
+ }
+
+ public void removeIdentity(Identity identity, boolean force) throws IdentityException
+ {
+ IdentityObjectType iot = getIdentityObjectType();
+
+ getRepository().removeIdentityObject(getInvocationContext(), createIdentityObject(identity));
+
+ }
+
+ public void removeGroup(Group group, boolean force) throws IdentityException
+ {
+ //TODO: force
+
+ getRepository().removeIdentityObject(getInvocationContext(), createIdentityObject(group));
+ }
+
+ public void refreshIdentityType(IdentityType it) throws IdentityException
+ {
+ //TODO: remove this method from the interface
+ }
+
+ public int getIdentityCount() throws IdentityException
+ {
+ IdentityObjectType iot = getIdentityObjectType();
+
+ return getRepository().getIdentityObjectsCount(getInvocationContext(), iot);
+ }
+
+ public int getGroupTypeCount(GroupType groupType) throws IdentityException
+ {
+ IdentityObjectType iot = getIdentityObjectType(groupType);
+
+ return getRepository().getIdentityObjectsCount(getInvocationContext(), iot);
+ }
+
+ public Identity findIdentity(String name) throws IdentityException
+ {
+ return createIdentity(getRepository().findIdentityObject(getInvocationContext(), name, getIdentityObjectType()));
+ }
+
+ public Identity findIdentity(Object id) throws IdentityException
+ {
+ return createIdentity(getRepository().findIdentityObject(getInvocationContext(), id));
+ }
+
+ public Collection<Identity> findIdentity(String filterName, int offset, int limit, boolean orderedByName, boolean ascending) throws IdentityException
+ {
+ Collection<IdentityObject> ios = getRepository().findIdentityObject(getInvocationContext(), getIdentityObjectType(), filterName, offset, limit, orderedByName, ascending);
+ List<Identity> identities = new LinkedList<Identity>();
+
+ for (Iterator<IdentityObject> iterator = ios.iterator(); iterator.hasNext();)
+ {
+ IdentityObject identityObject = iterator.next();
+ identities.add(createIdentity(identityObject));
+ }
+
+ return identities;
+
+ }
+
+ public Collection<Identity> findIdentity(String filterName, Map<String, String[]> attributes, int offset, int limit, boolean orderedByName, boolean ascending) throws IdentityException
+ {
+ Collection<IdentityObject> ios = getRepository().findIdentityObject(getInvocationContext(), getIdentityObjectType(), attributes, offset, limit, orderedByName, ascending);
+ List<Identity> identities = new LinkedList<Identity>();
+
+ for (Iterator<IdentityObject> iterator = ios.iterator(); iterator.hasNext();)
+ {
+ IdentityObject identityObject = iterator.next();
+ identities.add(createIdentity(identityObject));
+ }
+
+ return identities;
+ }
+
+ public Group findGroup(String name, GroupType groupType) throws IdentityException
+ {
+ return createGroup(getRepository().findIdentityObject(getInvocationContext(), name, getIdentityObjectType(groupType)));
+ }
+
+ public Group findGroup(Object id) throws IdentityException
+ {
+ return createGroup(getRepository().findIdentityObject(getInvocationContext(), id));
+ }
+
+ public Collection<Group> findGroup(GroupType groupType, String filterName, int offset, int limit, boolean orderedByName, boolean ascending) throws IdentityException
+ {
+ Collection<IdentityObject> ios = getRepository().findIdentityObject(getInvocationContext(), getIdentityObjectType(groupType), filterName, offset, limit, orderedByName, ascending);
+ List<Group> groups = new LinkedList<Group>();
+
+ for (Iterator<IdentityObject> iterator = ios.iterator(); iterator.hasNext();)
+ {
+ IdentityObject identityObject = iterator.next();
+ groups.add(createGroup(identityObject));
+ }
+
+ return groups;
+ }
+
+ public Collection<Group> findGroup(GroupType groupType, Map<String, String[]> attributes, int offset, int limit, boolean orderedByName, boolean ascending) throws IdentityException
+ {
+ Collection<IdentityObject> ios = getRepository().findIdentityObject(getInvocationContext(), getIdentityObjectType(groupType), attributes, offset, limit, orderedByName, ascending);
+ List<Group> groups = new LinkedList<Group>();
+
+ for (Iterator<IdentityObject> iterator = ios.iterator(); iterator.hasNext();)
+ {
+ IdentityObject identityObject = iterator.next();
+ groups.add(createGroup(identityObject));
+ }
+
+ return groups;
+ }
+}
Added: trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/ProfileManagerImpl.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/ProfileManagerImpl.java (rev 0)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/ProfileManagerImpl.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -0,0 +1,111 @@
+/*
+* 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.ProfileManager;
+import org.jboss.identity.api.IdentityType;
+import org.jboss.identity.exception.IdentityException;
+
+import java.util.Set;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.HashSet;
+import java.util.Collections;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class ProfileManagerImpl extends AbstractManager implements ProfileManager
+{
+ public ProfileManagerImpl(IdentitySession session)
+ {
+ super(session);
+ }
+
+ //TODO: fix to have similar signatures in API/SPI for String[]
+
+ public Set<String> getSupportedAttributeNames(IdentityType identityType) throws IdentityException
+ {
+ return getRepository().getSupportedAttributeNames(getInvocationContext(), createIdentityObject(identityType).getIdentityType());
+ }
+
+ public Map<String, String[]> getAttributes(IdentityType identity) throws IdentityException
+ {
+ Map<String, Set<String>> attributes = getRepository().getAttributes(getInvocationContext(), createIdentityObject(identity));
+
+ Map<String, String[]> attrs = new HashMap<String, String[]>();
+
+ for (Map.Entry<String, Set<String>> entry : attributes.entrySet())
+ {
+ attrs.put(entry.getKey(), entry.getValue().toArray(new String[entry.getValue().size()]));
+ }
+
+ return attrs;
+ }
+
+ public void updateAttributes(IdentityType identity, Map<String, String[]> attributes) throws IdentityException
+ {
+ Map<String, Set<String>> attrs = new HashMap<String, Set<String>>();
+
+ for (Map.Entry<String, String[]> entry : attributes.entrySet())
+ {
+ Set<String> vals = new HashSet<String>();
+ for (String s : entry.getValue())
+ {
+ vals.add(s);
+ }
+
+ attrs.put(entry.getKey(),vals);
+ }
+
+ getRepository().updateAttributes(getInvocationContext(), createIdentityObject(identity), attrs);
+
+ }
+
+ public void addAttributes(IdentityType identity, Map<String, String[]> attributes) throws IdentityException
+ {
+ Map<String, Set<String>> attrs = new HashMap<String, Set<String>>();
+
+ for (Map.Entry<String, String[]> entry : attributes.entrySet())
+ {
+ Set<String> vals = new HashSet<String>();
+ for (String s : entry.getValue())
+ {
+ vals.add(s);
+ }
+
+ attrs.put(entry.getKey(),vals);
+ }
+
+ getRepository().addAttributes(getInvocationContext(), createIdentityObject(identity), attrs);
+ }
+
+ public void removeAttributes(IdentityType identity, Set<String> attributes) throws IdentityException
+ {
+ getRepository().removeAttributes(getInvocationContext(), createIdentityObject(identity), attributes);
+
+ }
+}
Added: trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/RelationshipManagerImpl.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/RelationshipManagerImpl.java (rev 0)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/RelationshipManagerImpl.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -0,0 +1,179 @@
+/*
+* 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.RelationshipManager;
+import org.jboss.identity.api.IdentitySession;
+import org.jboss.identity.api.Group;
+import org.jboss.identity.api.Identity;
+import org.jboss.identity.api.IdentityType;
+import org.jboss.identity.api.GroupType;
+import org.jboss.identity.exception.IdentityException;
+import org.jboss.identity.spi.model.IdentityObjectRelationshipType;
+import org.jboss.identity.spi.model.IdentityObjectRelationship;
+import org.jboss.identity.impl.NotYetImplementedException;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class RelationshipManagerImpl extends AbstractManager implements RelationshipManager
+{
+
+ public static final IdentityObjectRelationshipType MEMBER = new IdentityObjectRelationshipType()
+ {
+ public String getName()
+ {
+ return "JBOSS_IDENTITY_MEMBERSHIP";
+ }
+ };
+
+ public RelationshipManagerImpl(IdentitySession session)
+ {
+ super(session);
+ }
+
+ public void associateGroups(Collection<Group> parents, Collection<Group> members) throws IdentityException
+ {
+ for (Iterator<Group> parentsIterator = parents.iterator(); parentsIterator.hasNext();)
+ {
+ Group parent = parentsIterator.next();
+
+ for (Iterator<Group> membersIterator = members.iterator(); membersIterator.hasNext();)
+ {
+ Group member = membersIterator.next();
+
+ associateGroups(parent, member);
+ }
+ }
+ }
+
+ public void associateGroups(Group parent, Group member) throws IdentityException
+ {
+ getRepository().createRelationship(getInvocationContext(), createIdentityObject(parent), createIdentityObject(member), MEMBER, null, true);
+ }
+
+ public void associateIdentities(Collection<Group> parents, Collection<Identity> members) throws IdentityException
+ {
+ for (Iterator<Group> parentsIterator = parents.iterator(); parentsIterator.hasNext();)
+ {
+ Group parent = parentsIterator.next();
+
+ for (Iterator<Identity> membersIterator = members.iterator(); membersIterator.hasNext();)
+ {
+ Identity member = membersIterator.next();
+
+ associateIdentities(parent, member);
+ }
+ }
+ }
+
+ public void associateIdentities(Group parent, Identity member) throws IdentityException
+ {
+ getRepository().createRelationship(getInvocationContext(), createIdentityObject(parent), createIdentityObject(member), MEMBER, null, true);
+ }
+
+ public void disassociateGroups(Collection<Group> parents, Collection<Group> members) throws IdentityException
+ {
+ for (Iterator<Group> parentsIterator = parents.iterator(); parentsIterator.hasNext();)
+ {
+ Group parent = parentsIterator.next();
+
+ for (Iterator<Group> membersIterator = members.iterator(); membersIterator.hasNext();)
+ {
+ Group member = membersIterator.next();
+
+ getRepository().removeRelationship(getInvocationContext(), createIdentityObject(parent), createIdentityObject(member), MEMBER, null);
+ }
+ }
+ }
+
+ public void disassociateIdentities(Collection<Group> parents, Collection<Identity> members) throws IdentityException
+ {
+ for (Iterator<Group> parentsIterator = parents.iterator(); parentsIterator.hasNext();)
+ {
+ Group parent = parentsIterator.next();
+
+ for (Iterator<Identity> membersIterator = members.iterator(); membersIterator.hasNext();)
+ {
+ Identity member = membersIterator.next();
+
+ getRepository().removeRelationship(getInvocationContext(), createIdentityObject(parent), createIdentityObject(member), MEMBER, null);
+ }
+ }
+
+ }
+
+ public <G extends IdentityType, I extends IdentityType> boolean isAssociated(Collection<G> parents, Collection<I> members) throws IdentityException
+ {
+ //TODO: IdentityStore should have isRelationshipPresent method to improve this
+
+ for (Iterator<G> parentsIterator = parents.iterator(); parentsIterator.hasNext();)
+ {
+ IdentityType parent = parentsIterator.next();
+
+ for (Iterator<I> membersIterator = members.iterator(); membersIterator.hasNext();)
+ {
+ IdentityType member = membersIterator.next();
+
+ Collection<IdentityObjectRelationship> relationships = getRepository().resolveRelationships(getInvocationContext(), createIdentityObject(parent), createIdentityObject(member));
+
+ boolean isRelated = false;
+
+ for (Iterator<IdentityObjectRelationship> identityObjectRelationshipIterator = relationships.iterator(); identityObjectRelationshipIterator.hasNext();)
+ {
+ IdentityObjectRelationship rel = identityObjectRelationshipIterator.next();
+ if (rel.getType().getName().equals(MEMBER.getName()))
+ {
+ isRelated = true;
+ }
+ }
+
+ if (!isRelated)
+ {
+ return false;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ public Collection<Group> findAssociatedGroups(Group group, GroupType groupType, boolean parent, boolean inherited, int offset, int limit, String orderedByAttributeName, boolean ascending) throws IdentityException
+ {
+ throw new NotYetImplementedException();
+ }
+
+ public Collection<Group> findAssociatedGroups(Identity identity, GroupType groupType, int offset, int limit, String orderedByAttributeName, boolean ascending) throws IdentityException
+ {
+ throw new NotYetImplementedException();
+ }
+
+ public Collection<Identity> findAssociatedIdentities(Group group, boolean inherited, int offset, int limit, String orderedByAttributeName, boolean ascending) throws IdentityException
+ {
+ throw new NotYetImplementedException();
+ }
+}
Added: trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/RoleHandler.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/RoleHandler.java (rev 0)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/RoleHandler.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -0,0 +1,50 @@
+/*
+* 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.spi.model.IdentityObjectRelationship;
+import org.jboss.identity.spi.model.IdentityObjectRelationshipType;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class RoleHandler
+{
+
+ boolean isNamedRole(IdentityObjectRelationshipType rt)
+ {
+ return false;
+ }
+
+ IdentityObjectRelationshipType createRelationshipType(String roleName)
+ {
+ return null;
+ }
+
+ String resolveRoleName(IdentityObjectRelationshipType rt)
+ {
+ return null;
+ }
+
+}
Added: trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/RoleManagerImpl.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/RoleManagerImpl.java (rev 0)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/RoleManagerImpl.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -0,0 +1,246 @@
+/*
+* 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.RoleManager;
+import org.jboss.identity.api.IdentitySession;
+import org.jboss.identity.api.RoleType;
+import org.jboss.identity.api.Role;
+import org.jboss.identity.api.Identity;
+import org.jboss.identity.api.Group;
+import org.jboss.identity.api.IdentityType;
+import org.jboss.identity.exception.IdentityException;
+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.impl.NotYetImplementedException;
+
+import java.util.Collection;
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class RoleManagerImpl extends AbstractManager implements RoleManager
+{
+ public static final IdentityObjectRelationshipType ROLE = new IdentityObjectRelationshipType()
+ {
+ public String getName()
+ {
+ return "JBOSS_IDENTITY_ROLE";
+ }
+ };
+
+ public RoleManagerImpl(IdentitySession session)
+ {
+ super(session);
+ }
+
+ public RoleType createRoleType(String name) throws IdentityException
+ {
+ String roleType = null;
+
+ try
+ {
+ roleType = getRepository().createRelationshipName(getInvocationContext(), name);
+ }
+ catch (OperationNotSupportedException e)
+ {
+ throw new IdentityException("Role management not supported");
+ }
+
+ return new SimpleRoleType(roleType);
+ }
+
+ public void removeRoleType(String name) throws IdentityException
+ {
+ try
+ {
+ getRepository().removeRelationshipName(getInvocationContext(), name);
+ }
+ catch (OperationNotSupportedException e)
+ {
+ throw new IdentityException("Role management not supported");
+ }
+ }
+
+ public void removeRoleType(RoleType roleType) throws IdentityException
+ {
+ removeRoleType(roleType.getName());
+ }
+
+ public RoleType getRoleType(String name) throws IdentityException
+ {
+ try
+ {
+ Set<String> names = getRepository().getRelationshipNames(getInvocationContext(), 0, 0, false, false);
+ if (names.contains(name))
+ {
+ return new SimpleRoleType(name);
+ }
+ }
+ catch (OperationNotSupportedException e)
+ {
+ throw new IdentityException("Role management not supported");
+ }
+
+ return null;
+ }
+
+ public Collection<RoleType> findRoleTypes(int offset, int limit, boolean orderedByName, boolean ascending) throws IdentityException
+ {
+
+ try
+ {
+ Set<String> names = getRepository().getRelationshipNames(getInvocationContext(), offset, limit, orderedByName, ascending);
+ Set<RoleType> types = new HashSet<RoleType>();
+
+ for (String name : names)
+ {
+ types.add(new SimpleRoleType(name));
+ }
+
+ return types;
+ }
+ catch (OperationNotSupportedException e)
+ {
+ throw new IdentityException("Role management not supported");
+ }
+
+ }
+
+ public Role createRole(RoleType roleType, Identity identity, Group group) throws IdentityException
+ {
+ //TODO: add createRoleType switch to the API
+
+ IdentityObjectRelationship rel = getRepository().createRelationship(getInvocationContext(), createIdentityObject(identity), createIdentityObject(group), ROLE, roleType.getName(), false);
+
+ //TODO: null id - IdentityObjectRelationship doesn't have id
+ return new SimpleRoleImpl(null, new SimpleRoleType(rel.getName()), createIdentity(rel.getFromIdentityObject()), createGroup(rel.getToIdentityObject()));
+
+ }
+
+ public void removeRole(RoleType roleType, Identity identity, Group group) throws IdentityException
+ {
+ getRepository().removeRelationship(getInvocationContext(), createIdentityObject(identity), createIdentityObject(group), ROLE, roleType.getName());
+ }
+
+ public void removeRole(Role role) throws IdentityException
+ {
+ getRepository().removeRelationship(getInvocationContext(), createIdentityObject(role.getIdentity()), createIdentityObject(role.getGroup()), ROLE, role.getRoleType().getName());
+ }
+
+ public boolean hasRole(Identity identity, Group group, RoleType roleType) throws IdentityException
+ {
+ //TODO: add hasRelationship to IdentityStore
+
+ Set<IdentityObjectRelationship> rels = getRepository().resolveRelationships(getInvocationContext(), createIdentityObject(identity), createIdentityObject(group));
+
+ for (IdentityObjectRelationship rel : rels)
+ {
+ if (rel.getType().getName().equals(ROLE.getName()) && rel.getName() != null && rel.getName().equals(roleType.getName()))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public Collection<RoleType> findRoleTypes(Identity identity, Group group, int offset, int limit, boolean orderedByName, boolean ascending) throws IdentityException
+ {
+ //TODO: improve IdentityStore SPI....
+
+
+ Set<IdentityObjectRelationship> rels = getRepository().resolveRelationships(getInvocationContext(), createIdentityObject(identity), createIdentityObject(group));
+ Set<RoleType> types = new HashSet<RoleType>();
+
+ for (IdentityObjectRelationship rel : rels)
+ {
+ if (rel.getType().getName().equals(ROLE.getName()))
+ {
+ types.add(new SimpleRoleType(rel.getName()));
+ }
+ }
+
+ return types;
+
+
+ }
+
+ public Collection<RoleType> findIdentityRoleTypes(Identity identity, int offset, int limit, boolean orderedByName, boolean ascending) throws IdentityException
+ {
+ Set<RoleType> types = new HashSet<RoleType>();
+
+ try
+ {
+ Collection<String> names = getRepository().getRelationshipNames(getInvocationContext(), createIdentityObject(identity), offset, limit, orderedByName, ascending);
+
+ for (String name : names)
+ {
+ types.add(new SimpleRoleType(name));
+ }
+
+ return types;
+
+ }
+ catch (OperationNotSupportedException e)
+ {
+ throw new IdentityException("Role management not supported");
+ }
+
+
+
+
+ }
+
+ public Collection<RoleType> findGroupRoleTypes(Group group, int offset, int limit, boolean orderedByName, boolean ascending) throws IdentityException
+ {
+ Set<RoleType> types = new HashSet<RoleType>();
+
+ try
+ {
+ Collection<String> names = getRepository().getRelationshipNames(getInvocationContext(), createIdentityObject(group), offset, limit, orderedByName, ascending);
+
+ for (String name : names)
+ {
+ types.add(new SimpleRoleType(name));
+ }
+
+ return types;
+
+ }
+ catch (OperationNotSupportedException e)
+ {
+ throw new IdentityException("Role management not supported");
+ }
+
+ }
+
+ public <T extends IdentityType> Collection<Role> findRoles(T identityType, RoleType roleType, int offset, int limit, boolean orderedByName, boolean ascending) throws IdentityException
+ {
+ throw new NotYetImplementedException();
+ }
+}
Added: trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SessionWrapper.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SessionWrapper.java (rev 0)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SessionWrapper.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -0,0 +1,83 @@
+/*
+* 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.exception.IdentityException;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public interface SessionWrapper
+{
+
+ /**
+ * Close this session
+ * @throws org.jboss.identity.exception.IdentityException
+ */
+ void close() throws IdentityException;
+
+ /**
+ * Save all pending changes
+ * @throws org.jboss.identity.exception.IdentityException
+ */
+ void save() throws IdentityException;
+
+ /**
+ * Clear this session
+ * @throws org.jboss.identity.exception.IdentityException
+ */
+ void clear() throws IdentityException;
+
+ /**
+ * Check if this session is open
+ * @return
+ */
+ boolean isOpen();
+
+
+ boolean isTransactionSupported();
+
+ /**
+ * Begin new transaction
+ */
+ void startTransaction();
+
+ /**
+ * Commit transaction - flush associated session
+ */
+ void commitTransaction();
+
+ /**
+ * Rollback transaction
+ */
+ void rollbackTransaction();
+
+ /**
+ *
+ * @return
+ */
+ boolean isTransactionActive();
+
+
+}
Added: trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleGroupImpl.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleGroupImpl.java (rev 0)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleGroupImpl.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -0,0 +1,67 @@
+/*
+* 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.Group;
+import org.jboss.identity.api.GroupType;
+import org.jboss.identity.spi.model.IdentityObject;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class SimpleGroupImpl implements Group
+{
+ private final String name;
+
+ private final Object id;
+
+ private final GroupType groupType;
+
+ public SimpleGroupImpl(String name, Object id, GroupType groupType)
+ {
+ this.name = name;
+ this.id = id;
+ this.groupType = groupType;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public GroupType getGroupType()
+ {
+ return groupType;
+ }
+
+ public Object getId()
+ {
+ return id;
+ }
+
+ public String getDescription()
+ {
+ return null;
+ }
+}
Added: trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleGroupType.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleGroupType.java (rev 0)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleGroupType.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -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.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 final String name;
+
+ public SimpleGroupType(String name)
+ {
+ this.name = name;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+
+}
Added: trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleIdentityImpl.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleIdentityImpl.java (rev 0)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleIdentityImpl.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -0,0 +1,63 @@
+/*
+* 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.Identity;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class SimpleIdentityImpl implements Identity
+{
+ private final String name;
+
+ private final Object id;
+
+
+ public SimpleIdentityImpl(String name, Object id)
+ {
+ this.name = name;
+ this.id = id;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public boolean isVirtual()
+ {
+ return false;
+ }
+
+ public Object getId()
+ {
+ return id;
+ }
+
+ public String getDescription()
+ {
+ return null;
+ }
+}
Added: trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleRoleImpl.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleRoleImpl.java (rev 0)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleRoleImpl.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -0,0 +1,76 @@
+/*
+* 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.Role;
+import org.jboss.identity.api.RoleType;
+import org.jboss.identity.api.Identity;
+import org.jboss.identity.api.Group;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class SimpleRoleImpl implements Role
+{
+ private final Object id;
+
+ private final RoleType type;
+
+ private final Identity identity;
+
+ private final Group group;
+
+ public SimpleRoleImpl(Object id, RoleType type, Identity identity, Group group)
+ {
+ this.id = id;
+ this.type = type;
+ this.identity = identity;
+ this.group = group;
+ }
+
+ public Object getId()
+ {
+ return id;
+ }
+
+ public Identity getIdentity()
+ {
+ return identity;
+ }
+
+ public Group getGroup()
+ {
+ return group;
+ }
+
+ public String getDescription()
+ {
+ return null;
+ }
+
+ public RoleType getRoleType()
+ {
+ return type;
+ }
+}
Added: trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleRoleType.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleRoleType.java (rev 0)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleRoleType.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -0,0 +1,74 @@
+/*
+* 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.RoleType;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class SimpleRoleType implements RoleType
+{
+ private final String name;
+
+ public SimpleRoleType(String name)
+ {
+ if (name == null)
+ {
+ throw new IllegalArgumentException("name cannot be null");
+ }
+ this.name = name;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public boolean equals(Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
+
+ SimpleRoleType that = (SimpleRoleType)o;
+
+ if (name != null ? !name.equals(that.name) : that.name != null)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ public int hashCode()
+ {
+ return (name != null ? name.hashCode() : 0);
+ }
+}
Added: trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleTransactionImpl.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleTransactionImpl.java (rev 0)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleTransactionImpl.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -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.api;
+
+import org.jboss.identity.api.Transaction;
+
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class SimpleTransactionImpl implements Transaction
+{
+ private final Set<SessionWrapper> sessionWrappers;
+
+ public SimpleTransactionImpl(Set<SessionWrapper> sessionWrappers)
+ {
+ this.sessionWrappers = sessionWrappers;
+ }
+
+ public void start()
+ {
+ for (SessionWrapper sessionWrapper : sessionWrappers)
+ {
+ sessionWrapper.startTransaction();
+ }
+ }
+
+ public void commit()
+ {
+ for (SessionWrapper sessionWrapper : sessionWrappers)
+ {
+ sessionWrapper.commitTransaction();
+ }
+ }
+
+ public void rollback()
+ {
+ for (SessionWrapper sessionWrapper : sessionWrappers)
+ {
+ sessionWrapper.rollbackTransaction();
+ }
+ }
+
+ public boolean isActive()
+ {
+
+ for (SessionWrapper sessionWrapper : sessionWrappers)
+ {
+ if (sessionWrapper.isTransactionActive())
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+}
Modified: 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 2008-10-15 10:59:42 UTC (rev 103)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/hibernate/HibernateIdentityObjectRelationshipName.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -28,6 +28,7 @@
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
/**
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
@@ -52,6 +53,7 @@
public class HibernateIdentityObjectRelationshipName
{
@Id
+ @GeneratedValue
Long id;
@Column(nullable = false, unique = true, name = "NAME")
Added: trunk/identity-impl/src/main/java/org/jboss/identity/impl/repository/AbstractIdentityStoreRepository.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/repository/AbstractIdentityStoreRepository.java (rev 0)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/repository/AbstractIdentityStoreRepository.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -0,0 +1,97 @@
+/*
+* 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.repository;
+
+import org.jboss.identity.spi.repository.IdentityStoreRepository;
+import org.jboss.identity.spi.store.IdentityStore;
+import org.jboss.identity.spi.store.AttributeStore;
+import org.jboss.identity.spi.model.IdentityObjectType;
+
+import java.util.Set;
+import java.util.Map;
+import java.util.HashSet;
+import java.util.Collections;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public abstract class AbstractIdentityStoreRepository implements IdentityStoreRepository
+{
+
+ private final Map<String, IdentityStore> identityStoreMappings;
+
+ private final Map<String, AttributeStore> attributeStoreMappings;
+
+ public AbstractIdentityStoreRepository(Map<String, IdentityStore> identityStoreMappings, Map<String, AttributeStore> attributeStoreMappings)
+ {
+ if (identityStoreMappings != null)
+ {
+ this.identityStoreMappings = Collections.unmodifiableMap(identityStoreMappings);
+ }
+ else
+ {
+ this.identityStoreMappings = null;
+ }
+
+ if (attributeStoreMappings != null)
+ {
+ this.attributeStoreMappings = Collections.unmodifiableMap(attributeStoreMappings);
+ }
+ else
+ {
+ this.attributeStoreMappings = null;
+ }
+
+ }
+
+ public Set<IdentityStore> getConfiguredIdentityStores()
+ {
+ return new HashSet<IdentityStore>(identityStoreMappings.values());
+ }
+
+ public Set<AttributeStore> getConfiguredAttributeStores()
+ {
+ return new HashSet<AttributeStore>(attributeStoreMappings.values());
+ }
+
+ public Map<String, IdentityStore> getIdentityStoreMappings()
+ {
+ return identityStoreMappings;
+ }
+
+ public Map<String, AttributeStore> getAttributeStoreMappings()
+ {
+ return attributeStoreMappings;
+ }
+
+ public IdentityStore getIdentityStore(IdentityObjectType identityObjectType)
+ {
+ return identityStoreMappings.get(identityObjectType.getName());
+ }
+
+ public AttributeStore getAttributeStore(IdentityObjectType identityObjectType)
+ {
+ return attributeStoreMappings.get(identityObjectType.getName());
+ }
+}
Added: trunk/identity-impl/src/main/java/org/jboss/identity/impl/repository/WrapperIdentityStoreRepository.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/repository/WrapperIdentityStoreRepository.java (rev 0)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/repository/WrapperIdentityStoreRepository.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -0,0 +1,198 @@
+/*
+* 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.repository;
+
+import org.jboss.identity.spi.repository.IdentityStoreRepository;
+import org.jboss.identity.spi.store.IdentityStore;
+import org.jboss.identity.spi.store.AttributeStore;
+import org.jboss.identity.spi.store.FeaturesDescription;
+import org.jboss.identity.spi.store.IdentityStoreInvocationContext;
+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 java.util.Map;
+import java.util.Collection;
+import java.util.Set;
+import java.io.IOException;
+
+/**
+ * Simply wraps IdentityStore and AttributeStore and delegates all the calls
+ *
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class WrapperIdentityStoreRepository extends AbstractIdentityStoreRepository
+{
+
+ private final IdentityStore identityStore;
+
+ private final AttributeStore attributeStore;
+
+ public WrapperIdentityStoreRepository(IdentityStore identityStore, AttributeStore attributeStore,
+ Map<String, IdentityStore> identityStoreMappings, Map<String, AttributeStore> attributeStoreMappings)
+ {
+ super(identityStoreMappings, attributeStoreMappings);
+
+ this.identityStore = identityStore;
+ this.attributeStore = attributeStore;
+ }
+
+ public void bootstrap() throws IOException
+ {
+
+ }
+
+ public String getId()
+ {
+ return null;
+ }
+
+ public FeaturesDescription getSupportedFeatures()
+ {
+ return null;
+ }
+
+ public IdentityObject createIdentityObject(IdentityStoreInvocationContext invocationCtx, String name, IdentityObjectType identityObjectType) throws IdentityException
+ {
+ return identityStore.createIdentityObject(invocationCtx, name, identityObjectType);
+ }
+
+ public void removeIdentityObject(IdentityStoreInvocationContext invocationCtx, IdentityObject identity) throws IdentityException
+ {
+ identityStore.removeIdentityObject(invocationCtx, identity);
+ }
+
+ public int getIdentityObjectsCount(IdentityStoreInvocationContext invocationCtx, IdentityObjectType identityType) throws IdentityException
+ {
+ return identityStore.getIdentityObjectsCount(invocationCtx, identityType);
+ }
+
+ public IdentityObject findIdentityObject(IdentityStoreInvocationContext invocationContext, String name, IdentityObjectType identityObjectType) throws IdentityException
+ {
+ return identityStore.findIdentityObject(invocationContext, name, identityObjectType);
+ }
+
+ public IdentityObject findIdentityObject(IdentityStoreInvocationContext invocationContext, Object id) throws IdentityException
+ {
+ return identityStore.findIdentityObject(invocationContext, id);
+ }
+
+ public Collection<IdentityObject> findIdentityObject(IdentityStoreInvocationContext invocationCtx, IdentityObjectType identityType, String nameFilter, int offset, int limit, boolean orderByName, boolean ascending) throws IdentityException
+ {
+ return identityStore.findIdentityObject(invocationCtx, identityType, nameFilter, offset, limit, orderByName, ascending);
+ }
+
+ public Collection<IdentityObject> findIdentityObject(IdentityStoreInvocationContext invocationCtx, IdentityObjectType identityType, Map<String, String[]> attributes, int offset, int limit, boolean orderByName, boolean ascending) throws IdentityException
+ {
+ return identityStore.findIdentityObject(invocationCtx, identityType, attributes, offset, limit, orderByName, ascending);
+ }
+
+ public Collection<IdentityObject> findIdentityObject(IdentityStoreInvocationContext invocationCxt, IdentityObject identity, IdentityObjectRelationshipType relationshipType, boolean parent, int offset, int limit, boolean orderByName, boolean ascending) throws IdentityException
+ {
+ return identityStore.findIdentityObject(invocationCxt, identity, relationshipType, parent, offset, limit, orderByName, ascending);
+ }
+
+ public IdentityObjectRelationship createRelationship(IdentityStoreInvocationContext invocationCxt, IdentityObject fromIdentity, IdentityObject toIdentity, IdentityObjectRelationshipType relationshipType, String relationshipName, boolean createNames) throws IdentityException
+ {
+ return identityStore.createRelationship(invocationCxt, fromIdentity, toIdentity, relationshipType, relationshipName, createNames);
+ }
+
+ public void removeRelationship(IdentityStoreInvocationContext invocationCxt, IdentityObject fromIdentity, IdentityObject toIdentity, IdentityObjectRelationshipType relationshipType, String relationshipName) throws IdentityException
+ {
+ identityStore.removeRelationship(invocationCxt, fromIdentity, toIdentity, relationshipType, relationshipName);
+ }
+
+ public void removeRelationships(IdentityStoreInvocationContext invocationCtx, IdentityObject identity1, IdentityObject identity2, boolean named) throws IdentityException
+ {
+ identityStore.removeRelationships(invocationCtx, identity1, identity2, named);
+ }
+
+ public Set<IdentityObjectRelationship> resolveRelationships(IdentityStoreInvocationContext invocationCxt, IdentityObject fromIdentity, IdentityObject toIdentity) throws IdentityException
+ {
+ return identityStore.resolveRelationships(invocationCxt, fromIdentity, toIdentity);
+ }
+
+ public String createRelationshipName(IdentityStoreInvocationContext ctx, String name) throws IdentityException, OperationNotSupportedException
+ {
+ return identityStore.createRelationshipName(ctx, name);
+ }
+
+ public String removeRelationshipName(IdentityStoreInvocationContext ctx, String name) throws IdentityException, OperationNotSupportedException
+ {
+ return identityStore.removeRelationshipName(ctx, name);
+ }
+
+ public Set<String> getRelationshipNames(IdentityStoreInvocationContext ctx, int offset, int limit, boolean orderByName, boolean ascending) throws IdentityException, OperationNotSupportedException
+ {
+ return identityStore.getRelationshipNames(ctx, offset, limit, orderByName, ascending);
+ }
+
+ public Set<String> getRelationshipNames(IdentityStoreInvocationContext ctx, IdentityObject identity, int offset, int limit, boolean orderByName, boolean ascending) throws IdentityException, OperationNotSupportedException
+ {
+ return identityStore.getRelationshipNames(ctx, identity, offset, limit, orderByName, ascending);
+ }
+
+ public boolean hasPasswordAttribute(IdentityStoreInvocationContext ctx, IdentityObjectType type) throws IdentityException
+ {
+ return identityStore.hasPasswordAttribute(ctx, type);
+ }
+
+ public boolean validatePassword(IdentityStoreInvocationContext ctx, IdentityObject identityObject, String password) throws IdentityException
+ {
+ return identityStore.validatePassword(ctx, identityObject, password);
+ }
+
+ public void updatePassword(IdentityStoreInvocationContext ctx, IdentityObject identityObject, String password) throws IdentityException
+ {
+ identityStore.updatePassword(ctx, identityObject, password);
+ }
+
+ public <T extends IdentityObjectType> Set<String> getSupportedAttributeNames(IdentityStoreInvocationContext invocationContext, T identityType) throws IdentityException
+ {
+ return attributeStore.getSupportedAttributeNames(invocationContext, identityType);
+ }
+
+ public Map<String, Set<String>> getAttributes(IdentityStoreInvocationContext invocationContext, IdentityObject identity) throws IdentityException
+ {
+ return attributeStore.getAttributes(invocationContext, identity);
+ }
+
+ public void updateAttributes(IdentityStoreInvocationContext invocationCtx, IdentityObject identity, Map<String, Set<String>> attributes) throws IdentityException
+ {
+ attributeStore.updateAttributes(invocationCtx, identity, attributes);
+ }
+
+ public void addAttributes(IdentityStoreInvocationContext invocationCtx, IdentityObject identity, Map<String, Set<String>> attributes) throws IdentityException
+ {
+ attributeStore.addAttributes(invocationCtx, identity, attributes);
+ }
+
+ public void removeAttributes(IdentityStoreInvocationContext invocationCtx, IdentityObject identity, Set<String> attributes) throws IdentityException
+ {
+ attributeStore.removeAttributes(invocationCtx, identity, attributes);
+ }
+}
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-10-15 10:59:42 UTC (rev 103)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/hibernate/HibernateIdentityStoreImpl.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -74,6 +74,10 @@
"select r from HibernateIdentityObjectRelationship r where r.fromIdentityObject like :fromIO and " +
"r.toIdentityObject like :toIO and r.type.name like :typeName";
+ private final String QUERY_RELATIONSHIP_BY_FROM_TO_TYPE_NAME =
+ "select r from HibernateIdentityObjectRelationship r where r.fromIdentityObject like :fromIO and " +
+ "r.toIdentityObject like :toIO and r.type.name like :typeName and r.name.name like :name";
+
private final String QUERY_RELATIONSHIP_BY_IDENTITIES =
"select r from HibernateIdentityObjectRelationship r where " +
"(r.fromIdentityObject like :IO1 and r.toIdentityObject like :IO2) or " +
@@ -364,7 +368,7 @@
return results;
}
- public void createRelationship(IdentityStoreInvocationContext ctx, IdentityObject fromIdentity, IdentityObject toIdentity,
+ public IdentityObjectRelationship createRelationship(IdentityStoreInvocationContext ctx, IdentityObject fromIdentity, IdentityObject toIdentity,
IdentityObjectRelationshipType relationshipType,
String name, boolean createNames) throws IdentityException
{
@@ -382,10 +386,11 @@
getSupportedFeatures().isRelationshipTypeSupported(fromIO.getIdentityType(), toIO.getIdentityType(), relationshipType);
- org.hibernate.Query query = getHibernateEntityManager(ctx).getSession().createQuery(QUERY_RELATIONSHIP_BY_FROM_TO_TYPE)
+ org.hibernate.Query query = getHibernateEntityManager(ctx).getSession().createQuery(QUERY_RELATIONSHIP_BY_FROM_TO_TYPE_NAME)
.setParameter("fromIO", fromIO)
.setParameter("toIO", toIO)
- .setParameter("typeName", type.getName());
+ .setParameter("typeName", type.getName())
+ .setParameter("name", name);
List results = query.list();
@@ -394,8 +399,23 @@
throw new IdentityException("Relationship already present");
}
- HibernateIdentityObjectRelationship relationship = new HibernateIdentityObjectRelationship(type, fromIO, toIO);
+ HibernateIdentityObjectRelationship relationship = null;
+
+ if (name != null)
+ {
+
+ HibernateIdentityObjectRelationshipName relationshipName = (HibernateIdentityObjectRelationshipName)getHibernateEntityManager(ctx).getSession().createCriteria(HibernateIdentityObjectRelationshipName.class).add(Restrictions.eq("name", name)).uniqueResult();
+
+ relationship = new HibernateIdentityObjectRelationship(type, fromIO, toIO, relationshipName);
+ }
+ else
+ {
+ relationship = new HibernateIdentityObjectRelationship(type, fromIO, toIO);
+ }
+
getHibernateEntityManager(ctx).persist(relationship);
+
+ return relationship;
}
@@ -414,12 +434,25 @@
getSupportedFeatures().isRelationshipTypeSupported(fromIO.getIdentityType(), toIO.getIdentityType(), relationshipType);
+ org.hibernate.Query query = null;
- org.hibernate.Query query = getHibernateEntityManager(ctx).getSession().createQuery(QUERY_RELATIONSHIP_BY_FROM_TO_TYPE)
- .setParameter("fromIO", fromIO)
- .setParameter("toIO", toIO)
- .setParameter("typeName", type.getName());
+ if (name == null)
+ {
+ query = getHibernateEntityManager(ctx).getSession().createQuery(QUERY_RELATIONSHIP_BY_FROM_TO_TYPE)
+ .setParameter("fromIO", fromIO)
+ .setParameter("toIO", toIO)
+ .setParameter("typeName", type.getName());
+ }
+ else
+ {
+ query = getHibernateEntityManager(ctx).getSession().createQuery(QUERY_RELATIONSHIP_BY_FROM_TO_TYPE_NAME)
+ .setParameter("fromIO", fromIO)
+ .setParameter("toIO", toIO)
+ .setParameter("typeName", type.getName())
+ .setParameter("name", name);
+ }
+
List results = query.list();
if (results == null)
@@ -755,7 +788,7 @@
}
catch (NoResultException e)
{
- throw new IdentityException("IdentityObjectType[ " + type.getName() + "] not present in the store.");
+ throw new IdentityException("IdentityObjectType[" + type.getName() + "] not present in the store.");
}
return hibernateType;
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-10-15 10:59:42 UTC (rev 103)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/ldap/LDAPIdentityStore.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -673,7 +673,7 @@
return objects;
}
- public void createRelationship(IdentityStoreInvocationContext ctx, IdentityObject fromIdentity, IdentityObject toIdentity,
+ public IdentityObjectRelationship createRelationship(IdentityStoreInvocationContext ctx, IdentityObject fromIdentity, IdentityObject toIdentity,
IdentityObjectRelationshipType relationshipType,
String name, boolean createNames) throws IdentityException
{
@@ -689,6 +689,8 @@
);
}
+ LDAPIdentityObjectRelationshipImpl relationship = null;
+
LDAPIdentityObjectImpl ldapFromIO = getSafeLDAPIO(ctx, fromIdentity);
LDAPIdentityObjectImpl ldapToIO = getSafeLDAPIO(ctx, toIdentity);
@@ -725,6 +727,8 @@
ldapContext.modifyAttributes(ldapFromIO.getDn(), DirContext.REPLACE_ATTRIBUTE, attrs);
+ relationship = new LDAPIdentityObjectRelationshipImpl(name, ldapFromIO, ldapToIO);
+
}
catch (NamingException e)
{
@@ -741,6 +745,9 @@
throw new IdentityException("Failed to close LDAP connection", e);
}
}
+
+
+ return relationship;
}
public void removeRelationship(IdentityStoreInvocationContext ctx, IdentityObject fromIdentity, IdentityObject toIdentity, IdentityObjectRelationshipType relationshipType, String name) throws IdentityException
Modified: trunk/identity-impl/src/main/java/org/jboss/identity/impl/types/SimpleIdentityObject.java
===================================================================
--- trunk/identity-impl/src/main/java/org/jboss/identity/impl/types/SimpleIdentityObject.java 2008-10-15 10:59:42 UTC (rev 103)
+++ trunk/identity-impl/src/main/java/org/jboss/identity/impl/types/SimpleIdentityObject.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -35,8 +35,7 @@
/**
- * Very simple identity
- * @author Anil.Saldhana(a)redhat.com
+ * Very simple identity object
* @author boleslaw dot dawidowicz at redhat anotherdot com
*
* @since Aug 6, 2008
@@ -44,51 +43,40 @@
public class SimpleIdentityObject implements IdentityObject
{
- public IdentityObjectType getIdentityType()
+
+ private final String name;
+
+ private final Object id;
+
+ private final IdentityObjectType type;
+
+ public SimpleIdentityObject(String name, Object id, IdentityObjectType type)
{
- return null;
+ this.name = name;
+ this.id = id;
+ this.type = type;
}
- protected String name;
- protected List<IdentityObjectAttribute> attributes = Collections.emptyList();
- protected List<Group> groups = Collections.emptyList();
- protected List<Role> roles = Collections.emptyList();
-
- public SimpleIdentityObject(String n)
+ public String getName()
{
- this.name = n;
+ return name;
}
public Object getId()
{
- return null;
+ return id;
}
- public String getFQDN()
+ public IdentityObjectType getIdentityType()
{
- return null;
+ return type;
}
- public Map<String, Set<String>> getAttributes()
+ public String getFQDN()
{
return null;
}
- public List<Group> getGroups()
- {
- return Collections.unmodifiableList(groups);
- }
-
- public List<Role> getRoles()
- {
- return Collections.unmodifiableList(roles);
- }
-
- public String getName()
- {
- return name;
- }
-
public void validatePolicy() throws PolicyValidationException
{
Added: trunk/identity-impl/src/test/java/org/jboss/identity/impl/HibernateTestSupport.java
===================================================================
--- trunk/identity-impl/src/test/java/org/jboss/identity/impl/HibernateTestSupport.java (rev 0)
+++ trunk/identity-impl/src/test/java/org/jboss/identity/impl/HibernateTestSupport.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -0,0 +1,130 @@
+/*
+* 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;
+
+import org.jboss.identity.impl.model.hibernate.HibernateIdentityObjectRelationshipType;
+import org.jboss.identity.impl.model.hibernate.HibernateIdentityObjectType;
+import org.hibernate.ejb.HibernateEntityManagerFactory;
+import org.hibernate.ejb.HibernateEntityManager;
+
+import javax.persistence.Persistence;
+import java.util.logging.Logger;
+import java.sql.Connection;
+import java.sql.DriverManager;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class HibernateTestSupport
+{
+ private static Logger logger = Logger.getLogger(HibernateTestSupport.class.getName());
+
+ private HibernateEntityManagerFactory emFactory;
+
+ protected HibernateEntityManager em;
+
+ private Connection connection;
+
+ public HibernateEntityManager getHibernateEntityManager()
+ {
+ return em;
+ }
+
+
+ public void start() throws Exception {
+ try {
+ logger.info("Starting in-memory HSQL database for unit tests");
+ Class.forName("org.hsqldb.jdbcDriver");
+ connection = DriverManager.getConnection("jdbc:hsqldb:mem:unit-testing-jpa", "sa", "");
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ logger.fine("Exception during HSQL database startup.");
+ throw ex;
+ }
+ try
+ {
+ logger.info("Building JPA EntityManager for unit tests");
+ emFactory = (HibernateEntityManagerFactory)Persistence.createEntityManagerFactory("jboss-identity-model");
+ em = (HibernateEntityManager)emFactory.createEntityManager();
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ logger.fine("Exception during JPA EntityManager instanciation.");
+ throw ex;
+ }
+ }
+
+ public void stop() throws Exception {
+ logger.info("Shuting down Hibernate JPA layer.");
+ if (em != null)
+ {
+ em.close();
+ }
+ if (emFactory != null)
+ {
+ emFactory.close();
+ }
+ logger.info("Stopping in-memory HSQL database.");
+ try
+ {
+ connection.createStatement().execute("SHUTDOWN");
+ }
+ catch (Exception ex) {
+ throw ex;
+ }
+ }
+
+ public void populateObjectTypes(String[] typeNames) throws Exception
+ {
+
+ em.getTransaction().begin();
+
+ for (String typeName : typeNames)
+ {
+ HibernateIdentityObjectType hibernateType = new HibernateIdentityObjectType(typeName);
+ em.persist(hibernateType);
+ }
+
+ em.getTransaction().commit();
+ }
+
+ public void populateRelationshipTypes(String[] typeNames) throws Exception
+ {
+
+ em.getTransaction().begin();
+
+ for (String typeName : typeNames)
+ {
+ HibernateIdentityObjectRelationshipType hibernateType = new HibernateIdentityObjectRelationshipType(typeName);
+ em.persist(hibernateType);
+ }
+
+ em.getTransaction().commit();
+ }
+
+
+}
Added: trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/APITestCase.java
===================================================================
--- trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/APITestCase.java (rev 0)
+++ trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/APITestCase.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -0,0 +1,132 @@
+/*
+* 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 junit.framework.TestCase;
+import org.jboss.identity.impl.HibernateTestSupport;
+import org.jboss.identity.impl.store.hibernate.HibernateIdentityStoreImpl;
+import org.jboss.identity.impl.store.hibernate.HibernateIdentityStoreInvocationContext;
+import org.jboss.identity.impl.repository.WrapperIdentityStoreRepository;
+import org.jboss.identity.api.IdentitySessionFactory;
+import org.jboss.identity.api.IdentitySession;
+import org.jboss.identity.spi.repository.IdentityStoreRepository;
+import org.jboss.identity.spi.store.IdentityStoreInvocationContext;
+import org.hibernate.ejb.HibernateEntityManager;
+
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class APITestCase extends TestCase implements APITestContext
+{
+ HibernateTestSupport hibernateSupport = new HibernateTestSupport();
+
+ OrganizationTest orgTest;
+
+ IdentitySessionFactory identitySessionFactory;
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ hibernateSupport.start();
+ orgTest = new OrganizationTest(this);
+
+ }
+
+ protected void tearDown() throws Exception
+ {
+ hibernateSupport.stop();
+ }
+
+ public void testOrganization() throws Exception
+ {
+ prepareRealm(OrganizationTest.RED_HAT_REALM, new String[]{"IDENTITY", "ORGANIZATION", "ORGANIZATION_UNIT", "DIVISION", "DEPARTMENT", "PROJECT", "PEOPLE"});
+ orgTest.testRedHatOrganization();
+ }
+
+ public void testSamplePortal() throws Exception
+ {
+ prepareRealm(OrganizationTest.PORTAL_REALM, new String[]{"IDENTITY", "SYSTEM", "ADMINISTRATION", "COMMUNITY", "ORGANIZATION", "ORGANIZATION_UNIT", "OFFICE", "DIVISION", "DEPARTMENT", "SECURITY", "PEOPLE"});
+ orgTest.testSamplePortal();
+ }
+
+ private void prepareRealm(String realmName, String[] objectTypes) throws Exception
+ {
+
+ Set<SessionWrapper> sessionWrappers = new HashSet<SessionWrapper>();
+ sessionWrappers.add(new EntityManagerWrapper(hibernateSupport.getHibernateEntityManager()));
+
+ hibernateSupport.populateObjectTypes(objectTypes);
+ hibernateSupport.populateRelationshipTypes(new String[]{"JBOSS_IDENTITY_MEMBERSHIP", "JBOSS_IDENTITY_ROLE"});
+
+ HibernateIdentityStoreImpl store = new HibernateIdentityStoreImpl();
+
+ ;
+
+ IdentityStoreRepository repository = new WrapperIdentityStoreRepository(store, store, null, null);
+
+ IdentityObjectTypeMapper iotMapper = new DirectIdentityObjectTypeMapperImpl("IDENTITY");
+
+ final HibernateIdentityStoreInvocationContext hibernateInvocationContext = new HibernateIdentityStoreInvocationContext()
+ {
+ public HibernateEntityManager getHibernateEntityManager()
+ {
+ return hibernateSupport.getHibernateEntityManager();
+ }
+ };
+
+ IdentityStoreInvocationContextResolver contextResolver = new IdentityStoreInvocationContextResolver()
+ {
+ public IdentityStoreInvocationContext resolveInvocationContext()
+ {
+ return hibernateInvocationContext;
+ }
+ };
+
+ IdentitySessionContext identitySessionContext = new IdentitySessionContextImpl(repository, iotMapper, contextResolver);
+
+ IdentitySession identitySession = new IdentitySessionImpl(realmName, identitySessionContext, sessionWrappers);
+
+ Map<String, IdentitySession> sessionMap = new HashMap<String, IdentitySession>();
+
+ sessionMap.put(realmName, identitySession);
+
+ identitySessionFactory = new IdentitySessionFactoryImpl(sessionMap);
+
+ }
+
+
+
+ public IdentitySessionFactory getIdentitySessionFactory()
+ {
+ return identitySessionFactory;
+ }
+
+
+}
+
Modified: 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 2008-10-15 10:59:42 UTC (rev 103)
+++ trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/OrganizationTest.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -42,6 +42,10 @@
public class OrganizationTest extends Assert
{
+ public static final String RED_HAT_REALM = "realm://RedHat";
+
+ public static final String PORTAL_REALM = "realm://portal/SamplePortal";
+
APITestContext ctx;
public OrganizationTest(APITestContext ctx)
@@ -73,7 +77,7 @@
IdentitySessionFactory factory = ctx.getIdentitySessionFactory();
- IdentitySession session = factory.createIdentitySession("realm://RedHat");
+ IdentitySession session = factory.createIdentitySession(RED_HAT_REALM);
session.getTransaction().start();
@@ -136,7 +140,6 @@
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);
@@ -226,7 +229,7 @@
//TODO: alter realm policies to make ORGANIZATION, ORGANIZATION_UNIT, DIVISION, DEPARTMENT and OFFICE hierarchical groups
- IdentitySession session = factory.createIdentitySession("realm://portal/SamplePortal");
+ IdentitySession session = factory.createIdentitySession(PORTAL_REALM);
session.getTransaction().start();
@@ -247,7 +250,7 @@
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);
+ Group usersROOTGroup = session.getPersistenceManager().createGroup("USERS_ROOT",SYSTEM);
// Communities
Deleted: 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 2008-10-15 10:59:42 UTC (rev 103)
+++ trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/SimpleGroupType.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -1,44 +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.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;
- }
-}
Modified: trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/hibernate/HibernateTestBase.java
===================================================================
--- trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/hibernate/HibernateTestBase.java 2008-10-15 10:59:42 UTC (rev 103)
+++ trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/hibernate/HibernateTestBase.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -32,6 +32,7 @@
import org.hibernate.ejb.HibernateEntityManager;
import org.hibernate.ejb.HibernateEntityManagerFactory;
import org.jboss.identity.impl.store.hibernate.HibernateModelTestCase;
+import org.jboss.identity.impl.HibernateTestSupport;
/**
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
@@ -41,13 +42,11 @@
{
private static Logger logger = Logger.getLogger(HibernateModelTestCase.class.getName());
- private HibernateEntityManagerFactory emFactory;
+ private HibernateTestSupport hibernateSupport = new HibernateTestSupport();
protected HibernateEntityManager em;
- private Connection connection;
-
public HibernateTestBase(String testName) {
super(testName);
}
@@ -55,46 +54,13 @@
@Override
protected void setUp() throws Exception {
super.setUp();
- try {
- logger.info("Starting in-memory HSQL database for unit tests");
- Class.forName("org.hsqldb.jdbcDriver");
- connection = DriverManager.getConnection("jdbc:hsqldb:mem:unit-testing-jpa", "sa", "");
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- fail("Exception during HSQL database startup.");
- }
- try
- {
- logger.info("Building JPA EntityManager for unit tests");
- emFactory = (HibernateEntityManagerFactory)Persistence.createEntityManagerFactory("jboss-identity-model");
- em = (HibernateEntityManager)emFactory.createEntityManager();
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- fail("Exception during JPA EntityManager instanciation.");
- }
+ hibernateSupport.start();
+ em = hibernateSupport.getHibernateEntityManager();
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
- logger.info("Shuting down Hibernate JPA layer.");
- if (em != null)
- {
- em.close();
- }
- if (emFactory != null)
- {
- emFactory.close();
- }
- logger.info("Stopping in-memory HSQL database.");
- try
- {
- connection.createStatement().execute("SHUTDOWN");
- }
- catch (Exception ex) {}
+ hibernateSupport.stop();
}
}
Modified: trunk/identity-spi/src/main/java/org/jboss/identity/spi/repository/IdentityStoreRepository.java
===================================================================
--- trunk/identity-spi/src/main/java/org/jboss/identity/spi/repository/IdentityStoreRepository.java 2008-10-15 10:59:42 UTC (rev 103)
+++ trunk/identity-spi/src/main/java/org/jboss/identity/spi/repository/IdentityStoreRepository.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -27,6 +27,7 @@
import org.jboss.identity.spi.model.IdentityObjectType;
import org.jboss.identity.spi.store.IdentityStore;
+import org.jboss.identity.spi.store.AttributeStore;
import org.jboss.identity.spi.policy.RelationshipPolicy;
/**
@@ -46,21 +47,37 @@
Set<IdentityStore> getConfiguredIdentityStores();
/**
- * @return mapping of IdentityType to the specific identity store
+ * @return a set of configured attribute stores
*/
- Map<IdentityObjectType, IdentityStore> getIdentityStoreMappings();
+ Set<AttributeStore> getConfiguredAttributeStores();
/**
+ * @return mapping of IdentityType name to the specific identity store
+ */
+ Map<String, IdentityStore> getIdentityStoreMappings();
+
+ /**
+ * @return mapping of IdentityType name to the specific attribute store
+ */
+ Map<String, AttributeStore> getAttributeStoreMappings();
+
+ /**
* @param identityObjectType
* @return proper identity store to store given identity type
*/
IdentityStore getIdentityStore(IdentityObjectType identityObjectType);
+ /**
+ * @param identityObjectType
+ * @return proper identity store to store given identity type
+ */
+ AttributeStore getAttributeStore(IdentityObjectType identityObjectType);
- /**
- * Return a list of relationship policies
- * @return
- */
- List<RelationshipPolicy<IdentityObjectType, IdentityObjectType>> getRelationshipPolicies(IdentityObjectType identityObjectType);
+
+ /**
+ * Return a list of relationship policies
+ * @return
+ */
+ //List<RelationshipPolicy<IdentityObjectType, IdentityObjectType>> getRelationshipPolicies(IdentityObjectType identityObjectType);
}
\ No newline at end of file
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-10-15 10:59:42 UTC (rev 103)
+++ trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/AttributeStore.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -39,6 +39,8 @@
public interface AttributeStore
{
+ //TODO: replace Set<String> with String[] in method signatures
+
/**
* @param invocationContext
* @param identityType @return names of supported attributes
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-10-15 10:59:42 UTC (rev 103)
+++ trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/IdentityStore.java 2008-10-17 20:52:50 UTC (rev 104)
@@ -191,7 +191,8 @@
* @param createNames
* @throws IdentityException
*/
- void createRelationship(IdentityStoreInvocationContext invocationCxt, IdentityObject fromIdentity,
+ IdentityObjectRelationship createRelationship(IdentityStoreInvocationContext invocationCxt, IdentityObject fromIdentity,
+
IdentityObject toIdentity,
IdentityObjectRelationshipType relationshipType, String relationshipName, boolean createNames) throws IdentityException;
16 years, 3 months
JBoss Identity SVN: r103 - in trunk: identity-impl/src/main/java/org/jboss/identity/impl/model/hibernate and 14 other directories.
by jboss-identity-commits@lists.jboss.org
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>
16 years, 3 months