@Override protected DirContextOperations doAuthentication( UsernamePasswordAuthenticationToken authentication) { try { return getAuthenticator().authenticate(authentication); } catch (PasswordPolicyException ppe) { // The only reason a ppolicy exception can occur during a bind is that the // account is locked. throw new LockedException(this.messages.getMessage( ppe.getStatus().getErrorCode(), ppe.getStatus().getDefaultMessage())); } catch (UsernameNotFoundException notFound) { if (this.hideUserNotFoundExceptions) { throw new BadCredentialsException(this.messages.getMessage( "LdapAuthenticationProvider.badCredentials", "Bad credentials")); } else { throw notFound; } } catch (NamingException ldapAccessFailure) { throw new InternalAuthenticationServiceException( ldapAccessFailure.getMessage(), ldapAccessFailure); } }
/** * Convenience method to get the explanation associated with this exception, * if the root cause was an instance of {@link javax.naming.NamingException}. * * @return a detail string explaining more about this exception if the root * cause is an instance of javax.naming.NamingException, or * <code>null</code> if there is no detail message for this * exception */ public String getExplanation() { if (getCause() instanceof javax.naming.NamingException) { return ((javax.naming.NamingException) getCause()).getExplanation(); } return null; }
/** * Checks if the <tt>resolvedObj</tt> of the causing exception is * suspected to be non-serializable, and if so temporarily nulls it before * calling the default serialization mechanism. * * @param stream * the stream onto which this object is serialized * @throws IOException * if there is an error writing this object to the stream */ private void writeObject(ObjectOutputStream stream) throws IOException { Object resolvedObj = getResolvedObj(); boolean serializable = resolvedObj instanceof Serializable; if (resolvedObj != null && !serializable) { // the cause is of this type, since resolvedObj is not null javax.naming.NamingException namingException = (javax.naming.NamingException) getCause(); namingException.setResolvedObj(null); try { stream.defaultWriteObject(); } finally { namingException.setResolvedObj(resolvedObj); } } else { stream.defaultWriteObject(); } } }
public void updatePassword(String uid, String passwordActuel, String newPassword) throws ToutaticeAnnuaireException { Name dn = buildDn(uid); try { /*LdapContextSource contextSourceAnnuaireAcademiqueLecture = new LdapContextSource(); contextSourceAnnuaireAcademiqueLecture.setUrl(url); contextSourceAnnuaireAcademiqueLecture.setBase(baseDN); contextSourceAnnuaireAcademiqueLecture.setUserDn(this.buildFullDn(uid)); contextSourceAnnuaireAcademiqueLecture.setPassword(passwordActuel); contextSourceAnnuaireAcademiqueLecture.setPooled(true); try { contextSourceAnnuaireAcademiqueLecture.afterPropertiesSet(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } LdapTemplate ldapTemplateAnnuaireAcademiqueEcriture = new LdapTemplate(contextSourceAnnuaireAcademiqueLecture); */ Attribute attr = new BasicAttribute(password, newPassword); ModificationItem item = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, attr); ldapTemplateAnnuaireAcademiqueEcriture.modifyAttributes(dn, new ModificationItem[] {item}); loggerModif.info("La personne "+uid+" a changé son mot de passe"); } catch (NamingException e) { logger.error("Impossible de mettre le mot de passe à jour sur l'annuaire académique pour l'utilisateur "+uid); logger.error(e.toString()); throw new ToutaticeAnnuaireException("Erreur lors de la mise à jour du mot de passe académique pour la personne "+uid); } }
@Test public void testNamingExceptionWithNonSerializableResolvedObj() throws Exception { javax.naming.NameAlreadyBoundException wrappedException = new javax.naming.NameAlreadyBoundException( "some error"); wrappedException.setResolvedObj(new InitialDirContext()); NamingException exception = new NameAlreadyBoundException( wrappedException); writeToStream(exception); NamingException deSerializedException = readFromStream(); assertNotNull( "Original exception resolvedObj after serialization should not be null", exception.getResolvedObj()); assertNull("De-serialized exception resolvedObj should be null", deSerializedException.getResolvedObj()); }
public void create(Person p) throws ToutaticeAnnuaireException { Name dn = buildDn(p); try { Attributes attr = buildAttributes(p); ldapTemplateEcriture.bind(dn, null, attr); } catch (NamingException e) { logger.error("Impossible de créér la personne "+ p.getUid()); e.printStackTrace(); throw new ToutaticeAnnuaireException("Erreur lors de la création de la personne "+p.getUid()+" dans l'annuaire"); } }
/** * Checks if the <tt>resolvedObj</tt> of the causing exception is * suspected to be non-serializable, and if so temporarily nulls it before * calling the default serialization mechanism. * * @param stream * the stream onto which this object is serialized * @throws IOException * if there is an error writing this object to the stream */ private void writeObject(ObjectOutputStream stream) throws IOException { Object resolvedObj = getResolvedObj(); boolean serializable = resolvedObj instanceof Serializable; if (resolvedObj != null && !serializable) { // the cause is of this type, since resolvedObj is not null javax.naming.NamingException namingException = (javax.naming.NamingException) getCause(); namingException.setResolvedObj(null); try { stream.defaultWriteObject(); } finally { namingException.setResolvedObj(resolvedObj); } } else { stream.defaultWriteObject(); } } }
public void updatePassword(String uid, String passwordActuel, String newPassword) throws ToutaticeAnnuaireException { Name dn = buildDn(uid); try { /*LdapContextSource contextSourceAnnuaireAcademiqueLecture = new LdapContextSource(); contextSourceAnnuaireAcademiqueLecture.setUrl(url); contextSourceAnnuaireAcademiqueLecture.setBase(baseDN); contextSourceAnnuaireAcademiqueLecture.setUserDn(this.buildFullDn(uid)); contextSourceAnnuaireAcademiqueLecture.setPassword(passwordActuel); contextSourceAnnuaireAcademiqueLecture.setPooled(true); try { contextSourceAnnuaireAcademiqueLecture.afterPropertiesSet(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } LdapTemplate ldapTemplateAnnuaireAcademiqueEcriture = new LdapTemplate(contextSourceAnnuaireAcademiqueLecture); */ Attribute attr = new BasicAttribute(password, newPassword); ModificationItem item = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, attr); ldapTemplateAnnuaireAcademiqueEcriture.modifyAttributes(dn, new ModificationItem[] {item}); loggerModif.info("La personne "+uid+" a changé son mot de passe"); } catch (NamingException e) { logger.error("Impossible de mettre le mot de passe à jour sur l'annuaire académique pour l'utilisateur "+uid); logger.error(e.toString()); throw new ToutaticeAnnuaireException("Erreur lors de la mise à jour du mot de passe académique pour la personne "+uid); } }
public void create(Profil profil) throws ToutaticeAnnuaireException { Name dn = buildDn(profil); try { Attributes attr = buildAttributes(profil); ldapTemplateEcriture.bind(dn, null, attr); } catch (NamingException e) { logger.error("Impossible de créér le profil "+ profil.getCn()); e.printStackTrace(); throw new ToutaticeAnnuaireException("Erreur lors de la création du profil "+profil.getCn()+" dans l'annuaire"); } for(String dnMembre:profil.getListeMembers()){ personDao.ajoutProfilViaMajProfil(dnMembre, profil.getDn()); } }
public void getAllGroups(LdapTemplate ldapTemplate , String groupBaseDnPattern) { try { groupInfo =new ArrayList<>(); LdapQuery query = query().base(groupBaseDnPattern); groupInfo = ldapTemplate.list(query.base()); } catch(NamingException e) { log.error("Unable to Groups from LDAP " + e.getMessage()); throw new RuntimeException(e); } }
/** * Checks if the <tt>resolvedObj</tt> of the causing exception is * suspected to be non-serializable, and if so temporarily nulls it before * calling the default serialization mechanism. * * @param stream * the stream onto which this object is serialized * @throws IOException * if there is an error writing this object to the stream */ private void writeObject(ObjectOutputStream stream) throws IOException { Object resolvedObj = getResolvedObj(); boolean serializable = resolvedObj instanceof Serializable; if (resolvedObj != null && !serializable) { // the cause is of this type, since resolvedObj is not null javax.naming.NamingException namingException = (javax.naming.NamingException) getCause(); namingException.setResolvedObj(null); try { stream.defaultWriteObject(); } finally { namingException.setResolvedObj(resolvedObj); } } else { stream.defaultWriteObject(); } } }
/** * Convenience method to get the resolved object associated with this * exception, if the root cause was an instance of * {@link javax.naming.NamingException}. * * @return the object that was resolved so far if the root cause is an * instance of javax.naming.NamingException, or <code>null</code> * if the resolved object field has not been set */ public Object getResolvedObj() { if (getCause() instanceof javax.naming.NamingException) { return ((javax.naming.NamingException) getCause()).getResolvedObj(); } return null; }
} catch (final NamingException e) { logger.error("Impossible de mettre le mot de passe à jour sur l'annuaire académique pour l'utilisateur "+uid); logger.error(e.toString()); throw new AnnuaireAcademiqueException("Erreur lors de la mise à jour du mot de passe académique pour la personne " + uid);
public void remove(Entity entity) throws SecurityException { String internalId = getInternalId(entity, false); if (internalId == null) { // not found return; } ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); ldapTemplate.unbind(getRelativeDN(internalId)); } catch (NameNotFoundException e) { // ignore } catch (NamingException e) { throw new SecurityException(SecurityException.UNEXPECTED.create(getClass().getName(), "remove", e.getMessage()), e); } finally { Thread.currentThread().setContextClassLoader(currentClassLoader); } }
/** * Checks if the <tt>resolvedObj</tt> of the causing exception is * suspected to be non-serializable, and if so temporarily nulls it before * calling the default serialization mechanism. * * @param stream * the stream onto which this object is serialized * @throws IOException * if there is an error writing this object to the stream */ private void writeObject(ObjectOutputStream stream) throws IOException { Object resolvedObj = getResolvedObj(); boolean serializable = resolvedObj instanceof Serializable; if (resolvedObj != null && !serializable) { // the cause is of this type, since resolvedObj is not null javax.naming.NamingException namingException = (javax.naming.NamingException) getCause(); namingException.setResolvedObj(null); try { stream.defaultWriteObject(); } finally { namingException.setResolvedObj(resolvedObj); } } else { stream.defaultWriteObject(); } } }
/** * Convenience method to get the resolved object associated with this * exception, if the root cause was an instance of * {@link javax.naming.NamingException}. * * @return the object that was resolved so far if the root cause is an * instance of javax.naming.NamingException, or <code>null</code> * if the resolved object field has not been set */ public Object getResolvedObj() { if (getCause() instanceof javax.naming.NamingException) { return ((javax.naming.NamingException) getCause()).getResolvedObj(); } return null; }
} catch (final NamingException e) { logger.error("Impossible de mettre le mot de passe à jour sur l'annuaire académique pour l'utilisateur "+uid); logger.error(e.toString()); throw new AnnuaireAcademiqueException("Erreur lors de la mise à jour du mot de passe académique pour la personne " + uid);
public void getEntities(Filter filter, EntitySearchResultHandler handler) throws SecurityException { Validate.notNull(handler, "EntitySearchResultHandler parameter must not be null"); String sf = createSearchFilter(filter); SearchControls sc = getSearchControls(SearchControls.SUBTREE_SCOPE, true, configuration.getEntityAttributeNames()); handler.setEntityFactory(getEntityFactory()); PagedSearchExecutor pse = new PagedSearchExecutor(configuration.getSearchDN(), sf, sc, handler, searchPageSize); ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); ldapTemplate.search(pse,pse); } catch (NamingException e) { throw new SecurityException(SecurityException.UNEXPECTED.create(getClass().getName(), "getEntities", e.getMessage()), e); } finally { Thread.currentThread().setContextClassLoader(currentClassLoader); handler.setEntityFactory(null); } }
/** * Convenience method to get the explanation associated with this exception, * if the root cause was an instance of {@link javax.naming.NamingException}. * * @return a detail string explaining more about this exception if the root * cause is an instance of javax.naming.NamingException, or * <code>null</code> if there is no detail message for this * exception */ public String getExplanation() { if (getCause() instanceof javax.naming.NamingException) { return ((javax.naming.NamingException) getCause()).getExplanation(); } return null; }
public void addPersonSmdp(Person p) throws ToutaticeAnnuaireException { try { Name dn = buildDn(p); Attribute attr = new BasicAttribute(idsurcharge,p.getIdSurcharge()); ModificationItem item = new ModificationItem(DirContext.ADD_ATTRIBUTE, attr); ldapTemplateEcriture.modifyAttributes(dn, new ModificationItem[] {item}); } catch(NamingException e) { logger.error("Impossible de mettre à jour l'attribut "+idsurcharge+" pour l'utilisateur "+p.getCn()); logger.error(e.toString()); throw new ToutaticeAnnuaireException("Erreur lors de la surcharge sur la personne "+p.getCn()+". Impossible de mettre à jour l'attribut personSmdp"); } }