feat: align local accounts with pevc
parent
3a410e286f
commit
031a8a3998
@ -1,36 +0,0 @@
|
||||
package com.yau.digitalrmb.identity.application;
|
||||
|
||||
import com.yau.digitalrmb.platformintegration.application.PlatformCredentialRepository;
|
||||
import com.yau.digitalrmb.platformintegration.application.PlatformIdentityRepository;
|
||||
import com.yau.digitalrmb.platformintegration.config.PlatformIntegrationProperties;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Profile("local")
|
||||
public class PlatformCredentialInitializer implements ApplicationRunner {
|
||||
private final PlatformIntegrationProperties.LocalLogin properties;
|
||||
private final PlatformIdentityRepository identityRepository;
|
||||
private final PlatformCredentialRepository credentialRepository;
|
||||
private final PlatformIdentityProjectionService projectionService;
|
||||
|
||||
public PlatformCredentialInitializer(PlatformIntegrationProperties properties,
|
||||
PlatformIdentityRepository identityRepository,
|
||||
PlatformCredentialRepository credentialRepository,
|
||||
PlatformIdentityProjectionService projectionService) {
|
||||
this.properties = properties.getLocalLogin();
|
||||
this.identityRepository = identityRepository;
|
||||
this.credentialRepository = credentialRepository;
|
||||
this.projectionService = projectionService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
properties.getInitialAccounts().stream().filter(account -> account != null && !account.isBlank())
|
||||
.forEach(account -> identityRepository.findBySchoolAccount(account)
|
||||
.flatMap(actor -> credentialRepository.findCredential(actor.platformUserId()))
|
||||
.ifPresent(projectionService::project));
|
||||
}
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
package com.yau.digitalrmb.platformintegration.application;
|
||||
|
||||
import com.yau.digitalrmb.platformintegration.domain.PlatformCredential;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface PlatformCredentialRepository {
|
||||
Optional<PlatformCredential> findCredential(long platformUserId);
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
package com.yau.digitalrmb.platformintegration.domain;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record PlatformCredential(PlatformActor actor, String rawPassword) {
|
||||
public PlatformCredential {
|
||||
Objects.requireNonNull(actor, "actor must not be null");
|
||||
if (rawPassword == null || rawPassword.isBlank()) {
|
||||
throw new IllegalArgumentException("rawPassword must not be blank");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PlatformCredential[actor=" + actor + ", rawPassword=<redacted>]";
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
INSERT INTO sys_user (id, username, password_hash, enabled, created_at, updated_at, created_by, updated_by, deleted)
|
||||
VALUES (487, 'tzs001', '$2a$10$ufcw5KFHtOmLzxAsV4C.MuIDOErMlw0iw5J5hc8OMzaTx0u9QYxG6', TRUE,
|
||||
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'SYSTEM', 'SYSTEM', FALSE)
|
||||
ON DUPLICATE KEY UPDATE username = VALUES(username), password_hash = VALUES(password_hash), enabled = TRUE,
|
||||
updated_at = CURRENT_TIMESTAMP, updated_by = 'SYSTEM', deleted = FALSE;
|
||||
|
||||
INSERT INTO platform_user_snapshot (platform_user_id, account, display_name, role_key, source_updated_at, synced_at)
|
||||
VALUES (487, 'tzs001', 'tzs001', 'STUDENT', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
|
||||
ON DUPLICATE KEY UPDATE account = VALUES(account), display_name = VALUES(display_name), role_key = VALUES(role_key),
|
||||
source_updated_at = CURRENT_TIMESTAMP, synced_at = CURRENT_TIMESTAMP;
|
||||
|
||||
INSERT IGNORE INTO sys_user_role (user_id, role_id) VALUES (487, 1002);
|
||||
@ -1,41 +0,0 @@
|
||||
package com.yau.digitalrmb.identity;
|
||||
|
||||
import com.yau.digitalrmb.identity.application.PlatformCredentialInitializer;
|
||||
import com.yau.digitalrmb.identity.application.PlatformIdentityProjectionService;
|
||||
import com.yau.digitalrmb.platformintegration.application.PlatformCredentialRepository;
|
||||
import com.yau.digitalrmb.platformintegration.application.PlatformIdentityRepository;
|
||||
import com.yau.digitalrmb.platformintegration.config.PlatformIntegrationProperties;
|
||||
import com.yau.digitalrmb.platformintegration.domain.PlatformActor;
|
||||
import com.yau.digitalrmb.platformintegration.domain.PlatformCredential;
|
||||
import com.yau.digitalrmb.platformintegration.domain.PlatformRole;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.DefaultApplicationArguments;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class PlatformCredentialInitializerTest {
|
||||
@Test
|
||||
void initializesOnlyConfiguredPlatformAccount() throws Exception {
|
||||
PlatformIdentityRepository identities = mock(PlatformIdentityRepository.class);
|
||||
PlatformCredentialRepository credentials = mock(PlatformCredentialRepository.class);
|
||||
PlatformIdentityProjectionService projection = mock(PlatformIdentityProjectionService.class);
|
||||
PlatformIntegrationProperties properties = new PlatformIntegrationProperties();
|
||||
properties.getLocalLogin().setInitialAccounts(List.of("tzs001"));
|
||||
PlatformActor actor = new PlatformActor(301L, 3L, "tzs001", "教师", PlatformRole.TEACHER,
|
||||
Instant.parse("2026-01-01T00:00:00Z"));
|
||||
PlatformCredential credential = new PlatformCredential(actor, "123qwe");
|
||||
when(identities.findBySchoolAccount("tzs001")).thenReturn(Optional.of(actor));
|
||||
when(credentials.findCredential(301L)).thenReturn(Optional.of(credential));
|
||||
|
||||
new PlatformCredentialInitializer(properties, identities, credentials, projection)
|
||||
.run(new DefaultApplicationArguments());
|
||||
|
||||
verify(projection).project(credential);
|
||||
}
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
package com.yau.digitalrmb.platformintegration.domain;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class PlatformCredentialTest {
|
||||
@Test
|
||||
void stringRepresentationRedactsRawPassword() {
|
||||
PlatformActor actor = new PlatformActor(301L, 3L, "tzs001", "教师", PlatformRole.TEACHER,
|
||||
Instant.parse("2026-01-01T00:00:00Z"));
|
||||
|
||||
PlatformCredential credential = new PlatformCredential(actor, "123qwe");
|
||||
|
||||
assertThat(credential.toString()).contains("<redacted>").doesNotContain("123qwe");
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue