Skip to content

Commit 80f34f8

Browse files
committed
add createTemporaryIdentity with IdentityConfiguration arg
Signed-off-by: Nicola Timeus <nicola.timeus@eurotech.com>
1 parent ba21529 commit 80f34f8

2 files changed

Lines changed: 33 additions & 5 deletions

File tree

kura/org.eclipse.kura.api/src/main/java/org/eclipse/kura/identity/IdentityService.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,25 @@ public IdentityConfiguration getIdentityDefaultConfiguration(final String identi
257257
*/
258258
public void createTemporaryIdentity(final String identityName, final Duration lifetime) throws KuraException;
259259

260+
261+
/**
262+
* Creates a temporary identity that is not persisted and has automatic
263+
* expiration. Temporary identities behave like regular identities but are
264+
* stored in-memory only and are automatically removed after the specified
265+
* lifetime period.
266+
*
267+
* @param identityConfiguration
268+
* the identity configuration including identity
269+
* name and optional configuration components.
270+
* @param lifetime
271+
* the duration before automatic expiration. The identity
272+
* will be automatically removed after this period.
273+
* @throws KuraException
274+
* if a failure occurs in creating the temporary identity,
275+
* if an identity with the given name already exists
276+
* (either regular or temporary) or if the provided configuration
277+
* is not valied.
278+
* @since 2.8.0
279+
*/
280+
public void createTemporaryIdentity(final IdentityConfiguration identityConfiguration, final Duration lifetime) throws KuraException;
260281
}

kura/org.eclipse.kura.core.identity/src/main/java/org/eclipse/kura/core/identity/IdentityServiceImpl.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,6 @@ private AdditionalConfigurations getAdditionalConfigurationsDefaults(final Strin
354354
return new AdditionalConfigurations(additionalConfigurations);
355355
}
356356

357-
358357
private void validatePasswordConfiguration(final IdentityConfiguration identityConfiguration,
359358
final PasswordConfiguration passwordCofiguration) throws KuraException {
360359
if (!passwordCofiguration.isPasswordAuthEnabled()) {
@@ -373,8 +372,7 @@ private void validatePasswordConfiguration(final IdentityConfiguration identityC
373372
.filter(u -> u.getCredentials().get(PASSWORD_PROPERTY) != null).isPresent();
374373
final boolean hasTemporaryPasswordHash = this.temporaryStore.getIdentity(identityConfiguration.getName())
375374
.flatMap(config -> config.getComponent(PasswordConfiguration.class))
376-
.flatMap(PasswordConfiguration::getPasswordHash)
377-
.isPresent();
375+
.flatMap(PasswordConfiguration::getPasswordHash).isPresent();
378376
if (!hasPersistedPasswordHash && !hasTemporaryPasswordHash) {
379377
throw new KuraException(KuraErrorCode.INVALID_PARAMETER,
380378
"Password authentication is enabled but no password has been provided or is currently assigned");
@@ -411,6 +409,15 @@ private void validateAdditionalConfigurations(final IdentityConfiguration identi
411409
public synchronized void createTemporaryIdentity(final String identityName, final Duration lifetime)
412410
throws KuraException {
413411

412+
createTemporaryIdentity(new IdentityConfiguration(identityName, Collections.emptyList()), lifetime);
413+
}
414+
415+
@Override
416+
public synchronized void createTemporaryIdentity(final IdentityConfiguration identityConfiguration,
417+
final Duration lifetime) throws KuraException {
418+
419+
final String identityName = identityConfiguration.getName();
420+
414421
ValidationUtil.validateNewIdentityName(identityName);
415422

416423
// Check if identity already exists (temporary or regular)
@@ -429,8 +436,8 @@ public synchronized void createTemporaryIdentity(final String identityName, fina
429436
"Temporary identity lifetime must be positive");
430437
}
431438

432-
this.temporaryIdentityStore.createIdentity(new IdentityConfiguration(identityName, Collections.emptyList()),
433-
lifetime);
439+
validateIdentityConfiguration(identityConfiguration);
440+
this.temporaryIdentityStore.createIdentity(identityConfiguration, lifetime);
434441

435442
}, "Create temporary identity " + identityName);
436443
}

0 commit comments

Comments
 (0)