fix: 新增只读属性

This commit is contained in:
wangyu 2021-03-21 11:49:29 +08:00
parent 41fb405723
commit 383f0630d3
5 changed files with 44 additions and 7 deletions

View File

@ -25,37 +25,39 @@ public abstract class AuditDomain extends Domain {
* 创建日期 * 创建日期
*/ */
@CreatedDate @CreatedDate
@Property("创建日期") @Property(value = "创建日期", readonly = true)
protected Date createTime; protected Date createTime;
/** /**
* 修改日期 * 修改日期
*/ */
@LastModifiedDate @LastModifiedDate
@Property("更新日期") @Property(value = "更新日期", readonly = true)
protected Date modifyTime; protected Date modifyTime;
/** /**
* 创建者 * 创建者
*/ */
@CreatedBy @CreatedBy
@Property("创建人") @Property(value = "创建人", readonly = true)
protected String creator; protected String creator;
/** /**
* 创建人id * 创建人id
*/ */
@Property(readonly = true)
protected String creatorId; protected String creatorId;
/** /**
* 修改者 * 修改者
*/ */
@LastModifiedBy @LastModifiedBy
@Property("更新人") @Property(value = "更新人", readonly = true)
protected String modifier; protected String modifier;
/** /**
* 修改人id * 修改人id
*/ */
@Property(readonly = true)
protected String modifierId; protected String modifierId;
} }

View File

@ -23,21 +23,25 @@ public abstract class Domain implements Po, Serializable {
*/ */
@Id @Id
protected String id; protected String id;
/** /**
* 编号 * 编号
*/ */
@Property(title = "编码", inherited = true) @Property(title = "编码", inherited = true)
protected String code; protected String code;
/** /**
* 名称 * 名称
*/ */
@Indexed @Indexed
@Property(title = "名称", inherited = true) @Property(title = "名称", inherited = true)
protected String name; protected String name;
/** /**
* 上下文冗余利用内存缓存上下文 * 上下文冗余利用内存缓存上下文
*/ */
@Transient @Transient
@Property(readonly = true)
private User currentUser; private User currentUser;
@Override @Override

View File

@ -13,6 +13,7 @@ import com.flyfish.framework.handler.JsonAuthenticationSuccessHandler;
import com.flyfish.framework.handler.JsonLogoutSuccessHandler; import com.flyfish.framework.handler.JsonLogoutSuccessHandler;
import com.flyfish.framework.initializer.UserInitializer; import com.flyfish.framework.initializer.UserInitializer;
import com.flyfish.framework.service.AuthenticationAuditor; import com.flyfish.framework.service.AuthenticationAuditor;
import com.flyfish.framework.service.AuthenticationLogger;
import com.flyfish.framework.service.UserService; import com.flyfish.framework.service.UserService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@ -24,7 +25,9 @@ import org.springframework.http.HttpStatus;
import org.springframework.security.authentication.ReactiveAuthenticationManager; import org.springframework.security.authentication.ReactiveAuthenticationManager;
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity; import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
import org.springframework.security.config.web.server.ServerHttpSecurity; import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.userdetails.ReactiveUserDetailsService; import org.springframework.security.core.userdetails.ReactiveUserDetailsService;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.factory.PasswordEncoderFactories; import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.DelegatingPasswordEncoder; import org.springframework.security.crypto.password.DelegatingPasswordEncoder;
@ -33,6 +36,9 @@ import org.springframework.security.web.server.SecurityWebFilterChain;
import org.springframework.security.web.server.authentication.HttpStatusServerEntryPoint; import org.springframework.security.web.server.authentication.HttpStatusServerEntryPoint;
import org.springframework.security.web.server.context.ServerSecurityContextRepository; import org.springframework.security.web.server.context.ServerSecurityContextRepository;
import org.springframework.security.web.server.context.WebSessionServerSecurityContextRepository; import org.springframework.security.web.server.context.WebSessionServerSecurityContextRepository;
import org.springframework.util.MultiValueMap;
import java.util.stream.Stream;
import static org.springframework.security.web.server.util.matcher.ServerWebExchangeMatchers.pathMatchers; import static org.springframework.security.web.server.util.matcher.ServerWebExchangeMatchers.pathMatchers;
@ -63,6 +69,27 @@ public class WebSecurityConfig {
return new AuthenticationAuditorImpl(); return new AuthenticationAuditorImpl();
} }
@Bean
@ConditionalOnMissingBean(AuthenticationLogger.class)
public AuthenticationLogger authenticationLogger() {
return new AuthenticationLogger() {
@Override
public void success(UserDetails user) {
}
@Override
public void failure(MultiValueMap<String, String> form, AuthenticationException exception) {
}
@Override
public void logout(UserDetails user) {
}
};
}
@ConditionalOnProperty(value = "jwt.enable", havingValue = "true") @ConditionalOnProperty(value = "jwt.enable", havingValue = "true")
@Bean("contextRepository") @Bean("contextRepository")
public JwtSecurityContextRepository jwtSecurityContextRepository() { public JwtSecurityContextRepository jwtSecurityContextRepository() {
@ -97,8 +124,8 @@ public class WebSecurityConfig {
http http
.securityContextRepository(contextRepository()) .securityContextRepository(contextRepository())
.authorizeExchange() .authorizeExchange()
.pathMatchers(properties.getAllowUris()).permitAll() .pathMatchers(Stream.concat(Stream.of(properties.getAllowUris()), Stream.of("/api/logout", "/api/login"))
.pathMatchers("/api/logout", "/api/login").permitAll() .toArray(String[]::new)).permitAll()
.pathMatchers("/api/users/**").authenticated() .pathMatchers("/api/users/**").authenticated()
.anyExchange().authenticated() .anyExchange().authenticated()
.and() .and()

View File

@ -32,6 +32,9 @@ public class BeanProperty {
// bean属性的类型js类型 // bean属性的类型js类型
private BeanPropertyType type; private BeanPropertyType type;
// 只读属性不生成于表单
private boolean readonly;
// 属性 // 属性
private Map<String, Object> props; private Map<String, Object> props;
@ -48,6 +51,7 @@ public class BeanProperty {
return Arrays.stream(descriptors) return Arrays.stream(descriptors)
.filter(descriptor -> !"class".equals(descriptor.getName())) .filter(descriptor -> !"class".equals(descriptor.getName()))
.map(descriptor -> BeanProperty.form(descriptor, clazz)) .map(descriptor -> BeanProperty.form(descriptor, clazz))
.filter(property -> !property.isReadonly())
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@ -71,6 +75,7 @@ public class BeanProperty {
String parentName = Optional.ofNullable(beanClass.getAnnotation(RestBean.class)).map(RestBean::name).orElse(""); String parentName = Optional.ofNullable(beanClass.getAnnotation(RestBean.class)).map(RestBean::name).orElse("");
property.setTitle(props.inherited() ? parentName + props.title() : props.title()); property.setTitle(props.inherited() ? parentName + props.title() : props.title());
property.setDescription(props.description()); property.setDescription(props.description());
property.setReadonly(props.readonly());
} }
} }
Class<?> clazz = descriptor.getPropertyType(); Class<?> clazz = descriptor.getPropertyType();

View File

@ -1,6 +1,5 @@
package com.flyfish.framework.service; package com.flyfish.framework.service;
import com.flyfish.framework.domain.po.User;
import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;