Author: bdaw
Date: 2008-12-17 12:15:21 -0500 (Wed, 17 Dec 2008)
New Revision: 169
Modified:
trunk/identity-api/src/main/java/org/jboss/identity/api/AttributesManager.java
trunk/identity-api/src/main/java/org/jboss/identity/api/Role.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/AttributesManagerImpl.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/BinaryCredential.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/PasswordCredential.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/RoleManagerImpl.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleRoleImpl.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/repository/FallbackIdentityStoreRepository.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/LDAPIdentityStoreImpl.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/CommonIdentityStoreTest.java
trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/IdentityStore.java
Log:
++
Modified: trunk/identity-api/src/main/java/org/jboss/identity/api/AttributesManager.java
===================================================================
---
trunk/identity-api/src/main/java/org/jboss/identity/api/AttributesManager.java 2008-12-16
17:33:03 UTC (rev 168)
+++
trunk/identity-api/src/main/java/org/jboss/identity/api/AttributesManager.java 2008-12-17
17:15:21 UTC (rev 169)
@@ -168,7 +168,7 @@
* @param identity
* @param credentialType
*/
- void hasCredential(Identity identity, CredentialType credentialType);
+ boolean hasCredential(Identity identity, CredentialType credentialType) throws
IdentityException;
/**
*
@@ -176,13 +176,13 @@
* @param credentials
* @return
*/
- boolean validateCredentials(Identity identity, Credential[] credentials);
+ boolean validateCredentials(Identity identity, Credential[] credentials) throws
IdentityException;
/**
*
* @param identity
* @param credential
*/
- void updateCredential(Identity identity, Credential credential);
+ void updateCredential(Identity identity, Credential credential) throws
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-12-16 17:33:03
UTC (rev 168)
+++ trunk/identity-api/src/main/java/org/jboss/identity/api/Role.java 2008-12-17 17:15:21
UTC (rev 169)
@@ -32,11 +32,6 @@
public interface Role
{
/**
- * @return id of this identity object
- */
- Object getId();
-
- /**
* @return description
*/
String getDescription();
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/AttributesManagerImpl.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/AttributesManagerImpl.java 2008-12-16
17:33:03 UTC (rev 168)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/AttributesManagerImpl.java 2008-12-17
17:15:21 UTC (rev 169)
@@ -31,6 +31,7 @@
import org.jboss.identity.api.Credential;
import org.jboss.identity.exception.IdentityException;
import org.jboss.identity.impl.NotYetImplementedException;
+import org.jboss.identity.spi.credential.IdentityObjectCredential;
import java.util.Set;
import java.util.Map;
@@ -42,6 +43,7 @@
*/
public class AttributesManagerImpl extends AbstractManager implements AttributesManager
{
+
public AttributesManagerImpl(IdentitySession session)
{
super(session);
@@ -104,42 +106,66 @@
public void removeAttributes(IdentityType identity, String[] attributes) throws
IdentityException
{
getRepository().removeAttributes(getInvocationContext(),
createIdentityObject(identity), attributes);
-
}
public boolean hasPasswordAttribute(Identity identity) throws IdentityException
{
- //TODO:NYI
- throw new NotYetImplementedException();
+ return
getRepository().getSupportedFeatures().isCredentialSupported(createIdentityObject(identity).getIdentityType(),
PasswordCredential.TYPE);
}
public boolean validatePasswordAttribute(Identity identity, String password) throws
IdentityException
{
- //TODO:NYI
- throw new NotYetImplementedException();
+ return getRepository().validateCredential(getInvocationContext(),
createIdentityObject(identity), new PasswordCredential(password));
}
public void updatePasswordAttribute(Identity identity, String password) throws
IdentityException
{
- //TODO:NYI
- throw new NotYetImplementedException();
+ getRepository().updateCredential(getInvocationContext(),
createIdentityObject(identity), new PasswordCredential(password));
}
- public void hasCredential(Identity identity, CredentialType credentialType)
+ public boolean hasCredential(Identity identity, CredentialType credentialType) throws
IdentityException
{
- //TODO:NYI
- throw new NotYetImplementedException();
+ return
getRepository().getSupportedFeatures().isCredentialSupported(createIdentityObject(identity).getIdentityType(),
new SimpleCredentialTypeImpl(credentialType.getName()));
}
- public boolean validateCredentials(Identity identity, Credential[] credentials)
+ public boolean validateCredentials(Identity identity, Credential[] credentials) throws
IdentityException
{
- //TODO:NYI
- throw new NotYetImplementedException();
+
+ for (Credential credential : credentials)
+ {
+ IdentityObjectCredential ioc = null;
+
+ //Handle only those credentials that implement SPI
+
+ if (credential instanceof IdentityObjectCredential)
+ {
+ ioc = (IdentityObjectCredential)ioc;
+ }
+ else
+ {
+ throw new IdentityException("Unsupported Credential implementation:
" + credential.getClass());
+ }
+
+ // All credentials must pass
+
+ if (!getRepository().validateCredential(getInvocationContext(),
createIdentityObject(identity), ioc))
+ {
+ return false;
+ }
+ }
+
+ return true;
}
- public void updateCredential(Identity identity, Credential credential)
+ public void updateCredential(Identity identity, Credential credential) throws
IdentityException
{
- //TODO:NYI
- throw new NotYetImplementedException();
+ if (credential instanceof IdentityObjectCredential)
+ {
+ getRepository().updateCredential(getInvocationContext(),
createIdentityObject(identity), (IdentityObjectCredential)credential);
+ }
+ else
+ {
+ throw new IdentityException("Unsupported Credential implementation: "
+ credential.getClass());
+ }
}
}
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/BinaryCredential.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/BinaryCredential.java 2008-12-16
17:33:03 UTC (rev 168)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/BinaryCredential.java 2008-12-17
17:15:21 UTC (rev 169)
@@ -30,9 +30,11 @@
{
private final byte[] value;
+ public static final SimpleCredentialTypeImpl TYPE = new
SimpleCredentialTypeImpl("BINARY");
+
public BinaryCredential(byte[] value)
{
- super(new SimpleCredentialTypeImpl("BINARY"));
+ super(TYPE);
this.value = value;
}
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/PasswordCredential.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/PasswordCredential.java 2008-12-16
17:33:03 UTC (rev 168)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/PasswordCredential.java 2008-12-17
17:15:21 UTC (rev 169)
@@ -33,9 +33,11 @@
{
private final String value;
+ public static final SimpleCredentialTypeImpl TYPE = new
SimpleCredentialTypeImpl("PASSWORD");
+
public PasswordCredential(String value)
{
- super(new SimpleCredentialTypeImpl("PASSWORD"));
+ super(TYPE);
this.value = value;
}
Modified:
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 2008-12-16
17:33:03 UTC (rev 168)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/RelationshipManagerImpl.java 2008-12-17
17:15:21 UTC (rev 169)
@@ -142,7 +142,7 @@
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
+ //TODO: maybe IdentityStore should have isRelationshipPresent method to improve
this?
for (Iterator<G> parentsIterator = parents.iterator();
parentsIterator.hasNext();)
{
@@ -152,21 +152,10 @@
{
IdentityType member = membersIterator.next();
- Collection<IdentityObjectRelationship> relationships =
getRepository().resolveRelationships(getInvocationContext(), createIdentityObject(parent),
createIdentityObject(member));
+ Collection<IdentityObjectRelationship> relationships =
getRepository().resolveRelationships(getInvocationContext(), createIdentityObject(parent),
createIdentityObject(member), MEMBER);
- boolean isRelated = false;
-
- for (Iterator<IdentityObjectRelationship>
identityObjectRelationshipIterator = relationships.iterator();
identityObjectRelationshipIterator.hasNext();)
+ if (relationships.size() == 0)
{
- IdentityObjectRelationship rel =
identityObjectRelationshipIterator.next();
- if (rel.getType().getName().equals(MEMBER.getName()))
- {
- isRelated = true;
- }
- }
-
- if (!isRelated)
- {
return false;
}
}
@@ -192,7 +181,7 @@
IdentityObjectType iot = getIdentityObjectType(groupType);
- //TODO inherited
+ //TODO Handle inherited
Collection<IdentityObject> ios =
getRepository().findIdentityObject(getInvocationContext(), createIdentityObject(group),
MEMBER, parent, convertSearchControls(controls));
@@ -260,10 +249,12 @@
{
List<Identity> identities = new LinkedList<Identity>();
- //TODO inherited
+ //TODO Handle inherited
Collection<IdentityObject> ios =
getRepository().findIdentityObject(getInvocationContext(), createIdentityObject(group),
MEMBER, true, convertSearchControls(controls));
+ //TODO: filter out groups....
+
for (IdentityObject io : ios)
{
identities.add(createIdentity(io));
Modified:
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 2008-12-16
17:33:03 UTC (rev 168)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/RoleManagerImpl.java 2008-12-17
17:15:21 UTC (rev 169)
@@ -34,6 +34,7 @@
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.model.IdentityObject;
import org.jboss.identity.spi.exception.OperationNotSupportedException;
import org.jboss.identity.impl.NotYetImplementedException;
@@ -145,7 +146,7 @@
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()));
+ return new SimpleRoleImpl(new SimpleRoleType(rel.getName()),
createIdentity(rel.getFromIdentityObject()), createGroup(rel.getToIdentityObject()));
}
@@ -161,9 +162,9 @@
public boolean hasRole(Identity identity, Group group, RoleType roleType) throws
IdentityException
{
- //TODO: add hasRelationship to IdentityStore
+ //TODO: does separate hasRelationship method in IdentityStore makes sense?
- Set<IdentityObjectRelationship> rels =
getRepository().resolveRelationships(getInvocationContext(),
createIdentityObject(identity), createIdentityObject(group));
+ Set<IdentityObjectRelationship> rels =
getRepository().resolveRelationships(getInvocationContext(),
createIdentityObject(identity), createIdentityObject(group), ROLE);
for (IdentityObjectRelationship rel : rels)
{
@@ -183,18 +184,13 @@
public Collection<RoleType> findRoleTypes(Identity identity, Group group,
IdentitySearchControl[] controls) throws IdentityException
{
- //TODO: improve IdentityStore SPI....
-
- Set<IdentityObjectRelationship> rels =
getRepository().resolveRelationships(getInvocationContext(),
createIdentityObject(identity), createIdentityObject(group));
+ Set<IdentityObjectRelationship> rels =
getRepository().resolveRelationships(getInvocationContext(),
createIdentityObject(identity), createIdentityObject(group), ROLE);
Set<RoleType> types = new HashSet<RoleType>();
for (IdentityObjectRelationship rel : rels)
{
- if (rel.getType().getName().equals(ROLE.getName()))
- {
- types.add(new SimpleRoleType(rel.getName()));
- }
+ types.add(new SimpleRoleType(rel.getName()));
}
return types;
@@ -265,6 +261,27 @@
public <T extends IdentityType> Collection<Role> findRoles(T identityType,
RoleType roleType, IdentitySearchControl[] controls) throws IdentityException
{
- throw new NotYetImplementedException();
+ Set<Role> roles = new HashSet<Role>();
+
+ Set<IdentityObjectRelationship> relationships = null;
+
+ // If Identity then search for parent relationships
+ if (identityType instanceof Identity)
+ {
+ relationships = getRepository().resolveRelationships(getInvocationContext(),
createIdentityObject(identityType), ROLE, true, true, null);
+ }
+ // If Group then search for child relationships
+ else
+ {
+ relationships = getRepository().resolveRelationships(getInvocationContext(),
createIdentityObject(identityType), ROLE, false, true, null);
+ }
+
+ for (IdentityObjectRelationship relationship : relationships)
+ {
+ roles.add(new SimpleRoleImpl(new SimpleRoleType(relationship.getName()),
createIdentity(relationship.getFromIdentityObject()),
createGroup(relationship.getToIdentityObject())));
+ }
+
+ return roles;
+
}
}
Modified:
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 2008-12-16
17:33:03 UTC (rev 168)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleRoleImpl.java 2008-12-17
17:15:21 UTC (rev 169)
@@ -33,27 +33,19 @@
*/
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)
+ public SimpleRoleImpl(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;
Modified:
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 2008-12-16
17:33:03 UTC (rev 168)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/repository/FallbackIdentityStoreRepository.java 2008-12-17
17:15:21 UTC (rev 169)
@@ -43,6 +43,8 @@
import org.jboss.identity.impl.api.SortByNameSearchControl;
import org.jboss.identity.impl.api.AttributeFilterSearchControl;
import org.jboss.identity.impl.api.NameFilterSearchControl;
+import org.jboss.identity.impl.NotYetImplementedException;
+import org.jboss.identity.impl.configuration.jaxb2.generated.RelationshipType;
import org.jboss.identity.api.Identity;
import java.util.Map;
@@ -91,6 +93,8 @@
private boolean allowNotDefinedAttributes = false;
+ private final Set<IdentityStore> configuredIdentityStores = new
HashSet<IdentityStore>();
+
public FallbackIdentityStoreRepository(String id)
{
this.id = id;
@@ -102,6 +106,15 @@
{
super.bootstrap(configurationMD, bootstrappedIdentityStores,
bootstrappedAttributeStores);
+ // Helper collection to keep all identity stores in use
+
+ if (getIdentityStoreMappings().size() > 0)
+ {
+ configuredIdentityStores.addAll(getIdentityStoreMappings().values());
+ }
+
+
+
this.configurationMD = configurationMD;
String asId = configurationMD.getDefaultAttributeStroeId();
@@ -115,6 +128,12 @@
if (isId != null && bootstrappedIdentityStores.keySet().contains(isId))
{
defaultIdentityStore = bootstrappedIdentityStores.get(isId);
+
+ if
(!getIdentityStoreMappings().keySet().contains(defaultIdentityStore.getId()))
+ {
+ configuredIdentityStores.add(defaultIdentityStore);
+ }
+
}
String allowNotDefineAttributes =
configurationMD.getOptionSingleValue(ALLOW_NOT_DEFINED_ATTRIBUTES);
@@ -523,7 +542,10 @@
defaultIdentityStore.removeRelationships(defaultTargetCtx, identity1, identity2,
named);
}
- public Set<IdentityObjectRelationship>
resolveRelationships(IdentityStoreInvocationContext invocationCxt, IdentityObject
fromIdentity, IdentityObject toIdentity) throws IdentityException
+ public Set<IdentityObjectRelationship>
resolveRelationships(IdentityStoreInvocationContext invocationCxt,
+ IdentityObject
fromIdentity,
+ IdentityObject
toIdentity,
+
IdentityObjectRelationshipType relationshipType) throws IdentityException
{
IdentityStore fromStore = resolveIdentityStore(fromIdentity);
@@ -536,7 +558,7 @@
if (fromStore == toStore)
{
- return fromStore.resolveRelationships(toTargetCtx, fromIdentity, toIdentity);
+ return fromStore.resolveRelationships(toTargetCtx, fromIdentity, toIdentity,
relationshipType);
}
@@ -550,30 +572,44 @@
defaultIdentityStore.createIdentityObject(defaultTargetCtx,
toIdentity.getName(), toIdentity.getIdentityType());
}
- return defaultIdentityStore.resolveRelationships(defaultTargetCtx, fromIdentity,
toIdentity);
- }
+ return defaultIdentityStore.resolveRelationships(defaultTargetCtx, fromIdentity,
toIdentity, relationshipType);
+ }
- public String createRelationshipName(IdentityStoreInvocationContext ctx, String name)
throws IdentityException, OperationNotSupportedException
+ public Set<IdentityObjectRelationship>
resolveRelationships(IdentityStoreInvocationContext ctx, IdentityObject identity,
IdentityObjectRelationshipType relationshipType, boolean parent, boolean named, String
name) throws IdentityException
{
- Set<IdentityStore> stores = new
HashSet<IdentityStore>(getIdentityStoreMappings().values());
+ IdentityStore store = resolveIdentityStore(identity);
+ Set<IdentityObjectRelationship> relationships = new
HashSet<IdentityObjectRelationship>();
+
// For any IdentityStore that supports named relationships...
- for (IdentityStore identityStore : stores)
+ for (IdentityStore identityStore : configuredIdentityStores)
{
- if (identityStore.getSupportedFeatures().isNamedRelationshipsSupported())
+ if
(!identityStore.getSupportedFeatures().getSupportedRelationshipTypes().contains(relationshipType.getName()))
{
+ continue;
+ }
+
+ if (!named || (named &&
identityStore.getSupportedFeatures().isNamedRelationshipsSupported()))
+ {
IdentityStoreInvocationContext storeCtx =
resolveInvocationContext(identityStore, ctx);
- identityStore.createRelationshipName(storeCtx, name);
-
+ relationships.addAll(identityStore.resolveRelationships(storeCtx, identity,
relationshipType, parent, named, name));
}
}
- if (!getIdentityStoreMappings().values().contains(defaultIdentityStore) &&
- defaultIdentityStore.getSupportedFeatures().isNamedRelationshipsSupported())
+ return relationships;
+ }
+
+ public String createRelationshipName(IdentityStoreInvocationContext ctx, String name)
throws IdentityException, OperationNotSupportedException
+ {
+ // For any IdentityStore that supports named relationships...
+ for (IdentityStore identityStore : configuredIdentityStores)
{
- IdentityStoreInvocationContext defaultCtx =
resolveInvocationContext(defaultIdentityStore, ctx);
+ if (identityStore.getSupportedFeatures().isNamedRelationshipsSupported())
+ {
+ IdentityStoreInvocationContext storeCtx =
resolveInvocationContext(identityStore, ctx);
+ identityStore.createRelationshipName(storeCtx, name);
- defaultIdentityStore.createRelationshipName(defaultCtx, name);
+ }
}
return name;
@@ -582,10 +618,8 @@
public String removeRelationshipName(IdentityStoreInvocationContext ctx, String name)
throws IdentityException, OperationNotSupportedException
{
- Set<IdentityStore> stores = new
HashSet<IdentityStore>(getIdentityStoreMappings().values());
-
// For any IdentityStore that supports named relationships...
- for (IdentityStore identityStore : stores)
+ for (IdentityStore identityStore : configuredIdentityStores)
{
if (identityStore.getSupportedFeatures().isNamedRelationshipsSupported())
{
@@ -595,25 +629,15 @@
}
}
- if (!getIdentityStoreMappings().values().contains(defaultIdentityStore) &&
- defaultIdentityStore.getSupportedFeatures().isNamedRelationshipsSupported())
- {
- IdentityStoreInvocationContext defaultCtx =
resolveInvocationContext(defaultIdentityStore, ctx);
-
- defaultIdentityStore.removeRelationshipName(defaultCtx, name);
- }
-
return name;
}
public Set<String> getRelationshipNames(IdentityStoreInvocationContext ctx,
IdentityObjectSearchControl[] controls) throws IdentityException,
OperationNotSupportedException
{
- Set<IdentityStore> stores = new
HashSet<IdentityStore>(getIdentityStoreMappings().values());
-
Set<String> results = new HashSet<String>();
// For any IdentityStore that supports named relationships...
- for (IdentityStore identityStore : stores)
+ for (IdentityStore identityStore : configuredIdentityStores)
{
if (identityStore.getSupportedFeatures().isNamedRelationshipsSupported())
{
@@ -623,13 +647,6 @@
}
}
- if (defaultIdentityStore.getSupportedFeatures().isNamedRelationshipsSupported())
- {
- IdentityStoreInvocationContext defaultCtx =
resolveInvocationContext(defaultIdentityStore, ctx);
-
- results.addAll(defaultIdentityStore.getRelationshipNames(defaultCtx,
controls));
- }
-
return results;
}
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-12-16
17:33:03 UTC (rev 168)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/hibernate/HibernateIdentityStoreImpl.java 2008-12-17
17:15:21 UTC (rev 169)
@@ -55,6 +55,7 @@
import org.hibernate.ejb.HibernateEntityManagerFactory;
import org.hibernate.criterion.Restrictions;
import org.hibernate.HibernateException;
+import org.hibernate.Criteria;
import javax.persistence.NoResultException;
import javax.persistence.Query;
@@ -91,6 +92,29 @@
"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_FROM =
+// "select r from HibernateIdentityObjectRelationship r where
r.fromIdentityObject like :fromIO";
+//
+// private final String QUERY_RELATIONSHIP_BY_FROM_NAMED =
+// "select r from HibernateIdentityObjectRelationship r where
r.fromIdentityObject like :fromIO and " +
+// "r.name is not null";
+//
+// private final String QUERY_RELATIONSHIP_BY_FROM_NAME =
+// "select r from HibernateIdentityObjectRelationship r where
r.fromIdentityObject like :fromIO and " +
+// "r.name.name = :name";
+//
+// private final String QUERY_RELATIONSHIP_BY_TO =
+// "select r from HibernateIdentityObjectRelationship r where
r.toIdentityObject like :toIO";
+//
+// private final String QUERY_RELATIONSHIP_BY_TO_NAMED =
+// "select r from HibernateIdentityObjectRelationship r where
r.toIdentityObject like :toIO and" +
+// "r.name is not null";
+//
+// private final String QUERY_RELATIONSHIP_BY_TO_NAME =
+// "select r from HibernateIdentityObjectRelationship r where
r.toIdentityObject like :toIO and " +
+// "r.name.name = :name";
+
+
private final String QUERY_RELATIONSHIP_BY_IDENTITIES =
"select r from HibernateIdentityObjectRelationship r where " +
"(r.fromIdentityObject like :IO1 and r.toIdentityObject like :IO2) or
" +
@@ -905,21 +929,83 @@
}
}
- public Set<IdentityObjectRelationship>
resolveRelationships(IdentityStoreInvocationContext ctx, IdentityObject fromIdentity,
IdentityObject toIdentity) throws IdentityException
+ public Set<IdentityObjectRelationship>
resolveRelationships(IdentityStoreInvocationContext ctx,
+ IdentityObject
fromIdentity,
+ IdentityObject
toIdentity,
+
IdentityObjectRelationshipType relationshipType) throws IdentityException
{
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)
+ org.hibernate.Query query = null;
+
+ if (relationshipType == null)
+ {
+ query =
getHibernateEntityManager(ctx).getSession().createQuery(QUERY_RELATIONSHIP_BY_FROM_TO);
+ }
+ else
+ {
+ query =
getHibernateEntityManager(ctx).getSession().createQuery(QUERY_RELATIONSHIP_BY_FROM_TO_TYPE)
+ .setParameter("typeName", relationshipType.getName());
+
+ }
+
+ query.setParameter("fromIO", hio1)
.setParameter("toIO", hio2);
+
List<HibernateIdentityObjectRelationship> results = query.list();
return new HashSet<IdentityObjectRelationship>(results);
}
+ public Set<IdentityObjectRelationship>
resolveRelationships(IdentityStoreInvocationContext ctx,
+ IdentityObject identity,
+
IdentityObjectRelationshipType type,
+ boolean parent,
+ boolean named,
+ String name) throws
IdentityException
+ {
+ HibernateIdentityObject hio = safeGet(ctx, identity);
+
+
+ Criteria criteria =
getHibernateEntityManager(ctx).getSession().createCriteria(HibernateIdentityObjectRelationship.class);
+
+ if (type != null)
+ {
+ HibernateIdentityObjectRelationshipType hibernateType =
getHibernateIdentityObjectRelationshipType(ctx, type);
+
+ criteria.add(Restrictions.eq("type", hibernateType));
+ }
+
+ if (name != null)
+ {
+ criteria.add(Restrictions.eq("name.name", name));
+ }
+ else if (named)
+ {
+ criteria.add(Restrictions.isNotNull("name"));
+ }
+ else
+ {
+ criteria.add(Restrictions.isNull("name"));
+ }
+
+ if (parent)
+ {
+ criteria.add(Restrictions.eq("fromIdentityObject", hio));
+ }
+ else
+ {
+ criteria.add(Restrictions.eq("toIdentityObject", hio));
+ }
+
+ List<HibernateIdentityObjectRelationship> results = criteria.list();
+
+ return new HashSet<IdentityObjectRelationship>(results);
+ }
+
public String createRelationshipName(IdentityStoreInvocationContext ctx, String name)
throws IdentityException, OperationNotSupportedException
{
if (name == null)
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/ldap/LDAPIdentityStoreImpl.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/ldap/LDAPIdentityStoreImpl.java 2008-12-16
17:33:03 UTC (rev 168)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/ldap/LDAPIdentityStoreImpl.java 2008-12-17
17:15:21 UTC (rev 169)
@@ -722,6 +722,10 @@
public Collection<IdentityObject>
findIdentityObject(IdentityStoreInvocationContext ctx, IdentityObject identity,
IdentityObjectRelationshipType relationshipType, boolean parent,
IdentityObjectSearchControl[] controls) throws IdentityException
{
+ //TODO: relationshipType is ignored - maybe check and allow only MEMBERSHIP?
+
+
+
checkControls(controls);
PageSearchControl pageSearchControl = null;
@@ -944,6 +948,164 @@
return objects;
}
+ public Set<IdentityObjectRelationship>
resolveRelationships(IdentityStoreInvocationContext ctx,
+ IdentityObject identity,
+
IdentityObjectRelationshipType type,
+ boolean parent,
+ boolean named,
+ String name) throws
IdentityException
+ {
+ //TODO: relationshipType is ignored - maybe check and allow only MEMBERSHIP?
+
+
+
+ LDAPIdentityObjectImpl ldapIO = getSafeLDAPIO(ctx, identity);
+
+ LDAPIdentityObjectTypeConfiguration typeConfig = getTypeConfiguration(ctx,
identity.getIdentityType());
+
+ LdapContext ldapContext = getLDAPContext(ctx);
+
+ Set<IdentityObjectRelationship> relationships = new
HashSet<IdentityObjectRelationship>();
+
+ try
+ {
+
+ // If parent simply look for all its members
+ if (parent)
+ {
+ Attributes attrs = ldapContext.getAttributes(ldapIO.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: use direct LDAP query instaed of other find method and add
attributesFilter
+
+
+ relationships.add(new LDAPIdentityObjectRelationshipImpl(null,
ldapIO, findIdentityObject(ctx, memberRef)));
+
+ }
+ else
+ {
+ //TODO: if relationships are not refered with DNs and only names its
not possible to map
+ //TODO: them to proper IdentityType and keep name uniqnes per type.
Workaround needed
+ throw new NotYetImplementedException("LDAP limitation. If
relationship targets are not refered with FQDNs " +
+ "and only names, it's not possible to map them to proper
IdentityType and keep name uniqnes per type. " +
+ "Workaround needed");
+ }
+ //break;
+ }
+ }
+ }
+
+ // if not parent then all parent entries need to be found
+ else
+ {
+ // Search in all other type contexts
+ for (IdentityObjectType parentType : configuration.getConfiguredTypes())
+ {
+ checkIOType(parentType);
+
+ LDAPIdentityObjectTypeConfiguration parentTypeConfiguration =
getTypeConfiguration(ctx, parentType);
+
+ List<String> allowedTypes =
Arrays.asList(parentTypeConfiguration.getAllowedMembershipTypes());
+
+ // Check if given identity type can be parent
+ if (!allowedTypes.contains(identity.getIdentityType().getName()))
+ {
+ continue;
+ }
+
+ String nameFilter = "*";
+
+ //Filter by name
+ Control[] requestControls = null;
+
+ StringBuilder af = new StringBuilder();
+
+
+ // Add filter to search only parents of the given entry
+ af.append("(")
+ .append(parentTypeConfiguration.getMembershipAttributeName())
+ .append("=");
+ if (parentTypeConfiguration.isMembershipAttributeDN())
+ {
+ af.append(ldapIO.getDn());
+ }
+ else
+ {
+ //TODO: this doesn't make much sense unless parent/child are same
identity types and resides in the same LDAP context
+ af.append(ldapIO.getName());
+ }
+ af.append(")");
+
+
+ String filter = parentTypeConfiguration.getEntrySearchFilter();
+ List<SearchResult> sr = null;
+
+ String[] entryCtxs = parentTypeConfiguration.getCtxDNs();
+
+ if (filter != null && filter.length() > 0)
+ {
+
+ Object[] filterArgs = {nameFilter};
+ sr = searchIdentityObjects(ctx,
+ entryCtxs,
+ "(&(" + filter + ")" + af.toString() +
")",
+ filterArgs,
+ new String[]{parentTypeConfiguration.getIdAttributeName()},
+ requestControls);
+ }
+ else
+ {
+ filter =
"(".concat(parentTypeConfiguration.getIdAttributeName()).concat("=").concat(nameFilter).concat(")");
+ sr = searchIdentityObjects(ctx,
+ entryCtxs,
+ "(&(" + filter + ")" + af.toString() +
")",
+ null,
+ new String[]{parentTypeConfiguration.getIdAttributeName()},
+ requestControls);
+ }
+
+ for (SearchResult res : sr)
+ {
+ LdapContext ldapCtx = (LdapContext)res.getObject();
+ String dn = ldapCtx.getNameInNamespace();
+
+ relationships.add(new LDAPIdentityObjectRelationshipImpl(null,
createIdentityObjectInstance(ctx, parentType, res.getAttributes(), dn), ldapIO));
+ }
+ }
+
+
+ }
+
+ }
+ 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 Collection<IdentityObject>
findIdentityObject(IdentityStoreInvocationContext ctx,
IdentityObject identity,
IdentityObjectRelationshipType
relationshipType,
@@ -1117,9 +1279,10 @@
}
- public Set<IdentityObjectRelationship>
resolveRelationships(IdentityStoreInvocationContext ctx, IdentityObject fromIdentity,
IdentityObject toIdentity) throws IdentityException
+ public Set<IdentityObjectRelationship>
resolveRelationships(IdentityStoreInvocationContext ctx, IdentityObject fromIdentity,
IdentityObject toIdentity, IdentityObjectRelationshipType relationshipType) throws
IdentityException
{
// relationshipType is ignored for now
+
if (log.isLoggable(Level.FINER))
{
Modified:
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 2008-12-16
17:33:03 UTC (rev 168)
+++
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/CommonIdentityStoreTest.java 2008-12-17
17:15:21 UTC (rev 169)
@@ -256,26 +256,26 @@
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());
+ assertEquals(1, testContext.getStore().resolveRelationships(testContext.getCtx(),
group1, user1, null).size());
+ assertEquals(0, testContext.getStore().resolveRelationships(testContext.getCtx(),
user1, group1, null).size());
+ assertEquals(1, testContext.getStore().resolveRelationships(testContext.getCtx(),
group2, user1, null).size());
+ assertEquals(0, testContext.getStore().resolveRelationships(testContext.getCtx(),
user1, group2, null).size());
testContext.getStore().removeRelationship(testContext.getCtx(), group2, user1,
RelationshipTypeEnum.JBOSS_IDENTITY_MEMBERSHIP, 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());
+ assertEquals(1, testContext.getStore().resolveRelationships(testContext.getCtx(),
group1, user1, null).size());
+ assertEquals(0, testContext.getStore().resolveRelationships(testContext.getCtx(),
user1, group1, null).size());
+ assertEquals(0, testContext.getStore().resolveRelationships(testContext.getCtx(),
group2, user1, null).size());
+ assertEquals(0, testContext.getStore().resolveRelationships(testContext.getCtx(),
user1, group2, null).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());
+ assertEquals(0, testContext.getStore().resolveRelationships(testContext.getCtx(),
group1, user1, null).size());
+ assertEquals(0, testContext.getStore().resolveRelationships(testContext.getCtx(),
user1, group1, null).size());
+ assertEquals(0, testContext.getStore().resolveRelationships(testContext.getCtx(),
group2, user1, null).size());
+ assertEquals(0, testContext.getStore().resolveRelationships(testContext.getCtx(),
user1, group2, null).size());
testContext.flush();
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-12-16
17:33:03 UTC (rev 168)
+++
trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/IdentityStore.java 2008-12-17
17:15:21 UTC (rev 169)
@@ -216,19 +216,42 @@
throws IdentityException;
/**
- * Resolve relationship types between two identities. Relationships can be
directional
+ * Resolve relationships between two identities. Relationships can be directional
* so order of parameters matters
*
* @param invocationCxt
* @param fromIdentity
* @param toIdentity
+ * @param relationshipType - may be null
* @return
* @throws IdentityException
*/
- Set<IdentityObjectRelationship>
resolveRelationships(IdentityStoreInvocationContext invocationCxt, IdentityObject
fromIdentity, IdentityObject toIdentity)
+ Set<IdentityObjectRelationship>
resolveRelationships(IdentityStoreInvocationContext invocationCxt,
+ IdentityObject fromIdentity,
+ IdentityObject toIdentity,
+ IdentityObjectRelationshipType
relationshipType)
throws IdentityException;
+ /**
+ * Resolve relationships for a given IdentityObject. Relationships can be directional
and parent switch defines which
+ * role identity play in it.
+ * @param invocationCxt
+ * @param identity
+ * @param named
+ * @param name - can be null
+ * @return
+ * @throws IdentityException
+ */
+ Set<IdentityObjectRelationship>
resolveRelationships(IdentityStoreInvocationContext invocationCxt,
+ IdentityObject identity,
+ IdentityObjectRelationshipType
relationshipType,
+ boolean parent,
+ boolean named,
+ String name)
+ throws IdentityException;
+
+
// Named relationships
/**