Skip to content

Commit

Permalink
feat: Added IdentityService APIs (#5132)
Browse files Browse the repository at this point in the history
* 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
nicolatimeus authored Feb 19, 2024
1 parent 574e54d commit 538fddc
Show file tree
Hide file tree
Showing 13 changed files with 886 additions and 0 deletions.
2 changes: 2 additions & 0 deletions kura/org.eclipse.kura.api/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Export-Package: org.eclipse.kura;version="1.7.0",
org.eclipse.kura.driver.descriptor;version="1.0.0",
org.eclipse.kura.executor;version="1.0.0",
org.eclipse.kura.gpio;version="1.1.0",
org.eclipse.kura.identity;version="1.0.0",
org.eclipse.kura.identity.configuration.extension;version="1.0.0",
org.eclipse.kura.linux.udev;version="1.0.1",
org.eclipse.kura.log;version="1.1.0",
org.eclipse.kura.log.listener;version="1.0.0",
Expand Down
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);
}

}
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);
}

}
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);
}

}
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 {
}
Loading

0 comments on commit 538fddc

Please sign in to comment.