protected 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: should have isIdentityPresent method } return false; }
IdentityStore resolveIdentityStore(IdentityObject io) throws IdentityException { return resolveIdentityStore(io.getIdentityType()); }
public Map<String, IdentityObjectAttribute> getAttributes(IdentityStoreInvocationContext ctx, IdentityObject identity) throws IdentityException { HibernateIdentityObject hibernateObject = safeGet(ctx, identity); Set<HibernateIdentityObjectAttribute> storeAttributes = hibernateObject.getAttributes(); Map<String, IdentityObjectAttribute> result = new HashMap<String, IdentityObjectAttribute>(); // Remap the names for (HibernateIdentityObjectAttribute attribute : storeAttributes) { String name = resolveAttributeNameFromStoreMapping(identity.getIdentityType(), attribute.getName()); if (name != null) { result.put(name, attribute); } } return result; }
protected User createUser(IdentityObject identityObject) { return new SimpleUser(identityObject.getName()); }
public Map<String, IdentityObjectAttribute> getAttributes(IdentityStoreInvocationContext invocationContext, IdentityObject identity) throws IdentityException { Map<String, IdentityObjectAttribute> results = cacheSupport.getAttributesFromCache(identity.getName(), identity.getIdentityType()); if (results == null) { results = attributeStore.getAttributes(invocationContext, identity); if (results != null && results.size() > 0) { //TODO:FIXME // cacheSupport.putIntoCache(identity, results); } } return results; }
public IdentityObjectAttribute getAttribute(IdentityStoreInvocationContext ctx, IdentityObject identity, String name) throws IdentityException { HibernateIdentityObject hibernateObject = safeGet(ctx, identity); Set<HibernateIdentityObjectAttribute> storeAttributes = hibernateObject.getAttributes(); // Remap the names for (HibernateIdentityObjectAttribute attribute : storeAttributes) { String mappedName = resolveAttributeNameFromStoreMapping(identity.getIdentityType(), name); if (mappedName != null) { return attribute; } } return null; }
public IdentityObjectAttribute getAttribute(IdentityStoreInvocationContext invocationContext, IdentityObject identity, String name) throws IdentityException { Map<String, IdentityObjectAttribute> results = cacheSupport.getAttributesFromCache(identity.getName(), identity.getIdentityType()); if (results != null && results.containsKey(name)) { return results.get(name); } else { return attributeStore.getAttribute(invocationContext, identity, name); //TODO: add this attribute to the node map } }
Set<String> supportedAttrs = toStore.getSupportedAttributeNames(targetCtx, identity.getIdentityType()); Set<String> supportedAttrs = defaultAttributeStore.getSupportedAttributeNames(defaultCtx, identity.getIdentityType()); for (String name : leftAttrs)
private HibernateIdentityObject getHibernateIdentityObject(IdentityStoreInvocationContext ctx, IdentityObject io) throws IdentityException { HibernateIdentityObject hibernateObject = null; Session hibernateSession = getHibernateSession(ctx); try { hibernateObject = (HibernateIdentityObject)hibernateSession.createQuery(HibernateIdentityObject.findIdentityObjectByNameAndType) .setParameter("name", io.getName()) .setParameter("typeName", io.getIdentityType().getName()) .setParameter("realm", getRealm(hibernateSession, ctx)) .uniqueResult(); } catch (Exception e) { throw new IdentityException("IdentityObject[ " + io.getName() + " | " + io.getIdentityType().getName() + "] not present in the store.", e); } return hibernateObject; }
public void removeIdentityObject(IdentityStoreInvocationContext invocationCtx, IdentityObject identity) throws IdentityException { identityStore.removeIdentityObject(invocationCtx, identity); cacheSupport.removeFromCache(identity); cacheSupport.invalidateCachedIdentityObjectSearches(identity); cacheSupport.invalidateCachedIdentityObjectCount(identity.getIdentityType()); }
protected Group createGroup(IdentityObject identityObject) { String groupType = getSessionContext().getIdentityObjectTypeMapper().getGroupType(identityObject.getIdentityType()); return new SimpleGroup(identityObject.getName(), groupType); }
String name = resolveAttributeStoreMapping(identity.getIdentityType(), attributes[i]); mappedAttributes[i] = name; Map<String, IdentityObjectAttributeMetaData> mdMap = attributesMetaData.get(identity.getIdentityType().getName());
public void removeRelationships(IdentityStoreInvocationContext invocationCtx, IdentityObject identity1, IdentityObject identity2, boolean named) throws IdentityException { IdentityStore fromStore = resolveIdentityStore(identity1); IdentityStore toStore = resolveIdentityStore(identity2); IdentityStoreInvocationContext toTargetCtx = resolveInvocationContext(toStore, invocationCtx); IdentityStoreInvocationContext defaultTargetCtx = resolveInvocationContext(defaultIdentityStore, invocationCtx); if (fromStore == toStore) { fromStore.removeRelationships(toTargetCtx, identity1, identity2, named); return; } if (!hasIdentityObject(defaultTargetCtx, defaultIdentityStore, identity1)) { defaultIdentityStore.createIdentityObject(defaultTargetCtx, identity1.getName(), identity1.getIdentityType()); } if (!hasIdentityObject(defaultTargetCtx, defaultIdentityStore, identity2)) { defaultIdentityStore.createIdentityObject(defaultTargetCtx, identity2.getName(), identity2.getIdentityType()); } defaultIdentityStore.removeRelationships(defaultTargetCtx, identity1, identity2, named); }
public Map<String, AttributeDescription> getSupportedAttributesDescriptions(IdentityType identityType) { checkNotNullArgument(identityType, "IdentityType"); Map<String, IdentityObjectAttributeMetaData> mdMap = getRepository().getAttributesMetaData(getInvocationContext(), createIdentityObject(identityType).getIdentityType()); Map<String, AttributeDescription> descriptionMap = new HashMap<String, AttributeDescription>(); if (mdMap != null) { for (IdentityObjectAttributeMetaData attributeMD : mdMap.values()) { if (attributeMD instanceof AttributeDescription) { descriptionMap.put(attributeMD.getName(), (AttributeDescription)attributeMD); } else { descriptionMap.put(attributeMD.getName(), new IdentityObjectAttributeMetaDataImpl(attributeMD)); } } } return descriptionMap; }
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); IdentityStoreInvocationContext toTargetCtx = resolveInvocationContext(toStore, invocationCxt); IdentityStoreInvocationContext defaultTargetCtx = resolveInvocationContext(defaultIdentityStore, invocationCxt); if (fromStore == toStore) { // If relationship is named and target store doesn't support named relationships it need to be put in default store anyway if (relationshipName == null || (relationshipName != null && fromStore.getSupportedFeatures().isNamedRelationshipsSupported())) { return fromStore.createRelationship(toTargetCtx, fromIdentity, toIdentity, relationshipType, relationshipName, createNames); } } if (!hasIdentityObject(defaultTargetCtx, defaultIdentityStore, fromIdentity)) { defaultIdentityStore.createIdentityObject(defaultTargetCtx, fromIdentity.getName(), fromIdentity.getIdentityType()); } if (!hasIdentityObject(defaultTargetCtx, defaultIdentityStore, toIdentity)) { defaultIdentityStore.createIdentityObject(defaultTargetCtx, toIdentity.getName(), toIdentity.getIdentityType()); } return defaultIdentityStore.createRelationship(defaultTargetCtx, fromIdentity, toIdentity, relationshipType, relationshipName, createNames); }
public Collection<Group> findAssociatedGroups(User user, IdentitySearchCriteria criteria) throws IdentityException { checkNotNullArgument(user, "User"); List<Group> identities = new LinkedList<Group>(); Collection<IdentityObject> ios = getRepository().findIdentityObject(getInvocationContext(), createIdentityObject(user), MEMBER, false, convertSearchControls(criteria)); String userTypeName = getUserObjectType().getName(); for (IdentityObject io : ios) { // Filter out users if (!io.getIdentityType().getName().equals(userTypeName)) identities.add(createGroup(io)); } return identities; }
public void removeRelationship(IdentityStoreInvocationContext invocationCxt, IdentityObject fromIdentity, IdentityObject toIdentity, IdentityObjectRelationshipType relationshipType, String relationshipName) throws IdentityException { IdentityStore fromStore = resolveIdentityStore(fromIdentity); IdentityStore toStore = resolveIdentityStore(toIdentity); IdentityStoreInvocationContext toTargetCtx = resolveInvocationContext(toStore, invocationCxt); IdentityStoreInvocationContext defaultTargetCtx = resolveInvocationContext(defaultIdentityStore, invocationCxt); if (fromStore == toStore) { if (relationshipName == null || (relationshipName != null && fromStore.getSupportedFeatures().isNamedRelationshipsSupported())) { fromStore.removeRelationship(toTargetCtx, fromIdentity, toIdentity, relationshipType, relationshipName); return; } } if (!hasIdentityObject(defaultTargetCtx, defaultIdentityStore, fromIdentity)) { defaultIdentityStore.createIdentityObject(defaultTargetCtx, fromIdentity.getName(), fromIdentity.getIdentityType()); } if (!hasIdentityObject(defaultTargetCtx, defaultIdentityStore, toIdentity)) { defaultIdentityStore.createIdentityObject(defaultTargetCtx, toIdentity.getName(), toIdentity.getIdentityType()); } defaultIdentityStore.removeRelationship(defaultTargetCtx, fromIdentity, toIdentity, relationshipType, relationshipName); }
Set<String> supportedAttrs = toStore.getSupportedAttributeNames(targetCtx, identity.getIdentityType()); Set<String> supportedAttrs = defaultAttributeStore.getSupportedAttributeNames(defaultCtx, identity.getIdentityType()); for (IdentityObjectAttribute entry : attributesToAdd)
public Set<IdentityObjectRelationship> resolveRelationships(IdentityStoreInvocationContext invocationCxt, IdentityObject fromIdentity, IdentityObject toIdentity, IdentityObjectRelationshipType relationshipType) throws IdentityException { IdentityStore fromStore = resolveIdentityStore(fromIdentity); IdentityStore toStore = resolveIdentityStore(toIdentity); IdentityStoreInvocationContext toTargetCtx = resolveInvocationContext(toStore, invocationCxt); IdentityStoreInvocationContext defaultTargetCtx = resolveInvocationContext(defaultIdentityStore, invocationCxt); if (fromStore == toStore && (!RoleManagerImpl.ROLE.getName().equals(relationshipType.getName()) || fromStore.getSupportedFeatures().isNamedRelationshipsSupported())) { return fromStore.resolveRelationships(toTargetCtx, fromIdentity, toIdentity, relationshipType); } if (!hasIdentityObject(defaultTargetCtx, defaultIdentityStore, fromIdentity)) { defaultIdentityStore.createIdentityObject(defaultTargetCtx, fromIdentity.getName(), fromIdentity.getIdentityType()); } if (!hasIdentityObject(defaultTargetCtx, defaultIdentityStore, toIdentity)) { defaultIdentityStore.createIdentityObject(defaultTargetCtx, toIdentity.getName(), toIdentity.getIdentityType()); } return defaultIdentityStore.resolveRelationships(defaultTargetCtx, fromIdentity, toIdentity, relationshipType); }