forked from linagora/james-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JAMES-2586 PostgresDelegationStore (linagora#1851)
- Loading branch information
1 parent
ddad6b5
commit decec6f
Showing
7 changed files
with
324 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...res-common/src/main/java/org/apache/james/modules/data/PostgresDelegationStoreModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/**************************************************************** | ||
* 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.modules.data; | ||
|
||
import org.apache.commons.configuration2.ex.ConfigurationException; | ||
import org.apache.james.backends.postgres.PostgresModule; | ||
import org.apache.james.server.core.configuration.ConfigurationProvider; | ||
import org.apache.james.user.api.DelegationStore; | ||
import org.apache.james.user.api.DelegationUsernameChangeTaskStep; | ||
import org.apache.james.user.api.UsernameChangeTaskStep; | ||
import org.apache.james.user.lib.UsersDAO; | ||
import org.apache.james.user.postgres.PostgresDelegationStore; | ||
import org.apache.james.user.postgres.PostgresUserModule; | ||
import org.apache.james.user.postgres.PostgresUsersDAO; | ||
import org.apache.james.user.postgres.PostgresUsersRepositoryConfiguration; | ||
|
||
import com.google.inject.AbstractModule; | ||
import com.google.inject.Provides; | ||
import com.google.inject.Scopes; | ||
import com.google.inject.Singleton; | ||
import com.google.inject.multibindings.Multibinder; | ||
|
||
public class PostgresDelegationStoreModule extends AbstractModule { | ||
@Override | ||
public void configure() { | ||
bind(DelegationStore.class).to(PostgresDelegationStore.class); | ||
bind(PostgresDelegationStore.UserExistencePredicate.class).to(PostgresDelegationStore.UserExistencePredicateImplementation.class); | ||
|
||
Multibinder.newSetBinder(binder(), UsernameChangeTaskStep.class) | ||
.addBinding().to(DelegationUsernameChangeTaskStep.class); | ||
|
||
bind(PostgresUsersDAO.class).in(Scopes.SINGLETON); | ||
bind(UsersDAO.class).to(PostgresUsersDAO.class); | ||
|
||
Multibinder<PostgresModule> postgresDataDefinitions = Multibinder.newSetBinder(binder(), PostgresModule.class); | ||
postgresDataDefinitions.addBinding().toInstance(PostgresUserModule.MODULE); | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
public PostgresUsersRepositoryConfiguration provideConfiguration(ConfigurationProvider configurationProvider) throws ConfigurationException { | ||
return PostgresUsersRepositoryConfiguration.from( | ||
configurationProvider.getConfiguration("usersrepository")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...a/data-postgres/src/main/java/org/apache/james/user/postgres/PostgresDelegationStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/**************************************************************** | ||
* 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.postgres; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.apache.james.core.Username; | ||
import org.apache.james.user.api.DelegationStore; | ||
import org.apache.james.user.api.UsersRepository; | ||
import org.reactivestreams.Publisher; | ||
|
||
import reactor.core.publisher.Mono; | ||
|
||
public class PostgresDelegationStore implements DelegationStore { | ||
public interface UserExistencePredicate { | ||
Mono<Boolean> exists(Username username); | ||
} | ||
|
||
public static class UserExistencePredicateImplementation implements UserExistencePredicate { | ||
private final UsersRepository usersRepository; | ||
|
||
@Inject | ||
UserExistencePredicateImplementation(UsersRepository usersRepository) { | ||
this.usersRepository = usersRepository; | ||
} | ||
|
||
@Override | ||
public Mono<Boolean> exists(Username username) { | ||
return Mono.from(usersRepository.containsReactive(username)); | ||
} | ||
} | ||
|
||
private PostgresUsersDAO postgresUsersDAO; | ||
private final UserExistencePredicate userExistencePredicate; | ||
|
||
@Inject | ||
public PostgresDelegationStore(PostgresUsersDAO postgresUsersDAO, UserExistencePredicate userExistencePredicate) { | ||
this.postgresUsersDAO = postgresUsersDAO; | ||
this.userExistencePredicate = userExistencePredicate; | ||
} | ||
|
||
@Override | ||
public Publisher<Username> authorizedUsers(Username baseUser) { | ||
return postgresUsersDAO.getAuthorizedUsers(baseUser); | ||
} | ||
|
||
@Override | ||
public Publisher<Void> clear(Username baseUser) { | ||
return postgresUsersDAO.removeAllAuthorizedUsers(baseUser); | ||
} | ||
|
||
@Override | ||
public Publisher<Void> addAuthorizedUser(Username baseUser, Username userWithAccess) { | ||
return userExistencePredicate.exists(userWithAccess) | ||
.flatMap(targetUserExists -> postgresUsersDAO.addAuthorizedUser(baseUser, userWithAccess, targetUserExists)); | ||
} | ||
|
||
@Override | ||
public Publisher<Void> removeAuthorizedUser(Username baseUser, Username userWithAccess) { | ||
return postgresUsersDAO.removeAuthorizedUser(baseUser, userWithAccess); | ||
} | ||
|
||
@Override | ||
public Publisher<Username> delegatedUsers(Username baseUser) { | ||
return postgresUsersDAO.getDelegatedToUsers(baseUser); | ||
} | ||
|
||
@Override | ||
public Publisher<Void> removeDelegatedUser(Username baseUser, Username delegatedToUser) { | ||
return postgresUsersDAO.removeDelegatedToUser(baseUser, delegatedToUser); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.