public Object getObject(String name) throws IdentityException { Object o = registry.getRegistration(name); if (o == null) { throw new IdentityException("No such mapping in IdentityContext: " + name); } return o; }
public IdentityStoreSession createIdentityStoreSession() throws IdentityException { try { return new HibernateIdentityStoreSessionImpl(sessionFactory); } catch (Exception e) { throw new IdentityException("Failed to obtain Hibernate SessionFactory",e); } }
public void register(Object object, String name) throws IdentityException { if (!registry.register(name, object)) { throw new IdentityException("Cannot register object in IdentityContext with name: " + name); } if (log.isLoggable(Level.FINER)) log.finer("registering object: " + name + " ; " + object.getClass()); }
public IdentityObject findIdentityObject(IdentityStoreInvocationContext ctx, String id) throws IdentityException { if (id == null) { throw new IllegalArgumentException("id is null"); } HibernateIdentityObject hibernateObject; try { hibernateObject = (HibernateIdentityObject)getHibernateSession(ctx).get(HibernateIdentityObject.class, new Long(id)); } catch(Exception e) { throw new IdentityException("Cannot find IdentityObject with id: " + id, e); } return hibernateObject; }
protected Session getHibernateSession(IdentityStoreInvocationContext ctx) throws IdentityException { try { return ((Session)ctx.getIdentityStoreSession().getSessionContext()); } catch (Exception e) { throw new IdentityException("Cannot obtain Hibernate Session", e); } }
public void addRealm(Session hibernateSession, String realmName) throws IdentityException { try { HibernateRealm realm = new HibernateRealm(realmName); hibernateSession.persist(realm); } catch (Exception e) { throw new IdentityException("Failed to create store realm", e); } }
public Map<String, String> getRelationshipNameProperties(IdentityStoreInvocationContext ctx, String name) throws IdentityException, OperationNotSupportedException { if (name == null) { throw new IllegalArgumentException("name is null"); } Session hibernateSession = getHibernateSession(ctx); try { HibernateIdentityObjectRelationshipName hiorn = (HibernateIdentityObjectRelationshipName)hibernateSession.createCriteria(HibernateIdentityObjectRelationshipName.class) .add(Restrictions.eq("name", name)).add(Restrictions.eq("realm", getRealm(hibernateSession, ctx))).uniqueResult(); if (hiorn == null) { throw new IdentityException("Relationship name doesn't exist"); } return new HashMap<String, String>(hiorn.getProperties()); } catch (Exception e) { throw new IdentityException("Cannot get relationship name properties: " + name, e); } }
public void setRelationshipNameProperties(IdentityStoreInvocationContext ctx, String name, Map<String, String> properties) throws IdentityException, OperationNotSupportedException { if (name == null) { throw new IllegalArgumentException("name is null"); } Session hibernateSession = getHibernateSession(ctx); try { HibernateIdentityObjectRelationshipName hiorn = (HibernateIdentityObjectRelationshipName)hibernateSession.createCriteria(HibernateIdentityObjectRelationshipName.class) .add(Restrictions.eq("name", name)).add(Restrictions.eq("realm", getRealm(hibernateSession, ctx))).uniqueResult(); if (hiorn == null) { throw new IdentityException("Relationship name doesn't exist"); } hiorn.getProperties().putAll(properties); } catch (Exception e) { throw new IdentityException("Cannot set relationship name properties: " + name, e); } }
public String removeRelationshipName(IdentityStoreInvocationContext ctx, String name) throws IdentityException, OperationNotSupportedException { if (name == null) { throw new IllegalArgumentException("name is null"); } Session hibernateSession = getHibernateSession(ctx); try { HibernateIdentityObjectRelationshipName hiorn = (HibernateIdentityObjectRelationshipName)hibernateSession.createCriteria(HibernateIdentityObjectRelationshipName.class) .add(Restrictions.eq("name", name)).add(Restrictions.eq("realm", getRealm(hibernateSession, ctx))).uniqueResult(); if (hiorn == null) { throw new IdentityException("Relationship name doesn't exist"); } getHibernateSession(ctx).delete(hiorn); } catch (Exception e) { throw new IdentityException("Cannot create new relationship name: " + name, e); } return name; }
public void removeRelationshipNameProperties(IdentityStoreInvocationContext ctx, String name, Set<String> properties) throws IdentityException, OperationNotSupportedException { if (name == null) { throw new IllegalArgumentException("name is null"); } Session hibernateSession = getHibernateSession(ctx); try { HibernateIdentityObjectRelationshipName hiorn = (HibernateIdentityObjectRelationshipName)hibernateSession.createCriteria(HibernateIdentityObjectRelationshipName.class) .add(Restrictions.eq("name", name)).add(Restrictions.eq("realm", getRealm(hibernateSession, ctx))).uniqueResult(); if (hiorn == null) { throw new IdentityException("Relationship name doesn't exist"); } for (String property : properties) { hiorn.getProperties().remove(property); } } catch (Exception e) { throw new IdentityException("Cannot remove relationship name properties: " + name, e); } }
public IdentitySession createIdentitySession(String realmName) throws IdentityException { if (!sessionContextMap.containsKey(realmName)) { throw new IdentityException("Cannot find configured realm with a given name: " + realmName); } //IdentitySession session = new IdentitySessionImpl(realmName, repo, mapper); IdentitySessionConfigurationContext sessionConfigCtx = sessionContextMap.get(realmName); IdentitySession newSession = new IdentitySessionImpl(sessionConfigCtx.getRealmName(), sessionConfigCtx.getRepository(), sessionConfigCtx.getTypeMapper()); realmMap.put(realmName, newSession); return newSession; }
public IdentityStore getIdentityStore(IdentityObjectType identityObjectType) throws IdentityException { IdentityStore store = identityStoreMappings.get(identityObjectType.getName()); if (store == null) { String option = configurationContext.getRepositoryConfigurationMetaData().getOptionSingleValue(ALLOW_NOT_DEFINED_IDENTITY_OBJECT_TYPES_OPTION); if (option != null && option.equalsIgnoreCase("true")) { return defaultIdentityStore; } else { throw new IdentityException("IdentityObjectType not mapped in the configuration: " + identityObjectType); } } return store; }
private void checkIOType(IdentityObjectType iot) throws IdentityException { if (iot == null) { throw new IllegalArgumentException("IdentityObjectType is null"); } if (!getSupportedFeatures().isIdentityObjectTypeSupported(iot)) { if (!isAllowNotDefinedIdentityObjectTypes()) { throw new IdentityException("IdentityType not supported by this IdentityStore implementation: " + iot); } } }
public AttributeStore getAttributeStore(IdentityObjectType identityObjectType) throws IdentityException { AttributeStore store = attributeStoreMappings.get(identityObjectType.getName()); if (store == null) { String option = configurationContext.getRepositoryConfigurationMetaData().getOptionSingleValue(ALLOW_NOT_DEFINED_IDENTITY_OBJECT_TYPES_OPTION); if (option != null && option.equalsIgnoreCase("true")) { return defaultIdentityStore; } else { throw new IdentityException("IdentityObjectType not mapped in the configuration: " + identityObjectType); } } return store; }
private HibernateIdentityObjectCredentialType getHibernateIdentityObjectCredentialType(IdentityStoreInvocationContext ctx, IdentityObjectCredentialType credentialType) throws IdentityException { Session session = getHibernateSession(ctx); HibernateIdentityObjectCredentialType hibernateType = null; try { hibernateType = (HibernateIdentityObjectCredentialType)session. createCriteria(HibernateIdentityObjectCredentialType.class).add(Restrictions.eq("name", credentialType.getName())).uniqueResult(); } catch (HibernateException e) { throw new IdentityException("IdentityObjectCredentialType[ " + credentialType.getName() + "] not present in the store."); } return hibernateType; }
public String createRelationshipName(IdentityStoreInvocationContext ctx, String name) throws IdentityException, OperationNotSupportedException { if (name == null) { throw new IllegalArgumentException("name is null"); } Session hibernateSession = getHibernateSession(ctx); HibernateRealm realm = getRealm(hibernateSession, ctx); try { HibernateIdentityObjectRelationshipName hiorn = (HibernateIdentityObjectRelationshipName)hibernateSession.createCriteria(HibernateIdentityObjectRelationshipName.class) .add(Restrictions.eq("name", name)).add(Restrictions.eq("realm", realm)).uniqueResult(); if (hiorn != null) { throw new IdentityException("Relationship name already exists"); } hiorn = new HibernateIdentityObjectRelationshipName(name, realm); getHibernateSession(ctx).persist(hiorn); } catch (Exception e) { throw new IdentityException("Cannot create new relationship name: " + name, e); } return name; }
private HibernateIdentityObjectRelationshipType getHibernateIdentityObjectRelationshipType(IdentityStoreInvocationContext ctx, IdentityObjectRelationshipType iot) throws IdentityException { HibernateIdentityObjectRelationshipType relationshipType = null; Session hibernateSession = getHibernateSession(ctx); try { relationshipType = (HibernateIdentityObjectRelationshipType)hibernateSession. createQuery(HibernateIdentityObjectRelationshipType.findIdentityObjectRelationshipTypeByName) .setParameter("name", iot.getName()) .uniqueResult(); } catch (Exception e) { throw new IdentityException("IdentityObjectRelationshipType[ " + iot.getName() + "] not present in the store."); } return relationshipType; }
public IdentityObject findIdentityObjectByUniqueAttribute(IdentityStoreInvocationContext invocationCtx, IdentityObjectType identityObjectType, IdentityObjectAttribute attribute) throws IdentityException { if (attribute == null) { throw new IllegalArgumentException("attribute is null"); } checkIOType(identityObjectType); String attrMappedName = resolveAttributeStoreMapping(identityObjectType, attribute.getName()); HibernateIdentityObjectType hiot = getHibernateIdentityObjectType(invocationCtx, identityObjectType); Session session = getHibernateSession(invocationCtx); Query q = session.createQuery("select a from HibernateIdentityObjectTextAttribute a where a.identityObject.identityType = :identityType " + "and a.name like :attributeName and :value = any elements(a.values)"); Set attrValues = new HashSet(); attrValues.addAll(attribute.getValues()); List<HibernateIdentityObjectAttribute> attrs = (List<HibernateIdentityObjectAttribute>) q.setParameter("identityType", hiot) .setParameter("attributeName", attrMappedName) .setParameter("value", attribute.getValue()).list(); if (attrs.size() == 0) { return null; } if (attrs.size() > 1) { throw new IdentityException("Illegal state - more than one IdentityObject with the same unique attribute value: " + attribute); } return attrs.get(0).getIdentityObject(); }
public Collection<RoleType> findRoleTypes(IdentitySearchCriteria criteria) throws IdentityException { try { Set<String> names = getRepository().getRelationshipNames(getInvocationContext(), convertSearchControls(criteria)); 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 void removeRoleType(String name) throws IdentityException { checkNotNullArgument(name, "RoleType name"); try { getRepository().removeRelationshipName(getInvocationContext(), name); } catch (OperationNotSupportedException e) { throw new IdentityException("Role management not supported"); } }