Skip to content

Commit

Permalink
Merge branch 'release/2021.9.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
sfeilmeier committed May 6, 2021
2 parents d2b9e62 + 43aff98 commit 39886a1
Show file tree
Hide file tree
Showing 142 changed files with 3,012 additions and 1,881 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ task buildEdge() {
doLast {
file("${buildDir}/openems-edge.jar").delete()
copy {
from file("${project(":io.openems.edge.application").distsDir}/executable/EdgeApp.jar")
from file("io.openems.edge.application/generated/distributions/executable/EdgeApp.jar")
into file("${buildDir}")
rename ("EdgeApp.jar", "openems-edge.jar")
}
Expand All @@ -40,7 +40,7 @@ task buildBackend() {
doLast {
file("${buildDir}/openems-backend.jar").delete()
copy {
from file("${project(":io.openems.backend.application").distsDir}/executable/BackendApp.jar")
from file("io.openems.backend.application/generated/distributions/executable/BackendApp.jar")
into file("${buildDir}")
rename ("BackendApp.jar", "openems-backend.jar")
}
Expand Down
12 changes: 6 additions & 6 deletions cnf/build.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ junit: \

# OpenEMS bnd.bnd defaults
buildpath: \
osgi.annotation;version=7.0.0,\
osgi.core;version=7.0.0,\
osgi.cmpn;version=7.0.0,\
slf4j.api;version=1.7.30,\
com.google.guava;version=28.2,\
com.google.gson;version=2.8.5
osgi.annotation;version='7.0.0',\
osgi.core;version='7.0.0',\
osgi.cmpn;version='7.0.0',\
slf4j.api;version='1.7.30',\
com.google.guava;version='30.1.1',\
com.google.gson;version='2.8.5'

testpath: \
slf4j.simple,\
Expand Down
18 changes: 12 additions & 6 deletions cnf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>29.0-jre</version>
<version>30.1.1-jre</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
Expand Down Expand Up @@ -75,7 +75,7 @@
<!-- Used by org.influxdb: influxdb-java -->
<groupId>com.squareup.retrofit2</groupId>
<artifactId>retrofit</artifactId>
<version>2.8.1</version>
<version>2.9.0</version>
</dependency>
<dependency>
<!-- HikariCP A solid, high-performance, JDBC connection pool at last. -->
Expand Down Expand Up @@ -181,7 +181,13 @@
<dependency>
<groupId>org.dhatim</groupId>
<artifactId>fastexcel</artifactId>
<version>0.12.7</version>
<version>0.12.9</version>
</dependency>
<dependency>
<!-- Eclipse Paho MQTTv5 Client -->
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.mqttv5.client</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
Expand Down Expand Up @@ -211,12 +217,12 @@
<dependency>
<groupId>org.ops4j.pax.logging</groupId>
<artifactId>pax-logging-api</artifactId>
<version>2.0.8</version>
<version>2.0.9</version>
</dependency>
<dependency>
<groupId>org.ops4j.pax.logging</groupId>
<artifactId>pax-logging-log4j1</artifactId>
<version>2.0.8</version>
<version>2.0.9</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
Expand All @@ -237,7 +243,7 @@
<!-- Used by io.openems.backend.metadata.odoo -->
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.19</version>
<version>42.2.20</version>
</dependency>
<dependency>
<!-- Used by io.openems.edge.timedata.rrd4j -->
Expand Down
2 changes: 1 addition & 1 deletion doc/modules/ROOT/pages/single_document.adoc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
= OpenEMS - Open Energy Management System
ifndef::toc[]
(c) 2020 OpenEMS Association e.V.
Version 2021.8.0
Version 2021.9.0
:sectnums:
:sectnumlevels: 4
:toc:
Expand Down
8 changes: 4 additions & 4 deletions io.openems.backend.application/BackendApp.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
-runbundles: \
Java-WebSocket;version='[1.5.2,1.5.3)',\
com.google.gson;version='[2.8.5,2.8.6)',\
com.google.guava;version='[29.0.0,29.0.1)',\
com.google.guava;version='[30.1.1,30.1.2)',\
com.google.guava.failureaccess;version='[1.0.1,1.0.2)',\
com.zaxxer.HikariCP;version='[4.0.3,4.0.4)',\
io.openems.backend.application;version=snapshot,\
Expand Down Expand Up @@ -73,9 +73,9 @@
org.apache.servicemix.bundles.ws-commons-util;version='[1.0.2,1.0.3)',\
org.apache.servicemix.bundles.xmlrpc-client;version='[3.1.3,3.1.4)',\
org.jsr-305;version='[3.0.2,3.0.3)',\
org.ops4j.pax.logging.pax-logging-api;version='[2.0.8,2.0.9)',\
org.ops4j.pax.logging.pax-logging-log4j1;version='[2.0.8,2.0.9)',\
org.ops4j.pax.logging.pax-logging-api;version='[2.0.9,2.0.10)',\
org.ops4j.pax.logging.pax-logging-log4j1;version='[2.0.9,2.0.10)',\
org.osgi.service.jdbc;version='[1.0.0,1.0.1)',\
org.osgi.util.function;version='[1.1.0,1.1.1)',\
org.osgi.util.promise;version='[1.1.1,1.1.2)',\
org.postgresql.jdbc;version='[42.2.19,42.2.20)'
org.postgresql.jdbc;version='[42.2.20,42.2.21)'
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.google.common.collect.HashMultimap;

import io.openems.common.channel.Level;
import io.openems.common.exceptions.OpenemsError;
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.common.exceptions.OpenemsException;
import io.openems.common.types.ChannelAddress;
Expand All @@ -27,6 +26,7 @@ public interface Metadata {
/**
* Was the Metadata service fully initialized?.
*
* <p>
* The service might take some time in the beginning to establish a connection
* or to cache data from an external database.
*
Expand All @@ -36,27 +36,17 @@ public interface Metadata {

/**
* See {@link #isInitialized()}.
*
* @param callback the callback on 'isInitialized'
*/
public void addOnIsInitializedListener(Runnable callback);

/**
* See {@link #isInitialized()}.
*/
public void removeOnIsInitializedListener(Runnable callback);

/**
* Authenticates a User without any information.
*
* <p>
* This is only useful for Dummy-Implementations. By default authentication is
* denied in this case.
*
* @return the User
* @throws OpenemsNamedException on error
* @param callback the callback on 'isInitialized'
*/
public default User authenticate() throws OpenemsNamedException {
throw OpenemsError.COMMON_AUTHENTICATION_FAILED.exception();
}
public void removeOnIsInitializedListener(Runnable callback);

/**
* Authenticates the User by username and password.
Expand All @@ -69,13 +59,20 @@ public default User authenticate() throws OpenemsNamedException {
public User authenticate(String username, String password) throws OpenemsNamedException;

/**
* Authenticates the User by a Session-ID.
* Authenticates the User by a Token.
*
* @param sessionId the Session-ID
* @param token the Token
* @return the {@link User}
* @throws OpenemsNamedException on error
*/
public User authenticate(String sessionId) throws OpenemsNamedException;
public User authenticate(String token) throws OpenemsNamedException;

/**
* Closes a session for a User.
*
* @param user the {@link User}
*/
public void logout(User user);

/**
* Gets the Edge-ID for an API-Key, i.e. authenticates the API-Key.
Expand Down Expand Up @@ -180,4 +177,5 @@ public static String activeStateChannelsToString(
}
return result.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import io.openems.common.exceptions.OpenemsError;
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.common.jsonrpc.response.AuthenticateWithPasswordResponse.EdgeMetadata;
import io.openems.common.jsonrpc.response.AuthenticateResponse.EdgeMetadata;
import io.openems.common.session.AbstractUser;
import io.openems.common.session.Role;

Expand All @@ -17,8 +17,23 @@
*/
public class User extends AbstractUser {

public User(String id, String name, Role globalRole, NavigableMap<String, Role> roles) {
/**
* Keeps the login token.
*/
private final String token;

public User(String id, String name, String token, Role globalRole, NavigableMap<String, Role> roles) {
super(id, name, globalRole, roles);
this.token = token;
}

/**
* Gets the login token.
*
* @return the token
*/
public String getToken() {
return this.token;
}

/**
Expand Down Expand Up @@ -62,6 +77,7 @@ public Role assertEdgeRoleIsAtLeast(String resource, String edgeId, Role role) t
/**
* Gets the Metadata information of the accessible Edges.
*
* @param user the {@link User}
* @param metadataService a {@link Metadata} provider
* @return a list of {@link EdgeMetadata}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -24,8 +25,8 @@
import io.openems.backend.common.metadata.Metadata;
import io.openems.backend.common.metadata.User;
import io.openems.common.channel.Level;
import io.openems.common.exceptions.OpenemsError;
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.common.exceptions.OpenemsException;
import io.openems.common.session.Role;
import io.openems.common.types.EdgeConfig;
import io.openems.common.types.EdgeConfigDiff;
Expand Down Expand Up @@ -64,26 +65,31 @@ void deactivate() {
}

@Override
public User authenticate() throws OpenemsException {
int id = this.nextUserId.incrementAndGet();
String userId = "user" + id;
public User authenticate(String username, String password) throws OpenemsNamedException {
String name = "User #" + this.nextUserId.incrementAndGet();
String token = UUID.randomUUID().toString();
TreeMap<String, Role> roles = new TreeMap<>();
for (String edgeId : this.edges.keySet()) {
roles.put(edgeId, Role.ADMIN);
}
User user = new User(userId, "User #" + id, Role.ADMIN, roles);
this.users.put(userId, user);
User user = new User(username, name, token, Role.ADMIN, roles);
this.users.put(user.getId(), user);
return user;
}

@Override
public User authenticate(String username, String password) throws OpenemsNamedException {
return this.authenticate();
public User authenticate(String token) throws OpenemsNamedException {
for (User user : this.users.values()) {
if (user.getToken().equals(token)) {
return user;
}
}
throw OpenemsError.COMMON_AUTHENTICATION_FAILED.exception();
}

@Override
public User authenticate(String sessionId) throws OpenemsException {
return this.authenticate();
public void logout(User user) {
this.users.remove(user.getId(), user);
}

@Override
Expand Down Expand Up @@ -133,7 +139,7 @@ public Collection<Edge> getAllEdges() {
return Collections.unmodifiableCollection(this.edges.values());
}

public static Optional<Integer> parseNumberFromName(String name) {
private static Optional<Integer> parseNumberFromName(String name) {
try {
Matcher matcher = NAME_NUMBER_PATTERN.matcher(name);
if (matcher.find()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Map.Entry;
import java.util.Optional;
import java.util.TreeMap;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;

import org.osgi.service.component.annotations.Activate;
Expand All @@ -31,8 +32,8 @@
import io.openems.backend.common.metadata.Metadata;
import io.openems.backend.common.metadata.User;
import io.openems.common.channel.Level;
import io.openems.common.exceptions.OpenemsError;
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.common.exceptions.OpenemsException;
import io.openems.common.session.Role;
import io.openems.common.types.EdgeConfig;
import io.openems.common.utils.JsonUtils;
Expand Down Expand Up @@ -63,15 +64,19 @@
)
public class FileMetadata extends AbstractMetadata implements Metadata {

private final Logger log = LoggerFactory.getLogger(FileMetadata.class);
private static final String USER_ID = "admin";
private static final String USER_NAME = "Administrator";
private static final Role USER_GLOBAL_ROLE = Role.ADMIN;

private final User user = new User("admin", "Administrator", Role.ADMIN, new TreeMap<>());
private final Logger log = LoggerFactory.getLogger(FileMetadata.class);
private final Map<String, MyEdge> edges = new HashMap<>();

private User user;
private String path = "";

public FileMetadata() {
super("Metadata.File");
this.user = FileMetadata.generateUser();
}

@Activate
Expand All @@ -91,18 +96,21 @@ void deactivate() {
}

@Override
public User authenticate() throws OpenemsException {
public User authenticate(String username, String password) throws OpenemsNamedException {
return this.user;
}

@Override
public User authenticate(String username, String password) throws OpenemsNamedException {
return this.authenticate();
public User authenticate(String token) throws OpenemsNamedException {
if (this.user.getToken().equals(token)) {
return this.user;
}
throw OpenemsError.COMMON_AUTHENTICATION_FAILED.exception();
}

@Override
public User authenticate(String sessionId) throws OpenemsException {
return this.authenticate();
public void logout(User user) {
this.user = FileMetadata.generateUser();
}

@Override
Expand Down Expand Up @@ -184,4 +192,9 @@ private synchronized void refreshData() {
this.setInitialized();
}

private static User generateUser() {
return new User(FileMetadata.USER_ID, FileMetadata.USER_NAME, UUID.randomUUID().toString(),
FileMetadata.USER_GLOBAL_ROLE, new TreeMap<>());
}

}
Loading

0 comments on commit 39886a1

Please sign in to comment.