Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,37 @@ public MongoDbSecretProviderExtensionPoint() {
super(EXTENSION_POINT_TYPE,
"MongoDbSecretProvider.SecretProviderType.Name",
"MongoDbSecretProvider.SecretProviderType.Desc");

// The password in our configuration might be a referenced secret that points to a secret provider, so we need
// to add a reference property for it. We need to register our reference property and consume updates / renames
// of the SecretProvider to keep our configuration in sync.
addReferenceProperty("password", builder -> builder
.targetType(SecretProviderConfig.RESOURCE_TYPE)
.value(resource -> {
// Return the SecretProvider name if the password is a referenced secret.
SecretConfig secretConfig = resource.password();
if (secretConfig != null && secretConfig.isReferenced()) {
return secretConfig.getAsReferenced().getProviderName();
}
return null;
})
.caseSensitive(true)
.onUpdate((resource, newName) -> {
// Return a new resource with the updated SecretProvider name if the password is a
// referenced secret.
SecretConfig secretConfig = resource.password();
if (secretConfig != null && secretConfig.isReferenced()) {
return new MongoDbSecretProviderResource(
resource.connectionString(),
resource.databaseName(),
resource.username(),
SecretConfig.referenced(newName, secretConfig.getAsReferenced().getSecretName()),
resource.authenticationDb()
);
}
return resource; // Should never get here, but return the original resource if we do.
})
);
}

public SecretProvider createProvider(SecretProviderContext context) throws SecretProviderTypeException {
Expand Down
2 changes: 1 addition & 1 deletion user-source-profile/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# UserSourceProfile
# User Source Profile

This module provides an implementation of the `UserSourceProvider` interface, which allows for the management of user
profiles in a system. It includes methods for creating, updating, and deleting user profiles, as well as retrieving user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@
import org.apache.log4j.Level;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.joda.time.DateTime;
import org.joda.time.Days;

import javax.annotation.Nonnull;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -264,13 +263,9 @@ private boolean isPasswordInvalid(Document document, String pwd, boolean bypassE
// Password is valid, now check if the password is expired
if (settings.passwordMaxAge() > 0 && !bypassExpiration) {
long pwdTimestamp = document.getLong(KEY_PASSWORD_DATE);
if (pwdTimestamp > 0) {
DateTime passwordCreatedOn = new DateTime(pwdTimestamp);
DateTime now = DateTime.now();
int days = Days.daysBetween(passwordCreatedOn.toLocalDate(), now.toLocalDate()).getDays();
if (days > settings.passwordMaxAge()) {
throw new PasswordExpiredException(getName(), uname);
}
long pwdExpiration = pwdTimestamp + TimeUnit.DAYS.toMillis(settings.passwordMaxAge());
if (pwdTimestamp > 0 && System.currentTimeMillis() >= pwdExpiration) {
throw new PasswordExpiredException(getName(), uname);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.inductiveautomation.ignition.gateway.config.ValidationErrors;
import com.inductiveautomation.ignition.gateway.dataroutes.openapi.SchemaUtil;
import com.inductiveautomation.ignition.gateway.model.GatewayContext;
import com.inductiveautomation.ignition.gateway.secrets.SecretConfig;
import com.inductiveautomation.ignition.gateway.secrets.SecretProviderConfig;
import com.inductiveautomation.ignition.gateway.user.UserSourceExtensionPoint;
import com.inductiveautomation.ignition.gateway.user.UserSourceProfile;
import com.inductiveautomation.ignition.gateway.user.UserSourceProfileConfig;
Expand All @@ -26,6 +28,39 @@ public MongoDbUserSourceExtensionPoint() {
"MongoDbUserSource.UserSourceType.Name",
"MongoDbUserSource.UserSourceType.Desc",
MongoDbUserSourceResource.class);

// The password in our configuration might be a referenced secret that points to a secret provider, so we need
// to add a reference property for it. We need to register our reference property and consume updates / renames
// of the SecretProvider to keep our configuration in sync.
addReferenceProperty("password", builder -> builder
.targetType(SecretProviderConfig.RESOURCE_TYPE)
.value(resource -> {
// Return the SecretProvider name if the password is a referenced secret.
SecretConfig secretConfig = resource.password();
if (secretConfig != null && secretConfig.isReferenced()) {
return secretConfig.getAsReferenced().getProviderName();
}
return null;
})
.caseSensitive(true)
.onUpdate((resource, newName) -> {
// Return a new resource with the updated SecretProvider name if the password is a
// referenced secret.
SecretConfig secretConfig = resource.password();
if (secretConfig != null && secretConfig.isReferenced()) {
return new MongoDbUserSourceResource(
resource.connectionString(),
resource.databaseName(),
resource.username(),
SecretConfig.referenced(newName, secretConfig.getAsReferenced().getSecretName()),
resource.authenticationDb(),
resource.passwordMaxAge(),
resource.passwordHistory()
);
}
return resource; // Should never get here, but return the original resource if we do.
})
);
}

@Override
Expand Down