IdentityStore resolveIdentityStore(IdentityObject io) throws IdentityException { return resolveIdentityStore(io.getIdentityType()); }
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 } }
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; }
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 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; }
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 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 void removeIdentityObject(IdentityStoreInvocationContext invocationCtx, IdentityObject identity) throws IdentityException { identityStore.removeIdentityObject(invocationCtx, identity); cacheSupport.removeFromCache(identity); cacheSupport.invalidateCachedIdentityObjectSearches(identity); cacheSupport.invalidateCachedIdentityObjectCount(identity.getIdentityType()); }
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; }
protected Group createGroup(IdentityObject identityObject) { String groupType = getSessionContext().getIdentityObjectTypeMapper().getGroupType(identityObject.getIdentityType()); return new SimpleGroup(identityObject.getName(), groupType); }
public boolean hasPassword(User user) throws IdentityException { checkNotNullArgument(user, "User"); return getRepository().getSupportedFeatures().isCredentialSupported(createIdentityObject(user).getIdentityType(), PasswordCredential.TYPE); }
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 AttributeDescription getAttributeDescription(IdentityType identityType, String name) { checkNotNullArgument(identityType, "IdentityType"); checkNotNullArgument(name, "Attribute name"); Map<String, IdentityObjectAttributeMetaData> mdMap = getRepository().getAttributesMetaData(getInvocationContext(), createIdentityObject(identityType).getIdentityType()); if (mdMap != null && mdMap.containsKey(name)) { IdentityObjectAttributeMetaData attributeMD = mdMap.get(name); if (attributeMD instanceof AttributeDescription) { return (AttributeDescription)attributeMD; } else { return new IdentityObjectAttributeMetaDataImpl(attributeMD); } } return null; }
public Set<String> getSupportedAttributeNames(IdentityType identityType) throws IdentityException { checkNotNullArgument(identityType, "IdentityType"); return getRepository().getSupportedAttributeNames(getInvocationContext(), createIdentityObject(identityType).getIdentityType()); }
public Collection<Group> findRelatedGroups(User user, String groupType, IdentitySearchCriteria criteria) throws IdentityException { checkNotNullArgument(user, "User"); List<Group> identities = new LinkedList<Group>(); Collection<IdentityObject> ios = getRepository().findIdentityObject(getInvocationContext(), createIdentityObject(user), null, 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 Collection<Group> findAssociatedGroups(User user, String groupType, IdentitySearchCriteria criteria) throws IdentityException { checkNotNullArgument(user, "User"); //checkNotNullArgument(groupType, "Group type"); List<Group> identities = new LinkedList<Group>(); IdentityObjectType iot = groupType != null ? getIdentityObjectType(groupType) : null; Collection<IdentityObject> ios = getRepository().findIdentityObject(getInvocationContext(), createIdentityObject(user), MEMBER, false, convertSearchControls(criteria)); for (IdentityObject io : ios) { if (iot == null || io.getIdentityType().getName().equals(iot.getName())) { identities.add(createGroup(io)); } } return identities; }
public Collection<User> findRelatedUsers(Group group, IdentitySearchCriteria criteria) throws IdentityException { checkNotNullArgument(group, "Group"); List<User> identities = new LinkedList<User>(); Collection<IdentityObject> ios = getRepository().findIdentityObject(getInvocationContext(), createIdentityObject(group), null, true, convertSearchControls(criteria)); String userTypeName = getUserObjectType().getName(); for (IdentityObject io : ios) { if (io.getIdentityType().getName().equals(userTypeName)) { User user = createUser(io); if (!identities.contains(user)) { identities.add(createUser(io)); } } } return identities; }
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 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); }
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); }