标签:lse audit lis jks modify The named bean classpath
@Configuration
public class CommonConfiguration implements AuditorAware<String> {
/**
* Get current auditor
* @return Auditor Optional object
*/
@Override
public Optional<String> getCurrentAuditor() {
//Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
//if (authentication == null) {
// return Optional.of("Unknown");
//} else if (!authentication.isAuthenticated()) {
// return Optional.of("Unauthenticated");
//} else {
// UserDetails userDetails = (UserDetails) authentication.getPrincipal();
// return Optional.of(userDetails.getUsername());
//}
return Optional.of("system");
}
}
Fucking Lombok...
/**
* For database auditing
* Could not audit remove operating
*
* @author seliote
* @since 2019-10-19
*/
// Designates its child class applied the mapping info, and had no separate table defined for it
@MappedSuperclass
// Enable auto @PrePersist & @PreUpdate
@EntityListeners(AuditingEntityListener.class)
// Hibernate change delete sql before execute, there could not get table name
public class Auditable {
// Row create user
@CreatedBy
@Column(name = "create_user")
private String createUser;
// Row create date
@CreatedDate
@Column(name = "create_date")
private LocalDateTime createDate;
// Row modify user
@LastModifiedBy
@Column(name = "modify_user")
private String modifyUser;
// Row modify date
@LastModifiedDate
@Column(name = "modify_date")
private LocalDateTime modifyDate;
// Delete mark, this field could auto audit, should manual update in every entity
@Column(name = "delete_mark")
private boolean deleteMark;
public String getCreateUser() {
return createUser;
}
public void setCreateUser(String createUser) {
this.createUser = createUser;
}
public LocalDateTime getCreateDate() {
return createDate;
}
public void setCreateDate(LocalDateTime createDate) {
this.createDate = createDate;
}
public String getModifyUser() {
return modifyUser;
}
public void setModifyUser(String modifyUser) {
this.modifyUser = modifyUser;
}
public LocalDateTime getModifyDate() {
return modifyDate;
}
public void setModifyDate(LocalDateTime modifyDate) {
this.modifyDate = modifyDate;
}
public boolean isDeleteMark() {
return deleteMark;
}
public void setDeleteMark(boolean deleteMark) {
this.deleteMark = deleteMark;
}
}
JPA annotation should in FIELD not GETTER, otherwise the method extended named get... will also mapping to database column
/**
* Admin entity
*
* @author seliote
* @since 2019-10-19
*/
@Entity
@Table(name = "admin")
@Where(clause = "delete_mark = 0")
@SQLDelete(sql = "UPDATE `admin` SET `delete_mark` = 1 WHERE `uuid` = ?")
public class AdminEntity extends Auditable implements UserDetails {
// Admin uuid, primary key
@Id
@Column(name = "uuid")
private String uuid;
// Admin name, login name
@Column(name = "user")
private String user;
// Admin password, login password
@Column(name = "password")
private String password;
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
@Override
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
// Grant ADMIN authority
return Arrays.asList(new SimpleGrantedAuthority(Constant.Security.Authority.ADMIN));
}
@Override
public String getUsername() {
return getUser();
}
@Override
public boolean isAccountNonExpired() {
return true;
}
@Override
public boolean isAccountNonLocked() {
return true;
}
@Override
public boolean isCredentialsNonExpired() {
return true;
}
@Override
public boolean isEnabled() {
return true;
}
}
This line defualt in application.properties, otherwise need @PropertySource
com.seliote.productId=666
Could inject this component to other bean and use getter
/**
* Inject all properties
*
* @author seliote
* @since 2019-10-20
*/
@Component
@ConfigurationProperties(prefix = "com.seliote")
public class PropertyConfiguration {
private String productId;
public String getProductId() {
return productId;
}
public void setProductId(String productId) {
this.productId = productId;
}
}
server:
# for embed Tomcat...
port: 8443
ssl:
key-store: classpath:cert/demo.jks
key-password: drowssap321
key-store-password: drowssap123
标签:lse audit lis jks modify The named bean classpath
原文地址:https://www.cnblogs.com/seliote/p/11741204.html