diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8af972c --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +/gradlew text eol=lf +*.bat text eol=crlf +*.jar binary diff --git a/.gitea/PULL_REQUEST_TEMPLATE.md b/.gitea/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..79564cf --- /dev/null +++ b/.gitea/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,11 @@ +## 问题与结果 + +说明触发场景和最终行为。 + +## 验证 + +分别记录 JVM 测试、Native 构建、原生集成测试,以及尚未验证的内容。 + +## 部署与文档 + +说明配置或数据迁移、回退方式;涉及 homelab 部署或状态时关联源码与 wiki。 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8e21a87 --- /dev/null +++ b/.gitignore @@ -0,0 +1,42 @@ +HELP.md +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +.env +.env.* +!.env.example +*.log diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..ec7c712 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,10 @@ +# Agent Notes + +- 默认中文维护项目文档、commit、issue 和 PR;代码与上游 API 名称保留英文。 +- 项目使用 Java 与 Spring;Native 是交付约束,不是可选优化,不引入 Kotlin。 +- 变更需通过适用的 JVM 测试和 Native 集成测试;未执行的验证明确报告。 +- 只实现当前任务范围。Hydra 负责签发,首轮 AD 负责身份和组,本服务独立于 Ayatori。 +- 不把 LDAP 密码成功当成完整 MFA 成功;所有因素绑定同一主体与认证事务。 +- 不提交凭据、MFA secret、生产配置秘密或包含上述内容的测试输出。 +- 生产部署配置属于 homelab-infra;本仓库初始化不授权切换现役登录入口。 +- 文档区分计划、实现、Native 实测和人类验收,禁止将代码存在当成部署证据。 diff --git a/README.md b/README.md index e7c8f9f..3ba200f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,62 @@ # iam-login -独立 IAM 登录与认证服务:Java、Spring Security、GraalVM Native,衔接 AD/MFA 与 Hydra \ No newline at end of file +独立 IAM 的登录与认证服务,以 Java、Spring Security 和 GraalVM Native 实现,作为 +Hydra 的 Login/Consent 应用。当前已生成 Spring Initializr 骨架,尚未实现 AD、MFA 与 Hydra 登录链路。 + +## 职责与边界 + +- 首轮直接连接 Samba AD:验证人类凭据、查询用户与组,沿用已有组名。 +- 处理人类 MFA、认证事务及稳定主体映射,完成 Hydra Login/Consent。 +- OAuth2/OIDC 协议与下游 token 签发由 Hydra 提供。 +- 独立于 Ayatori;Ayatori 是 IAM 消费者,不是本服务运行依赖。 +- AD 继续作为首轮用户与组权威;迁移目录、统一组模型及 machine/agent 入口留在后续。 + +```text +应用 → Hydra → iam-login → Samba AD + MFA + ↑ │ + └────────┘ 接受 Login/Consent +``` + +现役 Gitea 人类登录仍使用 homelab-infra 中的 Go OIDC 上游适配器和 Authelia,已通过 +维护者验收。创建本仓库不表示切换生产认证入口,也不改变现有 Gitea 账号关联。 + +## 代码与部署归属 + +本仓库负责应用源码、测试、依赖、Native 构建与发布。环境部署配置、域名、网络策略和 +外部秘密引用留在 [homelab-infra](https://git.ddupan.top/panxiao81/homelab-infra)。 +跨服务状态与运维知识维护在 +[homelab-wiki](https://git.ddupan.top/panxiao81/homelab-wiki/src/branch/main/services/hydra.md)。 + +## 技术选型 + +优先 Java 和熟悉的 Spring 生态,不引入 Kotlin。阻碍 Java 选型的是 JVM 部署与运行 +开销,满足功能和资源要求的 Native 应用仍为优先选择。项目使用 Java 25、Spring Boot +4.1.1 和 Gradle;Spring Security 等库由 Boot BOM 管理,插件版本在 build.gradle 中固定。 +Native 使用 GraalVM 25。 + +Native 构建与原生二进制上的认证测试是交付要求;JVM 测试通过或 native 编译成功都不 +单独构成验收。Keycloak 可作为流程与安全边界参考,不以它采用 Quarkus 作为 native +兼容性证据,不直接引入其服务端 SPI 和模型。 + +见 [Native 验证范围](docs/native-validation.md)和[首轮实现 issue #1](https://git.ddupan.top/panxiao81/iam-login/issues/1)。 + +## 开发骨架 + +项目由 [Spring Initializr](https://start.spring.io) 生成,参数和复现方法见 +[项目初始化](docs/bootstrap.md)。使用 JDK 25 执行: + +```sh +./gradlew test +./gradlew bootRun +``` + +测试需要可用的 Docker,生成器配置了 Grafana LGTM Testcontainer。 +当前只有默认应用和上下文测试,默认 Spring Security 登录页不是可用的 IAM 登录流程。 +使用 GraalVM 25 验证原生测试与编译: + +```sh +./gradlew nativeTest +./gradlew nativeCompile +``` + +这些是构建入口,不代表完整认证链路已通过 Native 验收。 diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..3639334 --- /dev/null +++ b/build.gradle @@ -0,0 +1,53 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '4.1.1' + id 'io.spring.dependency-management' version '1.1.7' + id 'org.graalvm.buildtools.native' version '1.1.8' +} + +group = 'top.ddupan.iam' +version = '0.0.1-SNAPSHOT' +description = 'Independent IAM login and authentication service for Hydra' + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(25) + } +} + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-actuator' + implementation 'org.springframework.boot:spring-boot-starter-data-ldap' + implementation 'org.springframework.boot:spring-boot-starter-opentelemetry' + implementation 'org.springframework.boot:spring-boot-starter-security' + implementation 'org.springframework.boot:spring-boot-starter-validation' + implementation 'org.springframework.boot:spring-boot-starter-webmvc' + implementation 'org.springframework.security:spring-security-webauthn' + compileOnly 'org.projectlombok:lombok' + developmentOnly 'org.springframework.boot:spring-boot-devtools' + runtimeOnly 'io.micrometer:micrometer-registry-prometheus' + annotationProcessor 'org.projectlombok:lombok' + annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' + testImplementation 'org.springframework.boot:spring-boot-starter-actuator-test' + testImplementation 'org.springframework.boot:spring-boot-starter-data-ldap-test' + testImplementation 'org.springframework.boot:spring-boot-starter-ldap' + testImplementation 'org.springframework.boot:spring-boot-starter-opentelemetry-test' + testImplementation 'org.springframework.boot:spring-boot-starter-security-test' + testImplementation 'org.springframework.boot:spring-boot-starter-validation-test' + testImplementation 'org.springframework.boot:spring-boot-starter-webmvc-test' + testImplementation 'org.springframework.boot:spring-boot-testcontainers' + testImplementation 'com.unboundid:unboundid-ldapsdk' + testImplementation 'org.testcontainers:testcontainers-grafana' + testImplementation 'org.testcontainers:testcontainers-junit-jupiter' + testCompileOnly 'org.projectlombok:lombok' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' + testAnnotationProcessor 'org.projectlombok:lombok' +} + +tasks.named('test') { + useJUnitPlatform() +} diff --git a/docs/bootstrap.md b/docs/bootstrap.md new file mode 100644 index 0000000..df37df5 --- /dev/null +++ b/docs/bootstrap.md @@ -0,0 +1,67 @@ +# 项目初始化 + +2026-09-25 使用 start.spring.io API 生成,选择当时默认正式版 Spring Boot 4.1.1、 +Java 25、Gradle Groovy DSL、YAML 配置和 Jar。应用包名为 `top.ddupan.iam.login`。 + +```sh +curl -fsSLG https://start.spring.io/starter.zip \ + --data-urlencode type=gradle-project \ + --data-urlencode language=java \ + --data-urlencode bootVersion=4.1.1 \ + --data-urlencode javaVersion=25 \ + --data-urlencode groupId=top.ddupan.iam \ + --data-urlencode artifactId=iam-login \ + --data-urlencode name=iam-login \ + --data-urlencode packageName=top.ddupan.iam.login \ + --data-urlencode 'description=Independent IAM login and authentication service for Hydra' \ + --data-urlencode packaging=jar \ + --data-urlencode configurationFileFormat=yaml \ + --data-urlencode dependencies=native,devtools,lombok,configuration-processor,web,security,spring-security-webauthn,data-ldap,validation,actuator,prometheus,opentelemetry,distributed-tracing,unboundid-ldap,testcontainers \ + -o iam-login-starter.zip +``` + +生成器提供 Gradle Wrapper、应用入口、上下文测试、依赖和 Native 构建插件。 +为生成的 `.gitignore` 补充秘密文件与日志忽略规则,以中文项目文档替代生成器的 `HELP.md`。 +Initializr 的可选版本会变化,未来可能需要调整请求;已提交源码、Gradle Wrapper 与插件版本是构建依据。 + +LDAP 和 WebAuthn 依赖尚未配置为真实认证流程;数据库和 MFA 凭据持久化随首轮实现引入。 +Actuator 与 Prometheus 依赖存在不等于监控端点已按生产策略开放。 + +## 骨架验证 + +构建环境为 `ghcr.io/graalvm/native-image-community:25`,固定 digest: +`sha256:0d936f32bb8acb5bc60c41b33e05f064d7a6aaf36b726538296c54949bd4a3c0`。 + +2026-09-25 在上述 GraalVM 容器(Java 25.0.2)中执行 `./gradlew --no-daemon --max-workers=4 test` +通过,包含测试 AOT 处理和 1 个 JVM 上下文测试。Grafana LGTM Testcontainer 实际启动成功。 +当前 Gradle 骨架的 `nativeCompile` 与 `nativeTest` 尚未执行,不声明 Native 已通过。 + +生成的上下文测试通过 Testcontainers 启动 Grafana LGTM,需访问 Docker。 +它不连接真实 AD 或 Hydra,也不验证 MFA。Native 骨架测试不代替完整认证链路验收。 + +## Docker 开发与 Gradle 缓存 + +Linux 主机示例:将缓存保留在宿主机用户缓存目录,避免每次临时容器重新下载 Wrapper、 +插件和依赖。项目工作目录也需要挂载,以保留 `build/` 和项目级 `.gradle/`。 + +```sh +IAM_GRADLE_CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/iam-login/gradle" +mkdir -p "$IAM_GRADLE_CACHE" +docker run --rm --network host \ + --user "$(id -u):$(id -g)" \ + --group-add "$(stat -c %g /var/run/docker.sock)" \ + -e LANG=C.UTF-8 \ + -e GRADLE_USER_HOME=/gradle \ + -e TESTCONTAINERS_HOST_OVERRIDE=127.0.0.1 \ + -v "$IAM_GRADLE_CACHE:/gradle" \ + -v "$PWD:/workspace" \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -w /workspace --entrypoint /bin/bash \ + ghcr.io/graalvm/native-image-community@sha256:0d936f32bb8acb5bc60c41b33e05f064d7a6aaf36b726538296c54949bd4a3c0 \ + -c './gradlew --no-daemon --max-workers=4 test' +``` + +宿主机 Docker socket 供 Testcontainers 使用,host network 让测试能访问它启动的动态端口。 +Docker Desktop 的网络方式需按平台调整。首次本地验证使用 `/tmp/iam-login-gradle` 作为 +上述缓存目录,未写入仓库;长期开发使用持久缓存目录。构建容器使用宿主 UID/GID, +避免产物和缓存变为 root 所有。 diff --git a/docs/native-validation.md b/docs/native-validation.md new file mode 100644 index 0000000..6232430 --- /dev/null +++ b/docs/native-validation.md @@ -0,0 +1,36 @@ +# 首轮 Native 验证范围 + +本页定义验收要求,不表示下列功能已实现或测试通过。MFA 首先验证 Spring 官方 +WebAuthn 集成;TOTP、恢复方式与已有 Authelia MFA 的迁移方式需在实现中明确。 + +## 认证与身份 + +- 使用隔离 LDAP 测试夹具验证正确密码、错误密码、未知及禁用用户;随后验证 Samba AD + 的真实 schema、LDAPS 信任和组查询,不把通用 LDAP 测试等同于 AD 验收。 +- 用户与组以 AD 为权威,直接映射;不把框架 ROLE_ 前缀或大小写转换泄露到 groups claim。 +- LDAP 与 MFA 必须绑定同一个稳定主体;仅完成密码不得接受 Hydra login challenge。 +- 验证 MFA 注册授权、challenge 过期与重放、其他用户凭据、重启后的持久化,以及恢复。 +- 新主体映射与现役 Go 适配器的 issuer/sub 哈希不同;切换前必须制定显式连续性映射, + 不依赖可变邮箱、用户名或自动创建账号来掩盖身份变化。 + +## Hydra + +- 认证事务绑定原始 challenge、浏览器会话和期限;成功后单次使用。 +- 校验允许的 client、scope、audience 和 Hydra 返回跳转的 origin/path。 +- Hydra admin 保持内部访问,业务日志不得包含密码、MFA secret、token 或 challenge。 +- 原生二进制与隔离 Hydra 完成授权码链路,再验证现有 Gitea 账号及权限。 + +## Native 与监控 + +- CI 构建 Native 产物并对该产物执行集成测试;测试报告区分 JVM 与 Native。 +- 最终运行镜像无需 JRE,不允许以回退 JVM 的方式令 Native 验收通过。 +- LDAP、MFA、数据库、TLS、JSON 和 Hydra HTTP 客户端全部在 Native 中执行。 +- 纳入 Actuator、Micrometer Prometheus 与 OpenTelemetry/分布式追踪;实际发起请求后 + 检查计数器、耗时分布与 trace 导出,确保 trace 属性不记录认证凭据或 challenge。 +- 记录镜像大小、启动时间、空闲与负载下内存、CPU、关键请求延迟;资源预算依据实测确认。 +- 将应用指标与 Native 运行时指标区分,不能假设 HotSpot JVM 仪表盘完整适用。 + +## 发布条件 + +通过上述测试后才准备生产切换;保留现役 OIDC 上游适配器作为回退路径。应用镜像以 +不可变 digest 交给 homelab-infra,部署状态与真实人类 MFA 验收分别记录。 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..eddabd2 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..ad7845b --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,9 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-9.7.1-bin.zip +networkTimeout=10000 +retries=0 +retryBackOffMs=500 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..249efbb --- /dev/null +++ b/gradlew @@ -0,0 +1,248 @@ +#!/bin/sh + +# +# Copyright © 2015 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# gradlew start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh gradlew +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..a51ec4f --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,82 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem gradlew startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables, and ensure extensions are enabled +setlocal EnableExtensions + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +"%COMSPEC%" /c exit 1 + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +"%COMSPEC%" /c exit 1 + +:execute +@rem Setup the command line + + + +@rem Execute gradlew +@rem endlocal doesn't take effect until after the line is parsed and variables are expanded +@rem which allows us to clear the local environment before executing the java command +endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel + +:exitWithErrorLevel +@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts +"%COMSPEC%" /c exit %ERRORLEVEL% diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..57183c7 --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'iam-login' diff --git a/src/main/java/top/ddupan/iam/login/IamLoginApplication.java b/src/main/java/top/ddupan/iam/login/IamLoginApplication.java new file mode 100644 index 0000000..24de1d4 --- /dev/null +++ b/src/main/java/top/ddupan/iam/login/IamLoginApplication.java @@ -0,0 +1,13 @@ +package top.ddupan.iam.login; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class IamLoginApplication { + + public static void main(String[] args) { + SpringApplication.run(IamLoginApplication.class, args); + } + +} diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml new file mode 100644 index 0000000..99ef6e2 --- /dev/null +++ b/src/main/resources/application.yaml @@ -0,0 +1,3 @@ +spring: + application: + name: iam-login diff --git a/src/test/java/top/ddupan/iam/login/IamLoginApplicationTests.java b/src/test/java/top/ddupan/iam/login/IamLoginApplicationTests.java new file mode 100644 index 0000000..7e86c5d --- /dev/null +++ b/src/test/java/top/ddupan/iam/login/IamLoginApplicationTests.java @@ -0,0 +1,15 @@ +package top.ddupan.iam.login; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Import; + +@Import(TestcontainersConfiguration.class) +@SpringBootTest +class IamLoginApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/src/test/java/top/ddupan/iam/login/TestIamLoginApplication.java b/src/test/java/top/ddupan/iam/login/TestIamLoginApplication.java new file mode 100644 index 0000000..71302f7 --- /dev/null +++ b/src/test/java/top/ddupan/iam/login/TestIamLoginApplication.java @@ -0,0 +1,11 @@ +package top.ddupan.iam.login; + +import org.springframework.boot.SpringApplication; + +public class TestIamLoginApplication { + + public static void main(String[] args) { + SpringApplication.from(IamLoginApplication::main).with(TestcontainersConfiguration.class).run(args); + } + +} diff --git a/src/test/java/top/ddupan/iam/login/TestcontainersConfiguration.java b/src/test/java/top/ddupan/iam/login/TestcontainersConfiguration.java new file mode 100644 index 0000000..fcb6eaf --- /dev/null +++ b/src/test/java/top/ddupan/iam/login/TestcontainersConfiguration.java @@ -0,0 +1,18 @@ +package top.ddupan.iam.login; + +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.boot.testcontainers.service.connection.ServiceConnection; +import org.springframework.context.annotation.Bean; +import org.testcontainers.grafana.LgtmStackContainer; +import org.testcontainers.utility.DockerImageName; + +@TestConfiguration(proxyBeanMethods = false) +class TestcontainersConfiguration { + + @Bean + @ServiceConnection + LgtmStackContainer grafanaLgtmContainer() { + return new LgtmStackContainer(DockerImageName.parse("grafana/otel-lgtm:latest")); + } + +}