Skip to content

Commit

Permalink
Merge pull request #8 from vnobo/dev
Browse files Browse the repository at this point in the history
开发合并主线
  • Loading branch information
vnobo authored Aug 1, 2024
2 parents 37bf25e + 69679ec commit 9c9a1cb
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
name: Gradle Build Package Image
name: Gradle Build Image
run-name: ${{ github.actor }} is bootBuildImage Actions
on:
release:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/gradle-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ jobs:

- name: Setup Gradle
uses: gradle/actions/setup-gradle@dbbdc275be76ac10734476cc723d82dfe7ec6eda

- name: Make gradlew executable
run: chmod +x ./gradlew

- name: Build with Gradle Wrapper
run: ./gradlew build test

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,34 +39,28 @@ protected <T> Flux<T> queryWithCache(Object key, String sql,
Flux<T> source = executeSpec
.map((row, rowMetadata) -> this.r2dbcConverter.read(entityClass, row, rowMetadata))
.all().flatMapSequential(ContextUtils::serializeUserAuditor);

return queryWithCache(key, source);
}

protected <T> Flux<T> queryWithCache(Object key, Flux<T> sourceFlux) {
String cacheKey = key + ":data";
Collection<T> cacheData = this.cache.get(cacheKey, ArrayList::new);
assert cacheData != null;

Flux<T> source = sourceFlux.doOnNext(cacheData::add)
.doAfterTerminate(() -> BeanUtils.cachePut(this.cache, cacheKey, cacheData));

return Flux.fromIterable(ObjectUtils.isEmpty(cacheData) ? Collections.emptyList() : cacheData)
.switchIfEmpty(Flux.defer(() -> source));
}

protected <T> Mono<Long> countWithCache(Object key, Query query, Class<T> entityClass) {
Mono<Long> source = this.entityTemplate.count(query, entityClass);
return countWithCache(key, source).cache();

}

