Skip to content

Commit

Permalink
Refactor bean definition of 'deactivateOnDelete'
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianhoelzl-sap committed Sep 4, 2024
1 parent 3be124c commit e72d23d
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Map;
import java.util.UUID;

import com.google.common.annotations.VisibleForTesting;
import org.cloudfoundry.identity.uaa.audit.event.SystemDeletable;
import org.cloudfoundry.identity.uaa.constants.OriginKeys;
import org.cloudfoundry.identity.uaa.resources.ResourceMonitor;
Expand Down Expand Up @@ -57,7 +58,6 @@
import org.cloudfoundry.identity.uaa.zone.beans.IdentityZoneManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.dao.DuplicateKeyException;
Expand Down Expand Up @@ -130,7 +130,6 @@ public Logger getLogger() {

private final PasswordEncoder passwordEncoder;

@Value("${scim.delete.deactivate:false}")
private boolean deactivateOnDelete;

private static final RowMapper<ScimUser> mapper = new ScimUserRowMapper();
Expand All @@ -148,7 +147,8 @@ public JdbcScimUserProvisioning(
final IdentityZoneManager identityZoneManager,
final JdbcIdentityZoneProvisioning jdbcIdentityZoneProvisioning,
@Qualifier("scimJoinQueryConverter") final SearchQueryConverter joinConverter,
@Qualifier("timeService") final TimeService timeService
final TimeService timeService,
@Value("${scim.delete.deactivate:false}") final boolean deactivateOnDelete
) {
super(namedJdbcTemplate, pagingListFactory, mapper);
Assert.notNull(namedJdbcTemplate, "JdbcTemplate required");
Expand All @@ -159,6 +159,7 @@ public JdbcScimUserProvisioning(
this.identityZoneManager = identityZoneManager;
this.joinConverter = joinConverter;
this.timeService = timeService;
this.deactivateOnDelete = deactivateOnDelete;
}

@Override
Expand Down Expand Up @@ -503,6 +504,7 @@ protected int deleteUser(String userId, int version, String zoneId) {
return updated;
}

@VisibleForTesting
public void setDeactivateOnDelete(boolean deactivateOnDelete) {
this.deactivateOnDelete = deactivateOnDelete;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void setup(@Autowired JdbcTemplate jdbcTemplate, @Autowired NamedParameterJdbcTe
namedJdbcTemplate,
new JdbcPagingListFactory(namedJdbcTemplate, LimitSqlAdapterFactory.getLimitSqlAdapter()),
passwordEncoder, mockIdentityZoneManager, new JdbcIdentityZoneProvisioning(jdbcTemplate),
new SimpleSearchQueryConverter(), new TimeServiceImpl());
new SimpleSearchQueryConverter(), new TimeServiceImpl(), true);

final RandomValueStringGenerator generator = new RandomValueStringGenerator();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void setupForTokenRevocation() {
ScimUserProvisioning userProvisioning = new JdbcScimUserProvisioning(
namedJdbcTemplate,
new JdbcPagingListFactory(namedJdbcTemplate, limitSqlAdapter),
passwordEncoder, new IdentityZoneManagerImpl(), new JdbcIdentityZoneProvisioning(jdbcTemplate), new SimpleSearchQueryConverter(), new TimeServiceImpl());
passwordEncoder, new IdentityZoneManagerImpl(), new JdbcIdentityZoneProvisioning(jdbcTemplate), new SimpleSearchQueryConverter(), new TimeServiceImpl(), true);
JdbcRevocableTokenProvisioning provisioning = spy(new JdbcRevocableTokenProvisioning(jdbcTemplate, limitSqlAdapter, new TimeServiceImpl()));
endpoint = spy(new TokenRevocationEndpoint(clientService, userProvisioning, provisioning));
ApplicationEventPublisher publisher = mock(ApplicationEventPublisher.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void configureProvider() throws SAMLException, SecurityException, DecryptionExce
groupProvisioning.createOrGet(new ScimGroup(null, UAA_USER, identityZoneManager.getCurrentIdentityZone().getId()), identityZoneManager.getCurrentIdentityZone().getId());
providerDefinition = new SamlIdentityProviderDefinition();

userProvisioning = new JdbcScimUserProvisioning(namedJdbcTemplate, new JdbcPagingListFactory(namedJdbcTemplate, limitSqlAdapter), passwordEncoder, new IdentityZoneManagerImpl(), new JdbcIdentityZoneProvisioning(jdbcTemplate), new SimpleSearchQueryConverter(), new TimeServiceImpl());
userProvisioning = new JdbcScimUserProvisioning(namedJdbcTemplate, new JdbcPagingListFactory(namedJdbcTemplate, limitSqlAdapter), passwordEncoder, new IdentityZoneManagerImpl(), new JdbcIdentityZoneProvisioning(jdbcTemplate), new SimpleSearchQueryConverter(), new TimeServiceImpl(), true);


uaaSamlUser = groupProvisioning.create(new ScimGroup(null, UAA_SAML_USER, IdentityZone.getUaaZoneId()), identityZoneManager.getCurrentIdentityZone().getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void initScimGroupBootstrapTests() throws SQLException {
JdbcPagingListFactory pagingListFactory = new JdbcPagingListFactory(namedJdbcTemplate, limitSqlAdapter);
DbUtils dbUtils = new DbUtils();
gDB = new JdbcScimGroupProvisioning(namedJdbcTemplate, pagingListFactory, dbUtils);
uDB = new JdbcScimUserProvisioning(namedJdbcTemplate, pagingListFactory, passwordEncoder, new IdentityZoneManagerImpl(), new JdbcIdentityZoneProvisioning(jdbcTemplate), new SimpleSearchQueryConverter(), new TimeServiceImpl());
uDB = new JdbcScimUserProvisioning(namedJdbcTemplate, pagingListFactory, passwordEncoder, new IdentityZoneManagerImpl(), new JdbcIdentityZoneProvisioning(jdbcTemplate), new SimpleSearchQueryConverter(), new TimeServiceImpl(), true);
mDB = new JdbcScimGroupMembershipManager(template, new TimeServiceImpl(), uDB, null, dbUtils);
mDB.setScimGroupProvisioning(gDB);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class ScimUserBootstrapTests {
@BeforeEach
void init() throws SQLException {
JdbcPagingListFactory pagingListFactory = new JdbcPagingListFactory(namedJdbcTemplate, LimitSqlAdapterFactory.getLimitSqlAdapter());
jdbcScimUserProvisioning = spy(new JdbcScimUserProvisioning(namedJdbcTemplate, pagingListFactory, passwordEncoder, new IdentityZoneManagerImpl(), new JdbcIdentityZoneProvisioning(jdbcTemplate), new SimpleSearchQueryConverter(), new TimeServiceImpl()));
jdbcScimUserProvisioning = spy(new JdbcScimUserProvisioning(namedJdbcTemplate, pagingListFactory, passwordEncoder, new IdentityZoneManagerImpl(), new JdbcIdentityZoneProvisioning(jdbcTemplate), new SimpleSearchQueryConverter(), new TimeServiceImpl(), true));
DbUtils dbUtils = new DbUtils();
jdbcScimGroupProvisioning = new JdbcScimGroupProvisioning(namedJdbcTemplate, pagingListFactory, dbUtils);
jdbcScimGroupMembershipManager = new JdbcScimGroupMembershipManager(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void setUp() throws SQLException {
dbUtils = new DbUtils();

JdbcPagingListFactory pagingListFactory = new JdbcPagingListFactory(namedJdbcTemplate, limitSqlAdapter);
JdbcScimUserProvisioning jdbcScimUserProvisioning = new JdbcScimUserProvisioning(namedJdbcTemplate, pagingListFactory, passwordEncoder, new IdentityZoneManagerImpl(), new JdbcIdentityZoneProvisioning(jdbcTemplate), new SimpleSearchQueryConverter(), new TimeServiceImpl());
JdbcScimUserProvisioning jdbcScimUserProvisioning = new JdbcScimUserProvisioning(namedJdbcTemplate, pagingListFactory, passwordEncoder, new IdentityZoneManagerImpl(), new JdbcIdentityZoneProvisioning(jdbcTemplate), new SimpleSearchQueryConverter(), new TimeServiceImpl(), true);
jdbcScimGroupProvisioning = new JdbcScimGroupProvisioning(namedJdbcTemplate, pagingListFactory, dbUtils);

jdbcScimGroupMembershipManager = new JdbcScimGroupMembershipManager(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void setUp(@Autowired LimitSqlAdapter limitSqlAdapter) {

SimpleSearchQueryConverter joinConverter = new SimpleSearchQueryConverter();
joinConverter.setAttributeNameMapper(new JoinAttributeNameMapper("u"));
jdbcScimUserProvisioning = new JdbcScimUserProvisioning(namedJdbcTemplate, pagingListFactory, passwordEncoder, idzManager, jdbcIdentityZoneProvisioning, joinConverter, new TimeServiceImpl());
jdbcScimUserProvisioning = new JdbcScimUserProvisioning(namedJdbcTemplate, pagingListFactory, passwordEncoder, idzManager, jdbcIdentityZoneProvisioning, joinConverter, new TimeServiceImpl(), true);

SimpleSearchQueryConverter filterConverter = new SimpleSearchQueryConverter();
Map<String, String> replaceWith = new HashMap<>();
Expand Down Expand Up @@ -318,7 +318,7 @@ void retrieveByScimFilterNoPaging() {
SimpleSearchQueryConverter joinConverter = new SimpleSearchQueryConverter();
joinConverter.setAttributeNameMapper(new JoinAttributeNameMapper("u"));
jdbcScimUserProvisioning = new JdbcScimUserProvisioning(namedJdbcTemplate, notInUse, passwordEncoder, new IdentityZoneManagerImpl(),
new JdbcIdentityZoneProvisioning(jdbcTemplate), joinConverter, new TimeServiceImpl());
new JdbcIdentityZoneProvisioning(jdbcTemplate), joinConverter, new TimeServiceImpl(), true);
String originActive = randomString();
addIdentityProvider(jdbcTemplate, currentIdentityZoneId, originActive, true);

Expand Down Expand Up @@ -374,7 +374,7 @@ void retrieveByScimFilterUsingLower() {
NamedParameterJdbcTemplate mockedJdbcTemplate = mock(NamedParameterJdbcTemplate.class);
SimpleSearchQueryConverter joinConverter = new SimpleSearchQueryConverter();
joinConverter.setAttributeNameMapper(new JoinAttributeNameMapper("u"));
jdbcScimUserProvisioning = new JdbcScimUserProvisioning(mockedJdbcTemplate, pagingListFactory, passwordEncoder, idzManager, jdbcIdentityZoneProvisioning, joinConverter, new TimeServiceImpl());
jdbcScimUserProvisioning = new JdbcScimUserProvisioning(mockedJdbcTemplate, pagingListFactory, passwordEncoder, idzManager, jdbcIdentityZoneProvisioning, joinConverter, new TimeServiceImpl(), true);

String scimFilter = "id eq '1111' or username eq 'j4hyqpassX' or origin eq 'uaa'";
jdbcScimUserProvisioning.setPageSize(0);
Expand Down Expand Up @@ -776,7 +776,7 @@ void cannotCreateScimUserWithEmptyEmail() {
void canReadScimUserWithMissingEmail() {
// Create a user with no email address, reflecting previous behavior

JdbcScimUserProvisioning noValidateProvisioning = new JdbcScimUserProvisioning(namedJdbcTemplate, pagingListFactory, passwordEncoder, new IdentityZoneManagerImpl(), new JdbcIdentityZoneProvisioning(jdbcTemplate), new SimpleSearchQueryConverter(), new TimeServiceImpl()) {
JdbcScimUserProvisioning noValidateProvisioning = new JdbcScimUserProvisioning(namedJdbcTemplate, pagingListFactory, passwordEncoder, new IdentityZoneManagerImpl(), new JdbcIdentityZoneProvisioning(jdbcTemplate), new SimpleSearchQueryConverter(), new TimeServiceImpl(), true) {
@Override
public ScimUser retrieve(String id, String zoneId) {
ScimUser createdUserId = new ScimUser();
Expand Down

0 comments on commit e72d23d

Please sign in to comment.