Remove unused TenantUserPasswordAuthenticationToken (#1966)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-11-08 12:29:19 +02:00
committed by GitHub
parent 03baf2a4c2
commit ade5723c8c
10 changed files with 99 additions and 223 deletions

View File

@@ -23,6 +23,11 @@ public interface BaseEntity extends Serializable, Identifiable<Long> {
return entity == null ? null : entity.getId();
}
/**
* @return user that created the {@link BaseEntity}.
*/
String getCreatedBy();
/**
* @return time in {@link TimeUnit#MILLISECONDS} when the {@link BaseEntity}
* was created.
@@ -30,9 +35,9 @@ public interface BaseEntity extends Serializable, Identifiable<Long> {
long getCreatedAt();
/**
* @return user that created the {@link BaseEntity}.
* @return user that updated the {@link BaseEntity} last.
*/
String getCreatedBy();
String getLastModifiedBy();
/**
* @return time in {@link TimeUnit#MILLISECONDS} when the {@link BaseEntity}
@@ -40,14 +45,8 @@ public interface BaseEntity extends Serializable, Identifiable<Long> {
*/
long getLastModifiedAt();
/**
* @return user that updated the {@link BaseEntity} last.
*/
String getLastModifiedBy();
/**
* @return version of the {@link BaseEntity}.
*/
int getOptLockRevision();
}
}

View File

@@ -9,6 +9,8 @@
*/
package org.eclipse.hawkbit.repository.jpa.model;
import java.io.Serial;
import jakarta.persistence.Access;
import jakarta.persistence.AccessType;
import jakarta.persistence.Column;
@@ -19,6 +21,9 @@ import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;
import jakarta.persistence.Version;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails;
import org.eclipse.hawkbit.repository.model.BaseEntity;
import org.springframework.data.annotation.CreatedBy;
@@ -31,32 +36,38 @@ import org.springframework.security.core.context.SecurityContextHolder;
/**
* Holder of the base attributes common to all entities.
*/
@NoArgsConstructor(access = AccessLevel.PROTECTED) // Default constructor needed for JPA entities.
@MappedSuperclass
@Access(AccessType.FIELD)
@EntityListeners({ AuditingEntityListener.class, EntityPropertyChangeListener.class, EntityInterceptorListener.class })
public abstract class AbstractJpaBaseEntity implements BaseEntity {
protected static final int USERNAME_FIELD_LENGTH = 64;
@Serial
private static final long serialVersionUID = 1L;
@Setter
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
private String createdBy;
private String lastModifiedBy;
private long createdAt;
private String lastModifiedBy;
private long lastModifiedAt;
@Setter
@Version
@Column(name = "optlock_revision")
private int optLockRevision;
/**
* Default constructor needed for JPA entities.
*/
protected AbstractJpaBaseEntity() {
// Default constructor needed for JPA entities.
@Override
@Access(AccessType.PROPERTY)
@Column(name = "created_by", updatable = false, nullable = false, length = USERNAME_FIELD_LENGTH)
public String getCreatedBy() {
return createdBy;
}
@Override
@@ -68,9 +79,9 @@ public abstract class AbstractJpaBaseEntity implements BaseEntity {
@Override
@Access(AccessType.PROPERTY)
@Column(name = "created_by", updatable = false, nullable = false, length = USERNAME_FIELD_LENGTH)
public String getCreatedBy() {
return createdBy;
@Column(name = "last_modified_by", nullable = false, length = USERNAME_FIELD_LENGTH)
public String getLastModifiedBy() {
return lastModifiedBy;
}
@Override
@@ -80,41 +91,11 @@ public abstract class AbstractJpaBaseEntity implements BaseEntity {
return lastModifiedAt;
}
@Override
@Access(AccessType.PROPERTY)
@Column(name = "last_modified_by", nullable = false, length = USERNAME_FIELD_LENGTH)
public String getLastModifiedBy() {
return lastModifiedBy;
}
@LastModifiedBy
public void setLastModifiedBy(final String lastModifiedBy) {
if (isController()) {
return;
}
this.lastModifiedBy = lastModifiedBy;
}
@Override
public int getOptLockRevision() {
return optLockRevision;
}
public void setOptLockRevision(final int optLockRevision) {
this.optLockRevision = optLockRevision;
}
@LastModifiedDate
public void setLastModifiedAt(final long lastModifiedAt) {
if (isController()) {
return;
}
this.lastModifiedAt = lastModifiedAt;
}
@CreatedBy
public void setCreatedBy(final String createdBy) {
if (isController()) {
@@ -142,15 +123,29 @@ public abstract class AbstractJpaBaseEntity implements BaseEntity {
}
}
@LastModifiedBy
public void setLastModifiedBy(final String lastModifiedBy) {
if (isController()) {
return;
}
this.lastModifiedBy = lastModifiedBy;
}
@LastModifiedDate
public void setLastModifiedAt(final long lastModifiedAt) {
if (isController()) {
return;
}
this.lastModifiedAt = lastModifiedAt;
}
@Override
public Long getId() {
return id;
}
public void setId(final Long id) {
this.id = id;
}
/**
* Defined equals/hashcode strategy for the repository in general is that an
* entity is equal if it has the same {@link #getId()} and
@@ -206,10 +201,7 @@ public abstract class AbstractJpaBaseEntity implements BaseEntity {
private boolean isController() {
return SecurityContextHolder.getContext().getAuthentication() != null
&& SecurityContextHolder.getContext().getAuthentication()
.getDetails() instanceof TenantAwareAuthenticationDetails
&& ((TenantAwareAuthenticationDetails) SecurityContextHolder.getContext().getAuthentication()
.getDetails()).isController();
&& SecurityContextHolder.getContext().getAuthentication().getDetails() instanceof TenantAwareAuthenticationDetails tenantAwareDetails
&& tenantAwareDetails.isController();
}
}
}

View File

@@ -154,7 +154,7 @@ public class SecurityContextSwitch {
authorities = annotation.authorities();
}
final TestingAuthenticationToken testingAuthenticationToken = new TestingAuthenticationToken(
new TenantAwareUser(annotation.principal(), annotation.tenantId()),
new TenantAwareUser(annotation.principal(), "***", null, annotation.tenantId()),
annotation.credentials(), authorities);
testingAuthenticationToken.setDetails(
new TenantAwareAuthenticationDetails(annotation.tenantId(), annotation.controller()));