Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 18 additions & 0 deletions core/src/main/java/org/apache/hop/core/security/HopSecurity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.hop.core.security;

import java.util.Optional;

/**
* Global entry point for authorization checks. Defaults to an unrestricted context (desktop / no
* auth). Hop Web installs a session-aware {@link ISecurityContextProvider} so concurrent users each
Expand Down Expand Up @@ -70,6 +72,22 @@ public static HopSecurityContext getContext() {
return context != null ? context : HopSecurityContext.unrestricted();
}

/**
* The name to record in the audit fields of a file, such as the user who created or last modified
* a pipeline or workflow.
*
* <p>Only an authenticated context yields a name. The desktop runs unrestricted under the {@link
* HopSecurityContext#ANONYMOUS_USERNAME} placeholder, and neither that placeholder nor the
* operating system account name says anything about who edited the file, so those cases return an
* empty result and leave whatever the file already holds untouched.
*
* @return the authenticated user name, or empty when no real user is known
*/
public static Optional<String> getAuditUsername() {
HopSecurityContext context = getContext();
return context.isAuthenticated() ? Optional.of(context.getUsername()) : Optional.empty();
Comment thread
mattcasters marked this conversation as resolved.
Outdated
}

/**
* @param permission permission to check
* @return true if the current context allows it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,14 @@ The Pipeline tab allows you to specify general properties about the pipeline inc
|Pipeline filename| The filename of the pipeline
|Description|Short description of the pipeline
|Extended description| Long extended description of the pipeline
|Status| Draft or production status
|Version|Description of the version
|Created by| Displays the original creator of the pipeline
|Status| Draft or production status. Deprecated: nothing in Hop acts on this value and it will be removed in a future release.
|Version|Description of the version. Deprecated: this label has to be maintained by hand and will be removed in a future release, use the version control system that holds the file instead.
|Created by| The user that created the pipeline. Only recorded when Hop knows who that is, such as an authenticated Hop web session, and shows `-` otherwise.
|Created at|Displays the date and time when the pipeline was created.
|Last modified by| Displays the last user that modified the pipeline
|Last modified at|Displays the date and time when the pipeline was last modified.
|Last modified by| The user that last modified the pipeline, recorded under the same conditions as `Created by`.
|Last modified at|Displays the date and time of the last save that changed the pipeline. A save that does not change anything leaves this untouched.
|Created with|The version of Hop that created the pipeline. Empty for pipelines created before Hop started recording this.
|Last modified with|The version of Hop that last saved a change to the pipeline.
|===

The parameters tab allows you to specify parameters specific for the pipeline.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,13 @@ See also Launching several copies of a transform. | `copy of transform`

|Pipeline file name|File name of the pipeline (XML only). | This code has leading white space : `{sp}pipeline file name`

|User that modified the pipeline last| | `User modified`
|User that created the pipeline|Only filled in when Hop knew who created the pipeline, such as an authenticated Hop web session. `-` otherwise. | `User created`

|Date when the pipeline was modified last| | `Date modified`
|Date when the pipeline was created|The date the pipeline was first created. | `Date created`

|User that modified the pipeline last|Only filled in when Hop knew who saved the pipeline last, such as an authenticated Hop web session. `-` otherwise. | `User modified`

|Date when the pipeline was modified last|The date of the last save that changed the pipeline. | `Date modified`

|Hostname (Network setup)|Returns the hostname of the server. | `Hostname`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,13 @@ The Workflow tab allows you to specify general properties about the workflow inc
|Workflow filename| The filename of the workflow
|Description|Short description of the workflow
|Extended description| Long extended description of the workflow
|Status| Draft or production status
|Version|Description of the version
|Created by| Displays the original creator of the workflow
|Version|Description of the version. Deprecated: this label has to be maintained by hand and will be removed in a future release, use the version control system that holds the file instead.
|Created by| The user that created the workflow. Only recorded when Hop knows who that is, such as an authenticated Hop web session, and shows `-` otherwise.
|Created at|Displays the date and time when the workflow was created.
|Last modified by| Displays the last user that modified the workflow
|Last modified at|Displays the date and time when the workflow was last modified.
|Last modified by| The user that last modified the workflow, recorded under the same conditions as `Created by`.
|Last modified at|Displays the date and time of the last save that changed the workflow. A save that does not change anything leaves this untouched.
|Created with|The version of Hop that created the workflow. Empty for workflows created before Hop started recording this.
|Last modified with|The version of Hop that last saved a change to the workflow.
|===

The parameters tab allows you to specify parameters specific for the workflow.
Expand Down
47 changes: 47 additions & 0 deletions engine/src/main/java/org/apache/hop/base/AbstractMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -49,6 +50,7 @@
import org.apache.hop.core.parameters.INamedParameterDefinitions;
import org.apache.hop.core.parameters.INamedParameters;
import org.apache.hop.core.parameters.UnknownParamException;
import org.apache.hop.core.security.HopSecurity;
import org.apache.hop.core.undo.ChangeAction;
import org.apache.hop.core.util.Utils;
import org.apache.hop.core.variables.IVariables;
Expand Down Expand Up @@ -989,6 +991,51 @@ public final void setChanged(boolean ch) {
}
}

/**
* Whether a save that is about to be written has to refresh the elements recording who last
* changed this file and when.
*
* <p>An edited file gets a fresh stamp, and so does a file that is being written for the first
* time. A save that writes the same content over a file that is already there does not: the
* elements would then change every time an untouched file is saved and show up as a difference in
* version control.
*
* @param fileExists whether the file about to be written is already there
* @return true if the file has to be stamped before it is written
*/
public boolean needsModificationStamp(boolean fileExists) {
return hasChanged() || !fileExists;
}

