-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added IdentityService APIs (#5132)
* feat: Added IdentityService APIs Signed-off-by: Nicola Timeus <[email protected]> * Added missing validation in constructor Signed-off-by: Nicola Timeus <[email protected]> * Addressed comments Signed-off-by: Nicola Timeus <[email protected]> --------- Signed-off-by: Nicola Timeus <[email protected]>
- Loading branch information
1 parent
574e54d
commit 538fddc
Showing
13 changed files
with
886 additions
and
0 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
90 changes: 90 additions & 0 deletions
90
...rg.eclipse.kura.api/src/main/java/org/eclipse/kura/identity/AdditionalConfigurations.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,90 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Eurotech and/or its affiliates and others | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Eurotech | ||
******************************************************************************/ | ||
package org.eclipse.kura.identity; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import org.eclipse.kura.configuration.ComponentConfiguration; | ||
import org.osgi.annotation.versioning.ProviderType; | ||
|
||
/** | ||
* Represents a set of additional configurations associated with an identity | ||
* managed by {@code IdentityConfigurationExtension} implementations. | ||
* <br> | ||
* This class contains a list of {@link ComponentConfiguration} instances, the | ||
* {@link ComponentConfiguration#getPid()} method of each configuration should | ||
* return the kura.service.pid of the associated | ||
* {@code IdentityConfigurationExtension}. | ||
* <br> | ||
* <br> | ||
* The {@link IdentityService#getIdentitiesConfiguration(List)} and | ||
* {@link IdentityService#getIdentityConfiguration(String, List)} method will | ||
* return the {@link ComponentConfiguration}s provided by all | ||
* {@code IdentityConfigurationExtension}s registered in the framework. | ||
* <br> | ||
* <br> | ||
* The | ||
* {@link IdentityService#updateIdentityConfiguration(IdentityConfiguration)} | ||
* method | ||
* will call | ||
* {@code IdentityConfigurationExtension.updateConfiguration(String, ComponentConfiguration)} | ||
* method of the {@code IdentityConfigurationExtension} instances whose | ||
* kura.service.pid is referenced by the provided configurations. | ||
* | ||
* @noextend This class is not intended to be subclassed by clients. | ||
* @since 2.7.0 | ||
*/ | ||
@ProviderType | ||
public class AdditionalConfigurations implements IdentityConfigurationComponent { | ||
|
||
private final List<ComponentConfiguration> configurations; | ||
|
||
/** | ||
* Creates a new instance containing the provided configuration list. | ||
* | ||
* @param configurations the configuration list. | ||
*/ | ||
public AdditionalConfigurations(final List<ComponentConfiguration> configurations) { | ||
this.configurations = requireNonNull(configurations, "configuration list cannot be null"); | ||
} | ||
|
||
/** | ||
* Returns the list of component configurations. | ||
* | ||
* @return the list of component configurations. | ||
*/ | ||
public List<ComponentConfiguration> getConfigurations() { | ||
return this.configurations; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(this.configurations); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (!(obj instanceof AdditionalConfigurations)) { | ||
return false; | ||
} | ||
AdditionalConfigurations other = (AdditionalConfigurations) obj; | ||
return Objects.equals(this.configurations, other.configurations); | ||
} | ||
|
||
} |
72 changes: 72 additions & 0 deletions
72
kura/org.eclipse.kura.api/src/main/java/org/eclipse/kura/identity/AssignedPermissions.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,72 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Eurotech and/or its affiliates and others | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Eurotech | ||
******************************************************************************/ | ||
package org.eclipse.kura.identity; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
import org.osgi.annotation.versioning.ProviderType; | ||
|
||
/** | ||
* Describes the the set of permissions currently assigned to a given identity. | ||
* If the | ||
* {@link IdentityService#updateIdentityConfiguration(IdentityConfiguration)} | ||
* receives an {@link IdentityConfiguration} containing this component, it | ||
* should replace the currently assigned permission set with the specified one. | ||
* | ||
* @noextend This class is not intended to be subclassed by clients. | ||
* @since 2.7.0 | ||
*/ | ||
@ProviderType | ||
public class AssignedPermissions implements IdentityConfigurationComponent { | ||
|
||
private final Set<Permission> permissions; | ||
|
||
/** | ||
* Creates a new instance representing the provided permission set. | ||
* | ||
* @param permissions the permission set. | ||
*/ | ||
public AssignedPermissions(final Set<Permission> permissions) { | ||
this.permissions = requireNonNull(permissions, "permissions cannot be null"); | ||
} | ||
|
||
/** | ||
* Returns the permission set. | ||
* | ||
* @return the permission set. | ||
*/ | ||
public Set<Permission> getPermissions() { | ||
return permissions; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(permissions); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (!(obj instanceof AssignedPermissions)) { | ||
return false; | ||
} | ||
AssignedPermissions other = (AssignedPermissions) obj; | ||
return Objects.equals(permissions, other.permissions); | ||
} | ||
|
||
} |
98 changes: 98 additions & 0 deletions
98
kura/org.eclipse.kura.api/src/main/java/org/eclipse/kura/identity/IdentityConfiguration.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,98 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Eurotech and/or its affiliates and others | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Eurotech | ||
******************************************************************************/ | ||
package org.eclipse.kura.identity; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
import org.osgi.annotation.versioning.ProviderType; | ||
|
||
/** | ||
* Describes the configuration for an identity. It is composed by different | ||
* {@link IdentityConfigurationComponent}s that can be retrieved and updated | ||
* separately using the {@link IdentityService}. | ||
* | ||
* @noextend This class is not intended to be subclassed by clients. | ||
* @since 2.7.0 | ||
*/ | ||
@ProviderType | ||
public class IdentityConfiguration { | ||
|
||
private final String name; | ||
private final List<IdentityConfigurationComponent> components; | ||
|
||
/** | ||
* Creates a new identity configuration with the given name and components. | ||
* | ||
* @param name the identity name. | ||
* @param components the {@link IdentityConfigurationComponent} list. | ||
*/ | ||
public IdentityConfiguration(String name, List<IdentityConfigurationComponent> components) { | ||
this.name = requireNonNull(name, "name cannot be null"); | ||
|
||
if (this.name.trim().isEmpty()) { | ||
throw new IllegalArgumentException("name cannot be empty"); | ||
} | ||
|
||
this.components = requireNonNull(components, "components cannot be null"); | ||
} | ||
|
||
/** | ||
* Returns the identity name. | ||
* | ||
* @return the identity name. | ||
*/ | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
/** | ||
* Returns the list of {@link IdentityConfigurationComponent}s. | ||
* | ||
* @return the list of {@link IdentityConfigurationComponent}s. | ||
*/ | ||
public List<IdentityConfigurationComponent> getComponents() { | ||
return components; | ||
} | ||
|
||
public <T extends IdentityConfigurationComponent> Optional<T> getComponent(final Class<T> clazz) { | ||
for (final IdentityConfigurationComponent component : components) { | ||
if (clazz.isInstance(component)) { | ||
return Optional.of(clazz.cast(component)); | ||
} | ||
} | ||
|
||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(components, name); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (!(obj instanceof IdentityConfiguration)) { | ||
return false; | ||
} | ||
IdentityConfiguration other = (IdentityConfiguration) obj; | ||
return Objects.equals(components, other.components) && Objects.equals(name, other.name); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
...ipse.kura.api/src/main/java/org/eclipse/kura/identity/IdentityConfigurationComponent.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,29 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Eurotech and/or its affiliates and others | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Eurotech | ||
******************************************************************************/ | ||
package org.eclipse.kura.identity; | ||
|
||
import org.osgi.annotation.versioning.ProviderType; | ||
|
||
/** | ||
* Represents a portion of the configuration of an identity that can be | ||
* retrieved and updated individually. | ||
* | ||
* The currently supported types are {@link PasswordConfiguration}, | ||
* {@link AssignedPermissions} and {@link AdditionalConfigurations}. | ||
* | ||
* @noimplement This interface is not intended to be implemented by clients. | ||
* @since 2.7.0 | ||
*/ | ||
@ProviderType | ||
public interface IdentityConfigurationComponent { | ||
} |
Oops, something went wrong.