private LdapContext getLDAPContext(IdentityStoreInvocationContext ctx) throws IdentityException { LdapContext ldapContext = null; try { ldapContext = (LdapContext)ctx.getIdentityStoreSession().getSessionContext(); } catch (Exception e) { if (log.isLoggable(Level.FINER)) { log.finer("Failed to obtain LDAP connection!"); } throw new IdentityException("Could not obtain LDAP connection: ", e); } if (ldapContext == null) { if (log.isLoggable(Level.FINER)) { log.finer("Failed to obtain LDAP connection!"); } throw new IdentityException("IllegalState: - Could not obtain LDAP connection"); } return ldapContext; }
private String readPasswordFromPicketLink(User user) throws Exception { PicketLinkIDMOrganizationServiceImpl orgService = (PicketLinkIDMOrganizationServiceImpl) organizationService; if (orgService.getConfiguration().isPasswordAsAttribute()) { return user.getPassword(); } else { IdentitySession identitySession = picketLinkIDMService.getIdentitySession(); IdentityStoreInvocationContext identitySessionContext = ((IdentitySessionImpl) identitySession).getSessionContext() .resolveStoreInvocationContext(); Session session = ((Session) ((RepositoryIdentityStoreSessionImpl) identitySessionContext.getIdentityStoreSession()) .getIdentityStoreSession("HibernateStore").getSessionContext()); HibernateIdentityObjectType hibernateIdentityObjectType = (HibernateIdentityObjectType) session .createCriteria(HibernateIdentityObjectType.class).add(Restrictions.eq("name", "USER")).uniqueResult(); HibernateIdentityObject hibernateUserObject = (HibernateIdentityObject) session .createCriteria(HibernateIdentityObject.class).add(Restrictions.eq("name", user.getUserName())) .add(Restrictions.eq("identityType", hibernateIdentityObjectType)).uniqueResult(); HibernateIdentityObjectCredential hibernateCredential = (HibernateIdentityObjectCredential) session .createCriteria(HibernateIdentityObjectCredential.class).createAlias("type", "t") .add(Restrictions.eq("t.name", PasswordCredential.TYPE.getName())) .add(Restrictions.eq("identityObject", hibernateUserObject)).setCacheable(true).uniqueResult(); if (hibernateCredential != null) { return hibernateCredential.getTextValue(); } else { return ""; } } }
DirContext ctx = (DirContext)createIdentityStoreSession().getSessionContext();