This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 92c0ff5912d0c59300461dee0e72646027a42321 Author: Raphael Ouazana <raphael.ouaz...@linagora.com> AuthorDate: Thu Nov 7 15:34:18 2019 +0100 JAMES-2949 Remove deprecate UsersFileRepository, based on raw Java serialization mechanism --- .../james/user/api/JamesUsersRepository.java | 54 ---- .../james/user/file/UsersFileRepository.java | 236 ---------------- .../james/user/file/UsersFileRepositoryTest.java | 119 -------- .../user/lib/AbstractJamesUsersRepository.java | 303 --------------------- 4 files changed, 712 deletions(-) diff --git a/server/data/data-api/src/main/java/org/apache/james/user/api/JamesUsersRepository.java b/server/data/data-api/src/main/java/org/apache/james/user/api/JamesUsersRepository.java deleted file mode 100644 index 2aca89f..0000000 --- a/server/data/data-api/src/main/java/org/apache/james/user/api/JamesUsersRepository.java +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.user.api; - -import org.apache.james.rrt.api.RecipientRewriteTable; - -/** - * @deprecated Use {@link UsersRepository} - */ -@Deprecated -public interface JamesUsersRepository extends UsersRepository, RecipientRewriteTable { - - /** - * enable/disable aliases in case of JamesUsers - * - * @param enableAliases - * enable - */ - void setEnableAliases(boolean enableAliases); - - /** - * enable/disable aliases in case of JamesUsers - * - * @param enableForwarding - * enable - */ - void setEnableForwarding(boolean enableForwarding); - - /** - * set case sensitive/insensitive operations - * - * @param ignoreCase - * ignore - */ - void setIgnoreCase(boolean ignoreCase); - -} diff --git a/server/data/data-file/src/main/java/org/apache/james/user/file/UsersFileRepository.java b/server/data/data-file/src/main/java/org/apache/james/user/file/UsersFileRepository.java deleted file mode 100644 index 77f97d2..0000000 --- a/server/data/data-file/src/main/java/org/apache/james/user/file/UsersFileRepository.java +++ /dev/null @@ -1,236 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.user.file; - -import java.util.Iterator; - -import javax.annotation.PostConstruct; -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.apache.commons.configuration2.BaseHierarchicalConfiguration; -import org.apache.commons.configuration2.HierarchicalConfiguration; -import org.apache.commons.configuration2.ex.ConfigurationException; -import org.apache.commons.configuration2.tree.ImmutableNode; -import org.apache.james.filesystem.api.FileSystem; -import org.apache.james.repository.file.FilePersistentObjectRepository; -import org.apache.james.user.api.UsersRepositoryException; -import org.apache.james.user.api.model.User; -import org.apache.james.user.lib.AbstractJamesUsersRepository; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * <p> - * Implementation of a Repository to store users on the File System. - * </p> - * - * <p> - * Requires a configuration element in the .conf.xml file of the form: - * - * <pre> - * <repository destinationURL="file://path-to-root-dir-for-repository" - * type="USERS" - * model="SYNCHRONOUS"/> - * </pre> - * - * Requires a logger called UsersRepository. - * </p> - */ -@Deprecated -@Singleton -public class UsersFileRepository extends AbstractJamesUsersRepository { - private static final Logger LOGGER = LoggerFactory.getLogger(UsersFileRepository.class); - - private FilePersistentObjectRepository objectRepository; - - /** - * The destination URL used to define the repository. - */ - private String destination; - - private FileSystem fileSystem; - - @Inject - public void setFileSystem(FileSystem fileSystem) { - this.fileSystem = fileSystem; - } - - @Override - protected void doConfigure(HierarchicalConfiguration<ImmutableNode> configuration) throws ConfigurationException { - super.doConfigure(configuration); - destination = configuration.getString("destination.[@URL]"); - - String urlSeparator = "/"; - if (!destination.endsWith(urlSeparator)) { - destination += urlSeparator; - } - } - - @PostConstruct - public void init() throws Exception { - try { - // TODO Check how to remove this! - // prepare Configurations for object and stream repositories - HierarchicalConfiguration<ImmutableNode> objectConfiguration = new BaseHierarchicalConfiguration(); - - objectConfiguration.addProperty("[@destinationURL]", destination); - - objectRepository = new FilePersistentObjectRepository(); - objectRepository.setFileSystem(fileSystem); - objectRepository.configure(objectConfiguration); - objectRepository.init(); - LOGGER.debug("{} created in {}", getClass().getName(), destination); - } catch (Exception e) { - LOGGER.error("Failed to initialize repository", e); - throw e; - } - } - - @Override - public Iterator<String> list() { - return objectRepository.list(); - } - - @Override - protected void doAddUser(User user) throws UsersRepositoryException { - if (contains(user.getUserName())) { - throw new UsersRepositoryException(user.getUserName() + " already exists."); - } - try { - objectRepository.put(user.getUserName(), user); - } catch (Exception e) { - throw new UsersRepositoryException("Exception caught while storing user", e); - } - } - - @Override - public synchronized User getUserByName(String name) throws UsersRepositoryException { - if (ignoreCase) { - name = getRealName(name); - if (name == null) { - return null; - } - } - if (contains(name)) { - try { - return (User) objectRepository.get(name); - } catch (Exception e) { - throw new UsersRepositoryException("Exception while retrieving user", e); - } - } else { - return null; - } - } - - /** - * Return the real name, given the ignoreCase boolean parameter - * - * @param name - * @param ignoreCase - * @return The real name - * @throws UsersRepositoryException - */ - private String getRealName(String name, boolean ignoreCase) { - if (ignoreCase) { - Iterator<String> it = list(); - while (it.hasNext()) { - String temp = it.next(); - if (name.equalsIgnoreCase(temp)) { - return temp; - } - } - return null; - } else { - return objectRepository.containsKey(name) ? name : null; - } - } - - /** - * Return the real name, given the ignoreCase boolean parameter - * - * @param name - * @return The real name - * @throws UsersRepositoryException - */ - private String getRealName(String name) throws UsersRepositoryException { - return getRealName(name, ignoreCase); - } - - @Override - protected void doUpdateUser(User user) throws UsersRepositoryException { - try { - objectRepository.put(user.getUserName(), user); - } catch (Exception e) { - throw new UsersRepositoryException("Exception caught while storing user", e); - } - } - - @Override - public synchronized void removeUser(String name) throws UsersRepositoryException { - if (!objectRepository.remove(name)) { - throw new UsersRepositoryException("User " + name + " does not exist"); - } - } - - @Override - public boolean contains(String name) throws UsersRepositoryException { - if (ignoreCase) { - return containsCaseInsensitive(name); - } else { - return objectRepository.containsKey(name); - } - } - - @Deprecated - private boolean containsCaseInsensitive(String name) { - Iterator<String> it = list(); - while (it.hasNext()) { - if (name.equalsIgnoreCase(it.next())) { - return true; - } - } - return false; - } - - @Override - public boolean test(String name, String password) throws UsersRepositoryException { - User user; - try { - user = getUserByName(name); - if (user == null) { - return false; - } - } catch (Exception e) { - throw new RuntimeException("Exception retrieving User", e); - } - return user.verifyPassword(password); - } - - @Override - public int countUsers() throws UsersRepositoryException { - int count = 0; - for (Iterator<String> it = list(); it.hasNext(); it.next()) { - count++; - } - return count; - } - -} diff --git a/server/data/data-file/src/test/java/org/apache/james/user/file/UsersFileRepositoryTest.java b/server/data/data-file/src/test/java/org/apache/james/user/file/UsersFileRepositoryTest.java deleted file mode 100644 index ea03978..0000000 --- a/server/data/data-file/src/test/java/org/apache/james/user/file/UsersFileRepositoryTest.java +++ /dev/null @@ -1,119 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.user.file; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.util.Iterator; - -import org.apache.commons.configuration2.BaseHierarchicalConfiguration; -import org.apache.commons.io.FileUtils; -import org.apache.james.filesystem.api.FileSystem; -import org.apache.james.lifecycle.api.LifecycleUtil; -import org.apache.james.user.api.UsersRepositoryException; -import org.apache.james.user.lib.AbstractUsersRepository; -import org.apache.james.user.lib.AbstractUsersRepositoryTest; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -/** - * Test basic behaviors of UsersFileRepository - */ -public class UsersFileRepositoryTest extends AbstractUsersRepositoryTest { - - private static final String TARGET_REPOSITORY_FOLDER = "target/var/users"; - private File targetRepositoryFolder; - - @Before - @Override - public void setUp() throws Exception { - super.setUp(); - targetRepositoryFolder = new File(TARGET_REPOSITORY_FOLDER); - this.usersRepository = getUsersRepository(); - } - - @Override - @After - public void tearDown() throws IOException { - FileUtils.forceDelete(targetRepositoryFolder); - } - - @SuppressWarnings("deprecation") - @Override - protected AbstractUsersRepository getUsersRepository() throws Exception { - FileSystem fs = new FileSystem() { - - @Override - public File getBasedir() throws FileNotFoundException { - return new File("."); - } - - @Override - public InputStream getResource(String url) throws IOException { - return new FileInputStream(getFile(url)); - } - - @Override - public File getFile(String fileURL) throws FileNotFoundException { - return new File(fileURL.substring(FileSystem.FILE_PROTOCOL.length())); - } - - }; - - BaseHierarchicalConfiguration configuration = new BaseHierarchicalConfiguration(); - configuration.addProperty("destination.[@URL]", "file://target/var/users"); - // Configure with ignoreCase = false, we need some more work to support true - configuration.addProperty("ignoreCase", "false"); - - UsersFileRepository res = new UsersFileRepository(); - - res.setFileSystem(fs); - res.configure(configuration); - res.init(); - return res; - } - - @Override - @Ignore - @Test - public void addUserShouldThrowWhenSameUsernameWithDifferentCase() throws UsersRepositoryException { - } - - @Override - protected void disposeUsersRepository() throws UsersRepositoryException { - if (this.usersRepository != null) { - Iterator<String> i = this.usersRepository.list(); - while (i.hasNext()) { - this.usersRepository.removeUser(i.next()); - } - LifecycleUtil.dispose(this.usersRepository); - } - } - - @Ignore - @Override - public void testShouldReturnTrueWhenAUserHasACorrectPasswordAndOtherCaseInDomain() throws Exception { - } -} diff --git a/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java b/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java deleted file mode 100644 index 3eee4fb..0000000 --- a/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java +++ /dev/null @@ -1,303 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.user.lib; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.apache.commons.configuration2.HierarchicalConfiguration; -import org.apache.commons.configuration2.ex.ConfigurationException; -import org.apache.commons.configuration2.tree.ImmutableNode; -import org.apache.james.core.Domain; -import org.apache.james.core.Username; -import org.apache.james.rrt.api.RecipientRewriteTable; -import org.apache.james.rrt.api.RecipientRewriteTableException; -import org.apache.james.rrt.lib.Mapping; -import org.apache.james.rrt.lib.MappingSource; -import org.apache.james.rrt.lib.Mappings; -import org.apache.james.rrt.lib.MappingsImpl; -import org.apache.james.rrt.lib.MappingsImpl.Builder; -import org.apache.james.user.api.JamesUsersRepository; -import org.apache.james.user.api.UsersRepository; -import org.apache.james.user.api.UsersRepositoryException; -import org.apache.james.user.api.model.JamesUser; -import org.apache.james.user.api.model.User; -import org.apache.james.user.lib.model.DefaultJamesUser; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * A partial implementation of a Repository to store users. - * <p> - * This implements common functionality found in different UsersRespository - * implementations, and makes it easier to create new User repositories. - * </p> - * - * @deprecated Please implement {@link UsersRepository} - */ -@Deprecated -public abstract class AbstractJamesUsersRepository extends AbstractUsersRepository implements JamesUsersRepository, RecipientRewriteTable { - private static final Logger LOGGER = LoggerFactory.getLogger(AbstractJamesUsersRepository.class); - - /** - * Ignore case in usernames - */ - protected boolean ignoreCase; - - /** - * Enable Aliases frmo JamesUser - */ - protected boolean enableAliases; - - /** - * Wether to enable forwarding for JamesUser or not - */ - protected boolean enableForwarding; - - @Override - public void configure(HierarchicalConfiguration<ImmutableNode> configuration) throws ConfigurationException { - setIgnoreCase(configuration.getBoolean("ignoreCase", false)); - setEnableAliases(configuration.getBoolean("enableAliases", false)); - setEnableForwarding(configuration.getBoolean("enableForwarding", false)); - super.configure(configuration); - } - - /** - * Adds a user to the underlying Repository. The user name must not clash - * with an existing user. - * - * @param user - * the user to add - */ - protected abstract void doAddUser(User user) throws UsersRepositoryException; - - /** - * Updates a user record to match the supplied User. - * - * @param user - * the user to update - */ - protected abstract void doUpdateUser(User user) throws UsersRepositoryException; - - @Override - protected void doAddUser(String username, String password) throws UsersRepositoryException { - User newbie = new DefaultJamesUser(username, "SHA"); - newbie.setPassword(password); - doAddUser(newbie); - } - - /** - * Update the repository with the specified user object. A user object with - * this username must already exist. - * - * @param user - * the user to be updated - * @throws UsersRepositoryException - */ - @Override - public void updateUser(User user) throws UsersRepositoryException { - // Return false if it's not found. - if (!contains(user.getUserName())) { - throw new UsersRepositoryException("User " + user.getUserName() + " does not exist"); - } else { - doUpdateUser(user); - } - } - - @Override - public Mappings getResolvedMappings(String username, Domain domain) throws ErrorMappingException, RecipientRewriteTableException { - Builder mappingsBuilder = MappingsImpl.builder(); - try { - User user = getUserByName(username); - - if (user instanceof JamesUser) { - JamesUser jUser = (JamesUser) user; - - if (enableAliases && jUser.getAliasing()) { - String alias = jUser.getAlias(); - if (alias != null) { - mappingsBuilder.add(alias + "@" + domain.asString()); - } - } - - if (enableForwarding && jUser.getForwarding()) { - String forward; - if (jUser.getForwardingDestination() != null && ((forward = jUser.getForwardingDestination().toString()) != null)) { - mappingsBuilder.add(forward); - } else { - String errorBuffer = "Forwarding was enabled for " + username + " but no forwarding address was set for this account."; - LOGGER.error(errorBuffer); - } - } - } - } catch (UsersRepositoryException e) { - throw new RecipientRewriteTableException("Unable to lookup forwards/aliases", e); - } - Mappings mappings = mappingsBuilder.build(); - if (mappings.size() == 0) { - return null; - } else { - return mappings; - } - } - - @Override - public void setEnableAliases(boolean enableAliases) { - this.enableAliases = enableAliases; - } - - @Override - public void setEnableForwarding(boolean enableForwarding) { - this.enableForwarding = enableForwarding; - } - - @Override - public void setIgnoreCase(boolean ignoreCase) { - this.ignoreCase = ignoreCase; - } - - @Override - public Map<MappingSource, Mappings> getAllMappings() throws RecipientRewriteTableException { - Map<MappingSource, Mappings> mappings = new HashMap<>(); - if (enableAliases || enableForwarding) { - try { - Iterator<String> users = list(); - while (users.hasNext()) { - String user = users.next(); - int index = user.indexOf("@"); - String username; - Domain domain; - if (index != -1) { - username = user.substring(0, index); - domain = Domain.of(user.substring(index + 1, user.length())); - } else { - username = user; - domain = Domain.LOCALHOST; - } - try { - MappingSource source = MappingSource.fromUser(Username.of(user)); - mappings.put(source, getResolvedMappings(username, domain)); - } catch (ErrorMappingException e) { - // shold never happen here - } - } - } catch (UsersRepositoryException e) { - throw new RecipientRewriteTableException("Unable to access forwards/aliases", e); - } - } - - return mappings; - } - - @Override - public Mappings getStoredMappings(MappingSource source) { - return MappingsImpl.empty(); - } - - @Override - public void addRegexMapping(MappingSource source, String regex) throws RecipientRewriteTableException { - throw new RecipientRewriteTableException("Read-Only RecipientRewriteTable"); - } - - @Override - public void removeRegexMapping(MappingSource source, String regex) throws RecipientRewriteTableException { - throw new RecipientRewriteTableException("Read-Only RecipientRewriteTable"); - - } - - @Override - public void addAddressMapping(MappingSource source, String address) throws RecipientRewriteTableException { - throw new RecipientRewriteTableException("Read-Only RecipientRewriteTable"); - - } - - @Override - public void removeAddressMapping(MappingSource source, String address) throws RecipientRewriteTableException { - throw new RecipientRewriteTableException("Read-Only RecipientRewriteTable"); - - } - - @Override - public void addErrorMapping(MappingSource source, String error) throws RecipientRewriteTableException { - throw new RecipientRewriteTableException("Read-Only RecipientRewriteTable"); - - } - - @Override - public void removeErrorMapping(MappingSource source, String error) throws RecipientRewriteTableException { - throw new RecipientRewriteTableException("Read-Only RecipientRewriteTable"); - - } - - @Override - public void addMapping(MappingSource source, Mapping mapping) throws RecipientRewriteTableException { - throw new RecipientRewriteTableException("Read-Only RecipientRewriteTable"); - - } - - @Override - public void removeMapping(MappingSource source, Mapping mapping) throws RecipientRewriteTableException { - throw new RecipientRewriteTableException("Read-Only RecipientRewriteTable"); - - } - - @Override - public void addAliasDomainMapping(MappingSource source, Domain realDomain) throws RecipientRewriteTableException { - throw new RecipientRewriteTableException("Read-Only RecipientRewriteTable"); - - } - - @Override - public void removeAliasDomainMapping(MappingSource source, Domain realDomain) throws RecipientRewriteTableException { - throw new RecipientRewriteTableException("Read-Only RecipientRewriteTable"); - - } - - @Override - public void addForwardMapping(MappingSource source, String address) throws RecipientRewriteTableException { - throw new RecipientRewriteTableException("Read-Only RecipientRewriteTable"); - } - - @Override - public void removeForwardMapping(MappingSource source, String address) throws RecipientRewriteTableException { - throw new RecipientRewriteTableException("Read-Only RecipientRewriteTable"); - } - - @Override - public void addGroupMapping(MappingSource source, String address) throws RecipientRewriteTableException { - throw new RecipientRewriteTableException("Read-Only RecipientRewriteTable"); - } - - @Override - public void removeGroupMapping(MappingSource source, String address) throws RecipientRewriteTableException { - throw new RecipientRewriteTableException("Read-Only RecipientRewriteTable"); - } - - @Override - public void addAliasMapping(MappingSource source, String address) throws RecipientRewriteTableException { - throw new RecipientRewriteTableException("Read-Only RecipientRewriteTable"); - } - - @Override - public void removeAliasMapping(MappingSource source, String address) throws RecipientRewriteTableException { - throw new RecipientRewriteTableException("Read-Only RecipientRewriteTable"); - } -} --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org