protected Mono<Long> countWithCache(Object key, String sql, Map<String, Object> bindParams) {
var executeSpec = this.databaseClient.sql(() -> sql);
executeSpec = executeSpec.bindValues(bindParams);

Mono<Long> source = executeSpec.mapValue(Long.class).first();

return countWithCache(key, source);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.base.CaseFormat;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.plate.boot.commons.utils.BeanUtils;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
Expand Down Expand Up @@ -107,7 +108,7 @@ public static ParamSql buildParamSql(Map<String, Object> objectMap, String prefi
public static Criteria build(Object object, Collection<String> skipKes) {
Map<String, Object> objectMap = BeanUtils.beanToMap(object, true);
if (!ObjectUtils.isEmpty(objectMap)) {
Set<String> mergeSet = new HashSet<>(SKIP_CRITERIA_KEYS);
Set<String> mergeSet = Sets.newHashSet(SKIP_CRITERIA_KEYS);
if (!ObjectUtils.isEmpty(skipKes)) {
mergeSet.addAll(skipKes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public RedisCacheManagerBuilderCustomizer myRedisCacheManagerBuilderCustomizer(O
.fromSerializer(new StringRedisSerializer()))
.serializeValuesWith(RedisSerializationContext.SerializationPair
.fromSerializer(new Jackson2JsonRedisSerializer<>(objectMapper, Object.class)));

}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import java.util.List;
import java.util.Set;

import static com.plate.boot.commons.utils.ContextUtils.RULE_ADMINISTRATORS;
import static com.plate.boot.config.SessionConfiguration.XML_HTTP_REQUEST;
import static com.plate.boot.config.SessionConfiguration.X_REQUESTED_WITH;

Expand Down Expand Up @@ -97,14 +98,14 @@ public PayloadSocketAcceptorInterceptor rsocketInterceptor(RSocketSecurity rsock
@Bean
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
http.authorizeExchange(exchange -> {
exchange.pathMatchers("/captcha/code", "/oauth2/qr/code", "/oauth2/realms/issuer/**").permitAll();
exchange.pathMatchers("/captcha/code", "/oauth2/qr/code").permitAll();
exchange.matchers(PathRequest.toStaticResources().atCommonLocations()).permitAll();
exchange.anyExchange().authenticated();
});
http.sessionManagement((sessions) -> sessions
.concurrentSessions((concurrency) -> concurrency.maximumSessions((authentication) -> {
if (authentication.getAuthorities().stream()
.anyMatch(a -> "ROLE_SYSTEM_ADMINISTRATORS".equals(a.getAuthority()))) {
.anyMatch(a -> RULE_ADMINISTRATORS.equals(a.getAuthority()))) {
return Mono.empty();
}
return Mono.just(3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class Menu implements BaseEntity<Integer> {
private MenuType type;

@NotBlank(message = "Authority cannot be blank!")
@Pattern(regexp = "^[a-zA-Z_]{1,50}$", message = "Authority can only contain English letters or '_' symbols.")
@Pattern(regexp = "^[a-zA-Z_]{1,256}$", message = "Authority can only contain English letters or '_' symbols.")
private String authority;

@NotBlank(message = "Name cannot be blank!")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.plate.boot.relational.rsocket;

import com.plate.boot.commons.utils.ContextUtils;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
* @author <a href="https://github.com/vnobo">Alex Bob</a>
Expand All @@ -12,6 +14,8 @@
@NoArgsConstructor
public class MessageIn implements Serializable {

private String code;
private LocalDateTime time;
private MessageType type;
private String content;
private Object data;
Expand All @@ -22,6 +26,8 @@ public MessageIn(MessageType type, String content, Object data) {
this.type = type;
this.content = content;
this.data = data;
this.data = ContextUtils.nextId();
this.time = LocalDateTime.now();
}

public static MessageIn of(MessageType type, String content, Object data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class SecurityController {
private final WebSessionServerSecurityContextRepository securityContextRepository =
new WebSessionServerSecurityContextRepository();

private final UserSecurityManager userSecurityManager;
private final SecurityManager securityManager;
private final PasswordEncoder passwordEncoder;
private final ServerOAuth2AuthorizedClientRepository clientRepository;

Expand Down Expand Up @@ -68,7 +68,7 @@ public Mono<UserDetails> changePassword(@Valid @RequestBody ChangePasswordReques
}
String newPassword = this.passwordEncoder.encode(request.getNewPassword());
UserDetails userDetails = (UserDetails) authentication.getDetails();
return this.userSecurityManager.updatePassword(userDetails, newPassword);
return this.securityManager.updatePassword(userDetails, newPassword);
}

@Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
@Log4j2
@Service
@RequiredArgsConstructor
public class UserSecurityManager extends AbstractDatabase
public class SecurityManager extends AbstractDatabase
implements ReactiveUserDetailsService, ReactiveUserDetailsPasswordService {

private final static String QUERY_GROUP_MEMBERS_SQL = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.plate.boot.commons.utils.ContextUtils;
import com.plate.boot.security.SecurityDetails;
import com.plate.boot.security.UserSecurityManager;
import com.plate.boot.security.SecurityManager;
import com.plate.boot.security.core.user.User;
import com.plate.boot.security.core.user.UserRequest;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -32,7 +32,7 @@ public class Oauth2UserService extends DefaultReactiveOAuth2UserService {

private static final SecureRandom SECURE_RANDOM = new SecureRandom();

private final UserSecurityManager userSecurityManager;
private final SecurityManager securityManager;

public static String generateRandoPassword() {
byte[] randomBytes = new byte[16];
Expand All @@ -49,7 +49,7 @@ public Mono<OAuth2User> loadUser(OAuth2UserRequest userRequest) throws OAuth2Aut
}

public Mono<OAuth2User> loadLocalUser(String registrationId, OAuth2User oAuth2User) {
return this.userSecurityManager.loadByOauth2(registrationId, oAuth2User.getName())
return this.securityManager.loadByOauth2(registrationId, oAuth2User.getName())
.delayUntil(user -> this.modifyUser(user, registrationId, oAuth2User))
.switchIfEmpty(Mono.defer(() -> this.registerUser(registrationId, oAuth2User)))
.map(user -> this.convertToOauth2User(user, oAuth2User));
Expand All @@ -69,12 +69,12 @@ public Mono<Void> modifyUser(User user, String registrationId, OAuth2User oAuth2
oauth2.set("registrationId", request.getExtend().get("oauth2").get(registrationId));
oldExtend.set("oauth2", oauth2);
request.setExtend(oldExtend);
return this.userSecurityManager.registerOrModifyUser(request).then();
return this.securityManager.registerOrModifyUser(request).then();
}

public Mono<User> registerUser(String registrationId, OAuth2User oAuth2User) {
var request = this.convertToUserRequest(registrationId, oAuth2User);
return this.userSecurityManager.registerOrModifyUser(request);
return this.securityManager.registerOrModifyUser(request);
}

public UserRequest convertToUserRequest(String registrationId, OAuth2User oAuth2User) {
Expand Down

0 comments on commit 9c9a1cb

Please sign in to comment.