/**
* Record the current time and user as the last modification of this file. Called by the save path
* right before the file is written, when {@link #needsModificationStamp(boolean)} says so.
*
* <p>The user is only recorded when a real one is known, see {@link
* HopSecurity#getAuditUsername()}. The desktop has no authenticated user, so there the modified
* date is maintained and the user is left at whatever the file already holds.
*/
public void stampModified() {
setModifiedDate(new Date());
HopSecurity.getAuditUsername().ifPresent(this::setModifiedUser);
}

/**
* Record the current user as the creator of this file. Called when a new file is created, never
* on save: the creator of an existing file is not whoever happens to save it next.
*
* <p>The creation date is set by the constructor. Only a known user is recorded, see {@link
* HopSecurity#getAuditUsername()}.
*/
public void stampCreated() {
HopSecurity.getAuditUsername()
.ifPresent(
username -> {
setCreatedUser(username);
setModifiedUser(username);
});
}

public void addObserver(IHopObserver o) {
changedFlag.addObserver(o);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2969,7 +2969,9 @@ public void checkTransforms(
* Gets the version of the pipeline.
*
* @return The version of the pipeline
* @deprecated since 2.20, for removal. See {@link PipelineMetaInfo#pipelineVersion}.
*/
@Deprecated(since = "2.20", forRemoval = true)
public String getPipelineVersion() {
return info.getPipelineVersion();
}
Expand All @@ -2978,7 +2980,9 @@ public String getPipelineVersion() {
* Sets the version of the pipeline.
*
* @param pipelineVersion The new version description of the pipeline
* @deprecated since 2.20, for removal. See {@link PipelineMetaInfo#pipelineVersion}.
*/
@Deprecated(since = "2.20", forRemoval = true)
public void setPipelineVersion(String pipelineVersion) {
info.setPipelineVersion(pipelineVersion);
}
Expand Down
20 changes: 18 additions & 2 deletions engine/src/main/java/org/apache/hop/pipeline/PipelineMetaInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@
@Getter
@Setter
public class PipelineMetaInfo extends AbstractMetaInfo {
/** The version string for the pipeline. */
/**
* The version string for the pipeline.
*
* @deprecated since 2.20, for removal. The label has to be set and updated by hand and says
* nothing that the version control system holding the file does not already say more
* reliably. It is still read from and written to the file, so no existing value is lost
* before it is removed.
*/
@Deprecated(since = "2.20", forRemoval = true)
@HopMetadataProperty(key = "pipeline_version")
protected String pipelineVersion;

Expand All @@ -42,7 +50,15 @@ public class PipelineMetaInfo extends AbstractMetaInfo {
@HopMetadataProperty(key = "transform_performance_capturing_size_limit")
protected String transformPerformanceCapturingSizeLimit;

/** The status of the pipeline. */
/**
* The status of the pipeline: {@code 1} for draft, {@code 2} for production, {@code -1} when
* unset.
*
* @deprecated since 2.20, for removal. Nothing in Hop acts on the value, it has to be maintained
* by hand, and it is left at {@code -1} in practice. It is still read from and written to the
* file, so no existing value is lost before it is removed.
*/
@Deprecated(since = "2.20", forRemoval = true)
@HopMetadataProperty(key = "pipeline_status")
protected int pipelineStatus;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ public class WorkflowMeta extends AbstractMeta
@HopMetadataProperty(inline = true)
protected WorkflowMetaInfo info;

/**
* The version string for the workflow.
*
* @deprecated since 2.20, for removal. The label has to be set and updated by hand and says
* nothing that the version control system holding the file does not already say more
* reliably. It is still read from and written to the file, so no existing value is lost
* before it is removed.
*/
@Deprecated(since = "2.20", forRemoval = true)
Comment thread
mattcasters marked this conversation as resolved.
Outdated
@HopMetadataProperty(key = "workflow_version")
protected String workflowVersion;

Expand Down
Loading
Loading