Skip to content

Commit 5bd8b28

Browse files
committed
Simplify user creation
We are putting users to default domain only. That can be created beforehand or its being created on our call. We do not need to adjust our logic according to it. Just log what the status is. Method to create user does not specify that exception is thrown when user does not exist. There can be a variety of problems. Do not assert that in our logs. JIRA: LIGHTY-426 Signed-off-by: Ivan Hrasko <ivan.hrasko@pantheon.tech>
1 parent 6da9a2b commit 5bd8b28

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

lighty-modules/lighty-aaa-aggregator/lighty-aaa/src/main/java/io/lighty/aaa/AAALightyShiroProvider.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,14 @@ private AAALightyShiroProvider(final DataBroker dataBroker,
102102
this.claimCache = idmLightProxy;
103103
}
104104
try {
105-
final StoreBuilder storeBuilder = new StoreBuilder(iidmStore);
106-
final String initDomain = storeBuilder.initDomainAndRolesWithoutUsers(IIDMStore.DEFAULT_DOMAIN);
107-
108-
// If the domain already exists, the init method returns null.
109-
// We fallback to the default domain string to ensure we have a valid ID for user creation.
110-
final String domain = initDomain == null ? IIDMStore.DEFAULT_DOMAIN : initDomain;
111-
// Create custom user from the JSON config
112-
try {
113-
storeBuilder.createUser(domain, aaaConfiguration.getUsername(), aaaConfiguration.getPassword(), true);
114-
LOG.info("Pre-seeded database with custom user '{}'", aaaConfiguration.getUsername());
115-
} catch (IDMStoreException e) {
116-
LOG.debug("User already exists, skipping creation.");
105+
final var storeBuilder = new StoreBuilder(iidmStore);
106+
final var created = storeBuilder.initDomainAndRolesWithoutUsers(IIDMStore.DEFAULT_DOMAIN);
107+
if (created == null) {
108+
LOG.debug("Default AAA domain has been already there, nothing to create");
109+
} else {
110+
LOG.debug("Default AAA domain has been created");
117111
}
118-
112+
storeBuilder.createUser(IIDMStore.DEFAULT_DOMAIN, aaaConfiguration.getUsername(), aaaConfiguration.getPassword(), true);
119113
} catch (final IDMStoreException e) {
120114
LOG.error("Failed to pre-seed data in store", e);
121115
}

0 commit comments

Comments
 (0)