feat: add platform integration configuration
parent
45a5f637c5
commit
10a66eca1f
@ -0,0 +1,72 @@
|
|||||||
|
package com.yau.digitalrmb.platformintegration.config;
|
||||||
|
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import jakarta.validation.constraints.AssertTrue;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Validated
|
||||||
|
@ConfigurationProperties("platform-integration")
|
||||||
|
public class PlatformIntegrationProperties {
|
||||||
|
@Valid
|
||||||
|
private Datasource datasource = new Datasource();
|
||||||
|
@Valid
|
||||||
|
private Token token = new Token();
|
||||||
|
@Valid
|
||||||
|
private Cas cas = new Cas();
|
||||||
|
@Valid
|
||||||
|
private Frontend frontend = new Frontend();
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public static class Datasource {
|
||||||
|
@NotBlank
|
||||||
|
private String url;
|
||||||
|
@NotBlank
|
||||||
|
private String username;
|
||||||
|
@NotBlank
|
||||||
|
private String password;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public static class Token {
|
||||||
|
@NotNull
|
||||||
|
private Duration maxAge;
|
||||||
|
@NotBlank
|
||||||
|
private String teacherClaimValue;
|
||||||
|
@NotBlank
|
||||||
|
private String studentClaimValue;
|
||||||
|
|
||||||
|
@AssertTrue(message = "token.max-age must be positive")
|
||||||
|
public boolean isMaxAgePositive() {
|
||||||
|
return maxAge != null && !maxAge.isNegative() && !maxAge.isZero();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public static class Cas {
|
||||||
|
@NotBlank
|
||||||
|
private String loginUrl;
|
||||||
|
@NotBlank
|
||||||
|
private String validateUrl;
|
||||||
|
@NotBlank
|
||||||
|
private String callbackUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public static class Frontend {
|
||||||
|
@NotBlank
|
||||||
|
private String callbackUrl;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
package com.yau.digitalrmb.platformintegration.domain;
|
||||||
|
|
||||||
|
public enum PlatformRole {
|
||||||
|
TEACHER("JT_S_02"),
|
||||||
|
STUDENT("JT_S_03");
|
||||||
|
|
||||||
|
private final String jobType;
|
||||||
|
|
||||||
|
PlatformRole(String jobType) {
|
||||||
|
this.jobType = jobType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PlatformRole fromJobType(String jobType) {
|
||||||
|
for (PlatformRole role : values()) {
|
||||||
|
if (role.jobType.equals(jobType)) {
|
||||||
|
return role;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("Unsupported platform job type: " + jobType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String jobType() {
|
||||||
|
return jobType;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,43 @@
|
|||||||
|
package com.yau.digitalrmb.platformintegration.config;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
class PlatformIntegrationPropertiesTest {
|
||||||
|
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||||
|
.withConfiguration(AutoConfigurations.of(PropertiesConfiguration.class))
|
||||||
|
.withPropertyValues(
|
||||||
|
"platform-integration.datasource.url=jdbc:mysql://localhost:3306/tianze",
|
||||||
|
"platform-integration.datasource.username=readonly",
|
||||||
|
"platform-integration.datasource.password=secret",
|
||||||
|
"platform-integration.token.max-age=PT2M",
|
||||||
|
"platform-integration.token.teacher-claim-value=teacher",
|
||||||
|
"platform-integration.token.student-claim-value=student",
|
||||||
|
"platform-integration.cas.login-url=https://sso.example.edu/login",
|
||||||
|
"platform-integration.cas.validate-url=https://sso.example.edu/p3/serviceValidate",
|
||||||
|
"platform-integration.cas.callback-url=https://rmb.example.edu/api/v1/auth/cas/callback",
|
||||||
|
"platform-integration.frontend.callback-url=https://rmb.example.edu/sso-callback");
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void bindsReadOnlyDatasourceAndAuthenticationEndpoints() {
|
||||||
|
contextRunner.run(context -> {
|
||||||
|
PlatformIntegrationProperties properties = context.getBean(PlatformIntegrationProperties.class);
|
||||||
|
|
||||||
|
assertThat(properties.getDatasource().getUsername()).isEqualTo("readonly");
|
||||||
|
assertThat(properties.getToken().getMaxAge()).isEqualTo(Duration.ofMinutes(2));
|
||||||
|
assertThat(properties.getCas().getCallbackUrl()).isEqualTo("https://rmb.example.edu/api/v1/auth/cas/callback");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@EnableConfigurationProperties(PlatformIntegrationProperties.class)
|
||||||
|
static class PropertiesConfiguration {
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
package com.yau.digitalrmb.platformintegration.domain;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
|
|
||||||
|
class PlatformRoleTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void mapsOnlyTeacherAndStudentJobTypes() {
|
||||||
|
assertThat(PlatformRole.fromJobType("JT_S_02")).isEqualTo(PlatformRole.TEACHER);
|
||||||
|
assertThat(PlatformRole.fromJobType("JT_S_03")).isEqualTo(PlatformRole.STUDENT);
|
||||||
|
assertThatThrownBy(() -> PlatformRole.fromJobType("JT_S_01"))
|
||||||
|
.isInstanceOf(IllegalArgumentException.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue