├── authmore-admin ├── README.md ├── src │ └── main │ │ ├── resources │ │ ├── application-dev.yml │ │ ├── application.yml │ │ ├── application-prod.yml │ │ └── banner.txt │ │ └── java │ │ └── me │ │ └── zbl │ │ └── authmore │ │ └── admin │ │ ├── AdminApplication.java │ │ ├── endpoint │ │ ├── UserDetailsEndpoint.java │ │ └── JwkSetEndpoint.java │ │ ├── user │ │ ├── UserDetailsRepo.java │ │ ├── UserDetailService.java │ │ └── UserInitializer.java │ │ ├── PasswordEndpoint.java │ │ ├── AuthController.java │ │ └── client │ │ ├── ClientDetailsRepo.java │ │ ├── ClientDetailService.java │ │ ├── ClientCreateResult.java │ │ └── ClientInitializer.java ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── Dockerfile.prod ├── Dockerfile.test ├── .gitignore ├── settings.gradle ├── build.gradle └── gradlew.bat ├── authmore-platform ├── README.md ├── src │ ├── main │ │ ├── resources │ │ │ ├── application-prod.yml │ │ │ ├── public │ │ │ │ ├── logo.png │ │ │ │ ├── favicon.ico │ │ │ │ ├── main.css │ │ │ │ └── app-icon.svg │ │ │ ├── templates │ │ │ │ ├── header.ftl │ │ │ │ ├── error.ftl │ │ │ │ ├── footer.ftl │ │ │ │ ├── dist.ftl │ │ │ │ └── signin.ftl │ │ │ ├── banner.txt │ │ │ └── application.yml │ │ └── java │ │ │ └── me │ │ │ └── zbl │ │ │ └── authmore │ │ │ └── platform │ │ │ ├── oauth │ │ │ ├── AccessTokenRepository.java │ │ │ ├── RefreshTokenRepository.java │ │ │ ├── ClientDetailsRepository.java │ │ │ ├── TokenRefreshTokenIssuer.java │ │ │ ├── TokenClientCredentialsTokenIssuer.java │ │ │ ├── TokenConfigurationProperties.java │ │ │ ├── TokenAuthorizationCodeTokenIssuer.java │ │ │ ├── ExceptionHandlers.java │ │ │ └── TokenPasswordTokenIssuer.java │ │ │ ├── authorization │ │ │ ├── CodeRepository.java │ │ │ ├── UserDetailsRepository.java │ │ │ ├── ScopeConstants.java │ │ │ ├── UserSessionManager.java │ │ │ ├── UserDetailsEndpoint.java │ │ │ ├── RedisCodeManager.java │ │ │ └── AuthenticationFilter.java │ │ │ ├── SecurityConfiguration.java │ │ │ ├── jwk │ │ │ ├── JWKSetEndpoint.java │ │ │ └── JWKConfiguration.java │ │ │ ├── Bootstrap.java │ │ │ └── ErrorEndpoint.java │ └── test │ │ └── java │ │ └── me │ │ └── zbl │ │ └── authmore │ │ └── platform │ │ └── RSAKeyPairTest.java ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── Dockerfile.prod ├── Dockerfile.test ├── .gitignore ├── settings.gradle ├── build.gradle └── gradlew.bat ├── authmore-client-springboot-starter ├── README.md ├── src │ └── main │ │ ├── resources │ │ └── META-INF │ │ │ └── spring.factories │ │ └── java │ │ └── me │ │ └── zbl │ │ └── authmore │ │ └── configuration │ │ ├── EndpointsAutoConfiguration.java │ │ └── AuthorizeAutoConfiguration.java ├── settings.gradle └── build.gradle ├── authmore-resource-sample ├── README.md ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── src │ ├── main │ │ ├── resources │ │ │ ├── banner.txt │ │ │ └── application.yml │ │ └── java │ │ │ └── me │ │ │ └── zbl │ │ │ └── authmore │ │ │ └── sample │ │ │ ├── ResourceSampleApplication.java │ │ │ ├── Inbox.java │ │ │ ├── SampleEndpoint.java │ │ │ ├── InboxResourceEndpoint.java │ │ │ ├── ResourceServerConfiguration.java │ │ │ └── Email.java │ └── test │ │ └── java │ │ └── me │ │ └── zbl │ │ └── authmore │ │ └── sample │ │ └── ResourceSampleApplicationTests.java ├── .gitignore ├── settings.gradle ├── build.gradle └── gradlew.bat ├── authmore-resource-springboot-starter ├── README.md ├── src │ └── main │ │ └── resources │ │ └── META-INF │ │ └── spring.factories ├── settings.gradle └── build.gradle ├── .doc ├── logo.png └── structure.png ├── deploy.sh ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── authmore-client-sample ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── README.md ├── src │ ├── main │ │ ├── resources │ │ │ ├── banner.txt │ │ │ └── application.yml │ │ └── java │ │ │ └── me │ │ │ └── zbl │ │ │ └── authmore │ │ │ └── clientsample │ │ │ ├── Inbox.java │ │ │ ├── ClientCredentialsEndpoint.java │ │ │ ├── Email.java │ │ │ ├── ClientSampleApplication.java │ │ │ ├── PasswordEndpoint.java │ │ │ └── ImplicitEndpoint.java │ └── test │ │ └── java │ │ └── me │ │ └── zbl │ │ └── authmore │ │ └── clientsample │ │ └── ClientSampleApplicationTests.java ├── .gitignore ├── settings.gradle ├── build.gradle └── gradlew.bat ├── .editorconfig ├── .gitignore ├── .travis.yml ├── authmore-common ├── settings.gradle ├── build.gradle └── src │ ├── main │ └── java │ │ └── me │ │ └── zbl │ │ └── authmore │ │ └── common │ │ ├── UniqueToken.java │ │ ├── Assert.java │ │ ├── ResultBuilder.java │ │ ├── ResponseContent.java │ │ ├── ResponseEntity.java │ │ ├── BasicController.java │ │ └── RandomSecret.java │ └── test │ └── java │ └── me │ └── zbl │ └── authmore │ └── common │ ├── UniqueTokenTest.java │ └── RandomSecretTest.java ├── authmore-core ├── settings.gradle ├── src │ └── main │ │ ├── java │ │ └── me │ │ │ └── zbl │ │ │ └── authmore │ │ │ ├── ErrorResponse.java │ │ │ ├── PasswordHolder.java │ │ │ ├── authorization │ │ │ ├── RequestProperties.java │ │ │ ├── SessionManager.java │ │ │ ├── AuthenticationException.java │ │ │ ├── AuthorizationException.java │ │ │ ├── SessionProperties.java │ │ │ ├── AuthenticationManager.java │ │ │ ├── AbstractCodeManager.java │ │ │ └── CodeBinding.java │ │ │ ├── client │ │ │ ├── ClientTokenRestTemplate.java │ │ │ ├── ClientTokenOperations.java │ │ │ ├── ClientHttpClientInterceptor.java │ │ │ ├── AuthorizationOperations.java │ │ │ ├── ClientCredentialsTokenManager.java │ │ │ ├── ImplicitAuthorizationEndpoint.java │ │ │ ├── RefreshTokenManager.java │ │ │ ├── PasswordTokenManager.java │ │ │ ├── AuthorizationCodeTokenManager.java │ │ │ ├── ClientRestTemplate.java │ │ │ └── AuthorizationTemplate.java │ │ │ ├── repositories │ │ │ ├── AccessTokenRepository.java │ │ │ ├── RefreshTokenRepository.java │ │ │ └── ClientDetailsRepository.java │ │ │ ├── resource │ │ │ ├── ScopeRequired.java │ │ │ ├── AuthorityRequired.java │ │ │ └── ResourceServerConfigurationProperties.java │ │ │ ├── oauth │ │ │ ├── CodeManager.java │ │ │ ├── RequestUtil.java │ │ │ ├── OAuthFilter.java │ │ │ ├── TokenManager.java │ │ │ ├── OAuthErrorResponse.java │ │ │ ├── RefreshTokenBinding.java │ │ │ ├── OAuthException.java │ │ │ └── AccessTokenBinding.java │ │ │ └── PasswordEncoderFactory.java │ │ └── resources │ │ └── templates │ │ └── implicit.ftl └── build.gradle ├── export.sh ├── settings.gradle ├── docker-compose.yml ├── README.md └── gradlew.bat /authmore-admin/README.md: -------------------------------------------------------------------------------- 1 | # Authmore 认证平台管理 -------------------------------------------------------------------------------- /authmore-platform/README.md: -------------------------------------------------------------------------------- 1 | # Authmore 认证平台 -------------------------------------------------------------------------------- /authmore-client-springboot-starter/README.md: -------------------------------------------------------------------------------- 1 | # Authmore 客户端 SDK -------------------------------------------------------------------------------- /authmore-resource-sample/README.md: -------------------------------------------------------------------------------- 1 | # Authmore Sample - 邮箱(资源服务) -------------------------------------------------------------------------------- /authmore-resource-springboot-starter/README.md: -------------------------------------------------------------------------------- 1 | # Authmore 资源服务 SDK -------------------------------------------------------------------------------- /.doc/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JamesZBL/authmore-framework/HEAD/.doc/logo.png -------------------------------------------------------------------------------- /.doc/structure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JamesZBL/authmore-framework/HEAD/.doc/structure.png -------------------------------------------------------------------------------- /deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | docker stack deploy --with-registry-auth -c docker-compose.yml authmore 3 | -------------------------------------------------------------------------------- /authmore-admin/src/main/resources/application-dev.yml: -------------------------------------------------------------------------------- 1 | logging: 2 | level: 3 | org.springframework.security: debug 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JamesZBL/authmore-framework/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /authmore-platform/src/main/resources/application-prod.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | data: 3 | mongodb: 4 | host: mongo 5 | redis: 6 | host: redis -------------------------------------------------------------------------------- /authmore-admin/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JamesZBL/authmore-framework/HEAD/authmore-admin/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /authmore-platform/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JamesZBL/authmore-framework/HEAD/authmore-platform/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /authmore-platform/src/main/resources/public/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JamesZBL/authmore-framework/HEAD/authmore-platform/src/main/resources/public/logo.png -------------------------------------------------------------------------------- /authmore-platform/src/main/resources/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JamesZBL/authmore-framework/HEAD/authmore-platform/src/main/resources/public/favicon.ico -------------------------------------------------------------------------------- /authmore-client-sample/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JamesZBL/authmore-framework/HEAD/authmore-client-sample/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /authmore-resource-sample/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JamesZBL/authmore-framework/HEAD/authmore-resource-sample/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /authmore-client-sample/README.md: -------------------------------------------------------------------------------- 1 | # Authmore Sample - 邮件阅读器(客户端) 2 | 3 | ## Sample URLs 4 | 5 | authorization_code /inbox 6 | password /password 7 | implicit /implicit 8 | client_credentials /client -------------------------------------------------------------------------------- /authmore-admin/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8083 3 | 4 | spring: 5 | profiles: 6 | active: dev 7 | 8 | data: 9 | mongodb: 10 | database: authmore -------------------------------------------------------------------------------- /authmore-admin/src/main/resources/application-prod.yml: -------------------------------------------------------------------------------- 1 | server: 2 | tomcat: 3 | max-threads: 5 4 | 5 | spring: 6 | data: 7 | mongodb: 8 | host: mongo 9 | redis: 10 | host: redis -------------------------------------------------------------------------------- /authmore-resource-springboot-starter/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | me.zbl.authmore.configuration.ResourceServerAutoConfiguration -------------------------------------------------------------------------------- /authmore-platform/src/main/resources/templates/header.ftl: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 |
-------------------------------------------------------------------------------- /authmore-platform/src/main/resources/templates/error.ftl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Error - Authmore 6 | 7 | 8 | ${error} 9 | 10 | -------------------------------------------------------------------------------- /authmore-admin/Dockerfile.prod: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jdk-alpine 2 | VOLUME /tmp 3 | ARG JAR_FILE=build/libs/authmore-admin-0.0.1-SNAPSHOT.jar 4 | ARG JAR_DEST=/app/app.jar 5 | WORKDIR /app 6 | COPY ${JAR_FILE} ${JAR_DEST} 7 | ENTRYPOINT ["java", "-Dspring.profiles.active=prod", "-jar", "app.jar"] -------------------------------------------------------------------------------- /authmore-platform/Dockerfile.prod: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jdk-alpine 2 | VOLUME /tmp 3 | ARG JAR_FILE=build/libs/authmore-platform-0.0.1-SNAPSHOT.jar 4 | ARG JAR_DEST=/app/app.jar 5 | WORKDIR /app 6 | COPY ${JAR_FILE} ${JAR_DEST} 7 | ENTRYPOINT ["java", "-Dspring.profiles.active=prod", "-jar", "app.jar"] -------------------------------------------------------------------------------- /authmore-platform/src/main/resources/templates/footer.ftl: -------------------------------------------------------------------------------- 1 |
2 |
3 |

Apache2 Licensed | Copyright © 2019 郑保乐

4 |
5 |
6 |
7 |
8 |
-------------------------------------------------------------------------------- /authmore-admin/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | _ _ _ 2 | / \ _ _| |_| |__ _ __ ___ ___ _ __ ___ 3 | / _ \| | | | __| '_ \| '_ ` _ \ / _ \| '__/ _ \ 4 | / ___ \ |_| | |_| | | | | | | | | (_) | | | __/ 5 | /_/ \_\__,_|\__|_| |_|_| |_| |_|\___/|_| \___| 6 | -------------------------------------------------------------------------------- /authmore-platform/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | _ _ _ 2 | / \ _ _| |_| |__ _ __ ___ ___ _ __ ___ 3 | / _ \| | | | __| '_ \| '_ ` _ \ / _ \| '__/ _ \ 4 | / ___ \ |_| | |_| | | | | | | | | (_) | | | __/ 5 | /_/ \_\__,_|\__|_| |_|_| |_| |_|\___/|_| \___| 6 | -------------------------------------------------------------------------------- /authmore-platform/src/main/resources/templates/dist.ftl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /authmore-client-sample/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | _ _ _ 2 | / \ _ _| |_| |__ _ __ ___ ___ _ __ ___ 3 | / _ \| | | | __| '_ \| '_ ` _ \ / _ \| '__/ _ \ 4 | / ___ \ |_| | |_| | | | | | | | | (_) | | | __/ 5 | /_/ \_\__,_|\__|_| |_|_| |_| |_|\___/|_| \___| 6 | -------------------------------------------------------------------------------- /authmore-admin/Dockerfile.test: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jdk-alpine 2 | VOLUME /tmp 3 | EXPOSE 8083 4 | ARG JAR_FILE=build/libs/authmore-admin-0.0.1-SNAPSHOT.jar 5 | ARG JAR_DEST=/app/app.jar 6 | WORKDIR /app 7 | COPY ${JAR_FILE} ${JAR_DEST} 8 | ENTRYPOINT ["java", "-Dspring.profiles.active=test", "-jar", "app.jar", "-Xmx32m", "-Xss256k"] -------------------------------------------------------------------------------- /authmore-resource-sample/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | _ _ _ 2 | / \ _ _| |_| |__ _ __ ___ ___ _ __ ___ 3 | / _ \| | | | __| '_ \| '_ ` _ \ / _ \| '__/ _ \ 4 | / ___ \ |_| | |_| | | | | | | | | (_) | | | __/ 5 | /_/ \_\__,_|\__|_| |_|_| |_| |_|\___/|_| \___| 6 | -------------------------------------------------------------------------------- /authmore-platform/Dockerfile.test: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jdk-alpine 2 | VOLUME /tmp 3 | EXPOSE 8086 4 | ARG JAR_FILE=build/libs/authmore-platform-0.0.1-SNAPSHOT.jar 5 | ARG JAR_DEST=/app/app.jar 6 | WORKDIR /app 7 | COPY ${JAR_FILE} ${JAR_DEST} 8 | ENTRYPOINT ["java","-Xmx32m", "-Xss256k", "-Dspring.profiles.active=test", "-jar", "app.jar"] -------------------------------------------------------------------------------- /authmore-platform/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8086 3 | servlet: 4 | session: 5 | timeout: 5m 6 | cookie: 7 | name: AUTHMORE_SESSION 8 | tomcat: 9 | max-threads: 5 10 | 11 | spring: 12 | data: 13 | mongodb: 14 | database: authmore 15 | 16 | token: 17 | policy: REDIS -------------------------------------------------------------------------------- /authmore-resource-sample/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8091 3 | 4 | authmore: 5 | resource: 6 | resource-id: MAILBOX 7 | token-info-url: http://platform.authmore/oauth/check_token 8 | jwk-set-url: http://platform.authmore/oauth/jwks 9 | client-id: 5cb88433ee173c60c379e04f 10 | client-secret: 6LJTlUAfSo4TZhgRdAh2BC1hfUGROEpT 11 | -------------------------------------------------------------------------------- /authmore-client-springboot-starter/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | me.zbl.authmore.configuration.TokenManagerAutoConfiguration,\ 3 | me.zbl.authmore.configuration.RestTemplateAutoConfiguration,\ 4 | me.zbl.authmore.configuration.AuthorizeAutoConfiguration,\ 5 | me.zbl.authmore.configuration.EndpointsAutoConfiguration -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | charset=utf-8 3 | end_of_line=lf 4 | insert_final_newline=false 5 | indent_style=space 6 | indent_size=4 7 | 8 | [{.babelrc,.stylelintrc,.eslintrc,jest.config,*.json,*.jsb3,*.jsb2,*.bowerrc}] 9 | indent_style=space 10 | indent_size=2 11 | 12 | [{*.kts,*.kt}] 13 | indent_style=space 14 | indent_size=4 15 | 16 | [{*.yml,*.yaml}] 17 | indent_style=space 18 | indent_size=2 19 | 20 | -------------------------------------------------------------------------------- /authmore-admin/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /authmore-platform/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | .sts4-cache 13 | 14 | ### IntelliJ IDEA ### 15 | .idea 16 | *.iws 17 | *.iml 18 | *.ipr 19 | /out/ 20 | 21 | ### NetBeans ### 22 | /nbproject/private/ 23 | /nbbuild/ 24 | /dist/ 25 | /nbdist/ 26 | /.nb-gradle/ 27 | -------------------------------------------------------------------------------- /authmore-client-sample/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | /build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | 6 | ### STS ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | 15 | ### IntelliJ IDEA ### 16 | .idea 17 | *.iws 18 | *.iml 19 | *.ipr 20 | /out/ 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | -------------------------------------------------------------------------------- /authmore-resource-sample/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | /build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | 6 | ### STS ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | 15 | ### IntelliJ IDEA ### 16 | .idea 17 | *.iws 18 | *.iml 19 | *.ipr 20 | /out/ 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | classes/ 2 | target/ 3 | */src/*/java/META-INF 4 | */src/META-INF/ 5 | */src/*/java/META-INF/ 6 | .classpath 7 | .springBeans 8 | .project 9 | .DS_Store 10 | .settings/ 11 | .idea/ 12 | out/ 13 | bin/ 14 | intellij/ 15 | build/ 16 | archive/ 17 | *.log 18 | *.log.* 19 | *.iml 20 | *.ipr 21 | *.iws 22 | *.tgz 23 | *.tar.gz 24 | .gradle/ 25 | gradle.properties 26 | atlassian-ide-plugin.xml 27 | !etc/eclipse/.checkstyle 28 | .checkstyle 29 | s101plugin.state 30 | .mvn 31 | mvnw 32 | mvnw.cmd 33 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | install: true 3 | 4 | jdk: 5 | - oraclejdk8 6 | 7 | services: 8 | - docker 9 | - mongodb 10 | - redis-server 11 | 12 | #before_install: 13 | #- echo $PRIVATE_REG_PASSWORD | docker login -u "$PRIVATE_REG_USERNAME" --password-stdin $PRIVATE_REG_HOST 14 | 15 | script: 16 | - ./gradlew build --scan -s 17 | 18 | before_cache: 19 | - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock 20 | - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ 21 | 22 | cache: 23 | directories: 24 | - $HOME/.gradle/caches/ 25 | - $HOME/.gradle/wrapper/ -------------------------------------------------------------------------------- /authmore-client-sample/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8090 3 | 4 | authmore: 5 | client: 6 | client-id: 5cb7e7bcee173c60c379e04e 7 | client-secret: afLTqlcRUr32UC3nWiUNIMsfOmVlzuzX 8 | request-token-on-startup: true 9 | scope: PROFILE+EMAIL 10 | token-issue-url: http://platform.authmore/oauth/token 11 | # "/implicit.html" for implicit mode 12 | redirect-uri: http://client.authmore/inbox 13 | authorize-uri: http://platform.authmore/authorize 14 | # only for implicit mode 15 | implicit-token-uri: http://client.authmore/token 16 | implicit-redirect-uri: http://client.authmore/implicit.html -------------------------------------------------------------------------------- /authmore-admin/settings.gradle: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright 2019 ZHENG BAO LE 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | rootProject.name = 'authmore-admin' -------------------------------------------------------------------------------- /authmore-common/settings.gradle: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright 2019 ZHENG BAO LE 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | rootProject.name = 'authmore-common' -------------------------------------------------------------------------------- /authmore-core/settings.gradle: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright 2019 ZHENG BAO LE 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | rootProject.name = 'authmore-core' -------------------------------------------------------------------------------- /export.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | home="archive" 3 | mkdir -p $home 4 | remote="git@gitee.com:zbl1996" 5 | for i in master; do 6 | for t in zip; do 7 | git archive --prefix=authmore-ui/ --format=$t --output archive/authmore-ui-$i.$t --remote=$remote/authmore-ui.git $i 8 | git archive --prefix=authmore-framework/ --format=$t --output archive/authmore-framework-$i.$t --remote=$remote/authmore.git $i 9 | cd $home 10 | mkdir tmp 11 | for f in authmore-*-$i.$t; do 12 | unzip -d tmp -o -u $f && rm $f 13 | done 14 | (cd tmp && zip -o authmore.$t -r authmore.$t .) 15 | mv tmp/authmore.$t . 16 | rm -r tmp 17 | done 18 | done 19 | echo Export finished. -------------------------------------------------------------------------------- /authmore-client-springboot-starter/settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | rootProject.name = 'authmore-client-springboot-starter' 17 | -------------------------------------------------------------------------------- /authmore-resource-springboot-starter/settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | rootProject.name = 'authmore-resource-springboot-starter' 17 | -------------------------------------------------------------------------------- /authmore-client-sample/settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | pluginManagement { 17 | repositories { 18 | gradlePluginPortal() 19 | } 20 | } 21 | rootProject.name = 'client-sample' 22 | -------------------------------------------------------------------------------- /authmore-platform/settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | pluginManagement { 17 | repositories { 18 | gradlePluginPortal() 19 | } 20 | } 21 | rootProject.name = 'authmore-platform' 22 | -------------------------------------------------------------------------------- /authmore-resource-sample/settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | pluginManagement { 17 | repositories { 18 | gradlePluginPortal() 19 | } 20 | } 21 | rootProject.name = 'resource-sample' 22 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2019 ZHENG BAO LE 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | distributionBase=GRADLE_USER_HOME 17 | distributionPath=wrapper/dists 18 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip 19 | zipStoreBase=GRADLE_USER_HOME 20 | zipStorePath=wrapper/dists 21 | -------------------------------------------------------------------------------- /authmore-admin/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2019 ZHENG BAO LE 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | distributionBase=GRADLE_USER_HOME 17 | distributionPath=wrapper/dists 18 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-bin.zip 19 | zipStoreBase=GRADLE_USER_HOME 20 | zipStorePath=wrapper/dists 21 | -------------------------------------------------------------------------------- /authmore-platform/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2019 ZHENG BAO LE 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | distributionBase=GRADLE_USER_HOME 17 | distributionPath=wrapper/dists 18 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-bin.zip 19 | zipStoreBase=GRADLE_USER_HOME 20 | zipStorePath=wrapper/dists 21 | -------------------------------------------------------------------------------- /authmore-client-sample/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2019 ZHENG BAO LE 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | distributionBase=GRADLE_USER_HOME 17 | distributionPath=wrapper/dists 18 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip 19 | zipStoreBase=GRADLE_USER_HOME 20 | zipStorePath=wrapper/dists 21 | -------------------------------------------------------------------------------- /authmore-resource-sample/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2019 ZHENG BAO LE 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | distributionBase=GRADLE_USER_HOME 17 | distributionPath=wrapper/dists 18 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip 19 | zipStoreBase=GRADLE_USER_HOME 20 | zipStorePath=wrapper/dists 21 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/ErrorResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore; 17 | 18 | /** 19 | * @author ZHENG BAO LE 20 | * @since 2019-03-05 21 | */ 22 | public interface ErrorResponse { 23 | 24 | String getError(); 25 | 26 | String getError_description(); 27 | } 28 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/PasswordHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore; 17 | 18 | /** 19 | * @author ZHENG BAO LE 20 | * @since 2019-02-05 21 | */ 22 | public interface PasswordHolder { 23 | 24 | String getPassword(); 25 | 26 | void setPassword(String encoded); 27 | } 28 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/authorization/RequestProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.authorization; 17 | 18 | /** 19 | * @author ZHENG BAO LE 20 | * @since 2019-02-26 21 | */ 22 | public interface RequestProperties { 23 | 24 | String CURRENT_CLIENT = "current_client"; 25 | } 26 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/client/ClientTokenRestTemplate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.client; 17 | 18 | import org.springframework.web.client.RestTemplate; 19 | 20 | /** 21 | * @author ZHENG BAO LE 22 | * @since 2019-03-02 23 | */ 24 | public class ClientTokenRestTemplate extends RestTemplate {} 25 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/authorization/SessionManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.authorization; 17 | 18 | import me.zbl.authmore.UserDetails; 19 | 20 | /** 21 | * @author ZHENG BAO LE 22 | * @since 2019-02-15 23 | */ 24 | public interface SessionManager { 25 | 26 | void signin(UserDetails user); 27 | } 28 | -------------------------------------------------------------------------------- /authmore-platform/src/main/java/me/zbl/authmore/platform/oauth/AccessTokenRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.zbl.authmore.platform.oauth; 18 | 19 | import org.springframework.stereotype.Repository; 20 | 21 | /** 22 | * @author ZHENG BAO LE 23 | * @since 2019-05-19 24 | */ 25 | @Repository 26 | public interface AccessTokenRepository extends me.zbl.authmore.repositories.AccessTokenRepository {} 27 | -------------------------------------------------------------------------------- /authmore-platform/src/main/java/me/zbl/authmore/platform/oauth/RefreshTokenRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.zbl.authmore.platform.oauth; 18 | 19 | import org.springframework.stereotype.Repository; 20 | 21 | /** 22 | * @author ZHENG BAO LE 23 | * @since 2019-05-19 24 | */ 25 | @Repository 26 | public interface RefreshTokenRepository extends me.zbl.authmore.repositories.RefreshTokenRepository {} 27 | -------------------------------------------------------------------------------- /authmore-platform/src/main/java/me/zbl/authmore/platform/oauth/ClientDetailsRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.zbl.authmore.platform.oauth; 18 | 19 | import org.springframework.stereotype.Repository; 20 | 21 | /** 22 | * @author ZHENG BAO LE 23 | * @since 2019-05-19 24 | */ 25 | @Repository 26 | public interface ClientDetailsRepository extends me.zbl.authmore.repositories.ClientDetailsRepository {} 27 | -------------------------------------------------------------------------------- /authmore-common/build.gradle: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright 2019 ZHENG BAO LE 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | apply plugin: 'java' 18 | apply plugin: "maven-publish" 19 | 20 | dependencies { 21 | implementation 'org.springframework:spring-web:5.1.4.RELEASE' 22 | testCompile 'org.junit.jupiter:junit-jupiter-api:5.4.0' 23 | testCompile 'org.slf4j:slf4j-log4j12:1.7.25' 24 | testCompile 'commons-codec:commons-codec:1.11' 25 | } 26 | 27 | jar { 28 | enabled = true 29 | } -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/client/ClientTokenOperations.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.client; 17 | 18 | import me.zbl.authmore.oauth.TokenResponse; 19 | 20 | import java.util.Map; 21 | 22 | /** 23 | * @author ZHENG BAO LE 24 | * @since 2019-03-02 25 | */ 26 | public interface ClientTokenOperations { 27 | 28 | TokenResponse getToken(String scope, Map restParams); 29 | } 30 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/repositories/AccessTokenRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.repositories; 17 | 18 | import me.zbl.authmore.oauth.AccessTokenBinding; 19 | import org.springframework.data.repository.CrudRepository; 20 | 21 | /** 22 | * @author ZHENG BAO LE 23 | * @since 2019-02-21 24 | */ 25 | public interface AccessTokenRepository extends CrudRepository {} 26 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/repositories/RefreshTokenRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.repositories; 17 | 18 | import me.zbl.authmore.oauth.RefreshTokenBinding; 19 | import org.springframework.data.repository.CrudRepository; 20 | 21 | /** 22 | * @author ZHENG BAO LE 23 | * @since 2019-02-26 24 | */ 25 | public interface RefreshTokenRepository extends CrudRepository {} 26 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* 18 | * This file was generated by the Gradle 'init' task. 19 | */ 20 | 21 | rootProject.name = 'authmore-framework' 22 | include 'authmore-core' 23 | include 'authmore-common' 24 | include 'authmore-admin' 25 | include 'authmore-platform' 26 | include 'authmore-resource-springboot-starter' 27 | include 'authmore-client-springboot-starter' 28 | include 'authmore-resource-sample' 29 | include 'authmore-client-sample' 30 | -------------------------------------------------------------------------------- /authmore-admin/src/main/java/me/zbl/authmore/admin/AdminApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.admin; 17 | 18 | import org.springframework.boot.SpringApplication; 19 | import org.springframework.boot.autoconfigure.SpringBootApplication; 20 | 21 | @SpringBootApplication 22 | public class AdminApplication { 23 | 24 | public static void main(String[] args) { 25 | SpringApplication.run(AdminApplication.class, args); 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /authmore-resource-springboot-starter/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | plugins { 17 | id 'java' 18 | id 'maven-publish' 19 | } 20 | 21 | dependencies { 22 | compile project(":authmore-core") 23 | compile project(":authmore-common") 24 | implementation 'org.springframework:spring-webmvc:5.1.5.RELEASE' 25 | compileOnly 'org.springframework.boot:spring-boot-autoconfigure:2.1.2.RELEASE' 26 | testCompile group: 'junit', name: 'junit', version: '4.12' 27 | } -------------------------------------------------------------------------------- /authmore-resource-sample/src/main/java/me/zbl/authmore/sample/ResourceSampleApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.sample; 17 | 18 | import org.springframework.boot.SpringApplication; 19 | import org.springframework.boot.autoconfigure.SpringBootApplication; 20 | 21 | @SpringBootApplication 22 | public class ResourceSampleApplication { 23 | 24 | public static void main(String[] args) { 25 | SpringApplication.run(ResourceSampleApplication.class, args); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /authmore-platform/src/main/java/me/zbl/authmore/platform/authorization/CodeRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.platform.authorization; 17 | 18 | import me.zbl.authmore.authorization.CodeBinding; 19 | import org.springframework.data.repository.CrudRepository; 20 | import org.springframework.stereotype.Repository; 21 | 22 | /** 23 | * @author ZHENG BAO LE 24 | * @since 2019-02-19 25 | */ 26 | @Repository 27 | public interface CodeRepository extends CrudRepository {} 28 | -------------------------------------------------------------------------------- /authmore-common/src/main/java/me/zbl/authmore/common/UniqueToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.zbl.authmore.common; 18 | 19 | import org.springframework.util.Base64Utils; 20 | 21 | import java.util.UUID; 22 | 23 | /** 24 | * @author ZHENG BAO LE 25 | * @since 2019-04-24 26 | */ 27 | public class UniqueToken { 28 | 29 | private UniqueToken() {} 30 | 31 | public static String create() { 32 | return Base64Utils.encodeToUrlSafeString(UUID.randomUUID().toString().getBytes()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/client/ClientHttpClientInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.client; 17 | 18 | import org.springframework.http.client.support.BasicAuthenticationInterceptor; 19 | 20 | /** 21 | * @author ZHENG BAO LE 22 | * @since 2019-03-01 23 | */ 24 | public class ClientHttpClientInterceptor extends BasicAuthenticationInterceptor { 25 | 26 | public ClientHttpClientInterceptor(String username, String password) { 27 | super(username, password); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /authmore-resource-sample/src/test/java/me/zbl/authmore/sample/ResourceSampleApplicationTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.sample; 17 | 18 | import org.junit.Test; 19 | import org.junit.runner.RunWith; 20 | import org.springframework.boot.test.context.SpringBootTest; 21 | import org.springframework.test.context.junit4.SpringRunner; 22 | 23 | @RunWith(SpringRunner.class) 24 | @SpringBootTest 25 | public class ResourceSampleApplicationTests { 26 | 27 | @Test 28 | public void contextLoads() { 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /authmore-client-sample/src/test/java/me/zbl/authmore/clientsample/ClientSampleApplicationTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.clientsample; 17 | 18 | import org.junit.Test; 19 | import org.junit.runner.RunWith; 20 | import org.springframework.boot.test.context.SpringBootTest; 21 | import org.springframework.test.context.junit4.SpringRunner; 22 | 23 | @RunWith(SpringRunner.class) 24 | @SpringBootTest 25 | public class ClientSampleApplicationTests { 26 | 27 | @Test 28 | public void contextLoads() { 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/client/AuthorizationOperations.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.client; 17 | 18 | import me.zbl.authmore.oauth.OAuthProperties.ResponseTypes; 19 | 20 | import javax.servlet.http.HttpServletResponse; 21 | import java.io.IOException; 22 | 23 | /** 24 | * @author ZHENG BAO LE 25 | * @since 2019-03-07 26 | */ 27 | public interface AuthorizationOperations { 28 | 29 | void redirectToUserAuthorize(HttpServletResponse response, ResponseTypes type, String scope) throws IOException; 30 | } 31 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/repositories/ClientDetailsRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.repositories; 17 | 18 | import me.zbl.authmore.ClientDetails; 19 | import org.springframework.data.mongodb.repository.MongoRepository; 20 | 21 | import java.util.Optional; 22 | 23 | /** 24 | * @author ZHENG BAO LE 25 | * @since 2019-02-15 26 | */ 27 | public interface ClientDetailsRepository extends MongoRepository { 28 | 29 | Optional findByClientId(String clientId); 30 | } 31 | -------------------------------------------------------------------------------- /authmore-client-springboot-starter/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | plugins { 17 | id 'java' 18 | id 'maven-publish' 19 | } 20 | 21 | dependencies { 22 | compile project(":authmore-core") 23 | compile project(":authmore-common") 24 | implementation 'org.springframework:spring-webmvc:5.1.5.RELEASE' 25 | implementation 'org.springframework.security:spring-security-core:5.1.4.RELEASE' 26 | compileOnly 'org.springframework.boot:spring-boot-autoconfigure:2.1.2.RELEASE' 27 | testCompile group: 'junit', name: 'junit', version: '4.12' 28 | } -------------------------------------------------------------------------------- /authmore-common/src/main/java/me/zbl/authmore/common/Assert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.common; 17 | 18 | import org.springframework.lang.Nullable; 19 | import org.springframework.util.StringUtils; 20 | 21 | /** 22 | * @author ZHENG BAO LE 23 | * @since 2019-03-02 24 | */ 25 | public final class Assert { 26 | 27 | private Assert() {} 28 | 29 | public static void notEmpty(@Nullable String value, String message) { 30 | if (StringUtils.isEmpty(value)) 31 | throw new IllegalArgumentException(message); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/resource/ScopeRequired.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.resource; 17 | 18 | import me.zbl.authmore.oauth.OAuthProperties; 19 | 20 | import java.lang.annotation.*; 21 | 22 | /** 23 | * @author ZHENG BAO LE 24 | * @since 2019-02-27 25 | */ 26 | @Target(ElementType.METHOD) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Documented 29 | public @interface ScopeRequired { 30 | 31 | OAuthProperties.RequireTypes type() default OAuthProperties.RequireTypes.ALL; 32 | 33 | String[] value() default {}; 34 | } 35 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/resource/AuthorityRequired.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.resource; 17 | 18 | import me.zbl.authmore.oauth.OAuthProperties; 19 | 20 | import java.lang.annotation.*; 21 | 22 | /** 23 | * @author ZHENG BAO LE 24 | * @since 2019-02-27 25 | */ 26 | @Target(ElementType.METHOD) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Documented 29 | public @interface AuthorityRequired { 30 | 31 | OAuthProperties.RequireTypes type() default OAuthProperties.RequireTypes.ANY; 32 | 33 | String[] value() default {}; 34 | } 35 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/oauth/CodeManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.oauth; 17 | 18 | import me.zbl.authmore.ClientDetails; 19 | import me.zbl.authmore.authorization.CodeBinding; 20 | 21 | import java.util.Set; 22 | 23 | /** 24 | * @author ZHENG BAO LE 25 | * @since 2019-02-18 26 | */ 27 | public interface CodeManager { 28 | 29 | void saveCodeBinding(ClientDetails client, String code, Set scopes, String redirectUri, String userId); 30 | 31 | CodeBinding getCodeDetails(String clientId, String code); 32 | 33 | void expireCode(String code); 34 | } 35 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/authorization/AuthenticationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.authorization; 17 | 18 | /** 19 | * @author ZHENG BAO LE 20 | * @since 2019-02-15 21 | */ 22 | public class AuthenticationException extends Exception { 23 | 24 | public static final String INVALID_USERNAME = "Invalid username"; 25 | public static final String INVALID_PASSWORD = "Invalid password"; 26 | public static final String ACCOUNT_DISABLED = "Account is disabled"; 27 | 28 | public AuthenticationException(String message) { 29 | super(message); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/authorization/AuthorizationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.authorization; 17 | 18 | /** 19 | * @author ZHENG BAO LE 20 | * @since 2019-02-18 21 | */ 22 | public class AuthorizationException extends RuntimeException { 23 | 24 | public AuthorizationException() { 25 | super("authorization_error"); 26 | } 27 | 28 | public AuthorizationException(String message) { 29 | super(message); 30 | } 31 | 32 | public AuthorizationException(String message, Throwable cause) { 33 | super(message, cause); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /authmore-resource-sample/src/main/java/me/zbl/authmore/sample/Inbox.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.zbl.authmore.sample; 18 | 19 | import java.util.List; 20 | 21 | /** 22 | * @author ZHENG BAO LE 23 | * @since 2019-04-18 24 | */ 25 | public class Inbox { 26 | 27 | private List emails; 28 | 29 | public Inbox(List emails) { 30 | this.emails = emails; 31 | } 32 | 33 | public List getEmails() { 34 | return emails; 35 | } 36 | 37 | public Inbox setEmails(List emails) { 38 | this.emails = emails; 39 | return this; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /authmore-platform/src/main/java/me/zbl/authmore/platform/authorization/UserDetailsRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.platform.authorization; 17 | 18 | import me.zbl.authmore.UserDetails; 19 | import org.springframework.data.mongodb.repository.MongoRepository; 20 | import org.springframework.stereotype.Repository; 21 | 22 | import java.util.Optional; 23 | 24 | /** 25 | * @author ZHENG BAO LE 26 | * @since 2019-02-14 27 | */ 28 | @Repository 29 | public interface UserDetailsRepository extends MongoRepository { 30 | 31 | Optional findByUsername(String userName); 32 | } 33 | -------------------------------------------------------------------------------- /authmore-client-sample/src/main/java/me/zbl/authmore/clientsample/Inbox.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.zbl.authmore.clientsample; 18 | 19 | import java.util.List; 20 | 21 | /** 22 | * @author ZHENG BAO LE 23 | * @since 2019-04-18 24 | */ 25 | public class Inbox { 26 | 27 | private List emails; 28 | 29 | public Inbox(List emails) { 30 | this.emails = emails; 31 | } 32 | 33 | public List getEmails() { 34 | return emails; 35 | } 36 | 37 | public Inbox setEmails(List emails) { 38 | this.emails = emails; 39 | return this; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /authmore-platform/src/main/resources/public/main.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | body { 18 | padding-top: 3rem; 19 | padding-bottom: 3rem; 20 | color: #5e778d; 21 | background-color: #e3e7ec; 22 | } 23 | 24 | .header { 25 | color: #415262; 26 | } 27 | 28 | .form-control { 29 | margin-top: 10px; 30 | } 31 | 32 | .title { 33 | line-height: 60px; 34 | } 35 | 36 | .logo { 37 | max-width: 100px; 38 | max-height: 100px; 39 | } 40 | 41 | .btn-primary { 42 | background-color: #1890ff; 43 | } 44 | 45 | .btn-danger { 46 | background-color: #ff6a76; 47 | } 48 | 49 | .card { 50 | box-shadow: #a3bdcf 0 0.5rem 2rem; 51 | } -------------------------------------------------------------------------------- /authmore-common/src/main/java/me/zbl/authmore/common/ResultBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.common; 17 | 18 | import java.util.HashMap; 19 | import java.util.Map; 20 | 21 | /** 22 | * @author ZHENG BAO LE 23 | * @since 2019-02-11 24 | */ 25 | public class ResultBuilder { 26 | 27 | private Map map; 28 | 29 | public ResultBuilder() { 30 | this.map = new HashMap<>(); 31 | } 32 | 33 | public ResultBuilder put(String key, Object value) { 34 | this.map.put(key, value); 35 | return this; 36 | } 37 | 38 | public Map map() { 39 | return this.map; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/oauth/RequestUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.oauth; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | /** 23 | * @author ZHENG BAO LE 24 | * @since 2019-03-01 25 | */ 26 | public final class RequestUtil { 27 | 28 | private RequestUtil() {} 29 | 30 | public static String queryStringOf(Map params) { 31 | List stringParis = new ArrayList<>(); 32 | params.forEach((k, v) -> stringParis.add(String.format("%s=%s", String.valueOf(k), String.valueOf(v)))); 33 | return String.join("&", stringParis); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /authmore-platform/src/main/java/me/zbl/authmore/platform/SecurityConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.platform; 17 | 18 | import me.zbl.authmore.PasswordEncoderFactory; 19 | import org.springframework.context.annotation.Bean; 20 | import org.springframework.context.annotation.Configuration; 21 | import org.springframework.security.crypto.password.PasswordEncoder; 22 | 23 | /** 24 | * @author ZHENG BAO LE 25 | * @since 2019-02-15 26 | */ 27 | @Configuration 28 | public class SecurityConfiguration { 29 | 30 | @Bean 31 | PasswordEncoder passwordEncoder() { 32 | return PasswordEncoderFactory.createDelegatingPasswordEncoder(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /authmore-resource-sample/src/main/java/me/zbl/authmore/sample/SampleEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.sample; 17 | 18 | import me.zbl.authmore.resource.AuthorityRequired; 19 | import me.zbl.authmore.resource.ScopeRequired; 20 | import org.springframework.web.bind.annotation.GetMapping; 21 | import org.springframework.web.bind.annotation.RestController; 22 | 23 | /** 24 | * @author ZHENG BAO LE 25 | * @since 2019-02-28 26 | */ 27 | @RestController 28 | public class SampleEndpoint { 29 | 30 | @GetMapping() 31 | @ScopeRequired("PROFILE") 32 | @AuthorityRequired("SA") 33 | public String sample() { 34 | return "sample"; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/authorization/SessionProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.authorization; 17 | 18 | /** 19 | * @author ZHENG BAO LE 20 | * @since 2019-02-15 21 | */ 22 | public interface SessionProperties { 23 | 24 | String CURRENT_USER = "current_user"; 25 | String CURRENT_USER_DETAILS = "current_user_details"; 26 | String LAST_URL = "last_url"; 27 | String CURRENT_CLIENT = "current_client"; 28 | String CURRENT_REDIRECT_URI = "current_redirect_uri"; 29 | String LAST_STATE = "last_state"; 30 | String LAST_SCOPE = "last_scope"; 31 | String LAST_TYPE = "last_type"; 32 | String FORGET_ME = "forget_me"; 33 | } 34 | -------------------------------------------------------------------------------- /authmore-core/src/main/resources/templates/implicit.ftl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | Authmore Implicit 8 | 9 | 10 | 11 |

跳转中...

12 | 13 | 14 | -------------------------------------------------------------------------------- /authmore-admin/src/main/java/me/zbl/authmore/admin/endpoint/UserDetailsEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.admin.endpoint; 17 | 18 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; 19 | import org.springframework.web.bind.annotation.GetMapping; 20 | import org.springframework.web.bind.annotation.RestController; 21 | 22 | import java.security.Principal; 23 | 24 | /** 25 | * @author ZHENG BAO LE 26 | * @since 2019-01-29 27 | */ 28 | @RestController 29 | @EnableResourceServer 30 | public class UserDetailsEndpoint { 31 | 32 | @GetMapping("/about/me") 33 | public Principal user(Principal principal) { 34 | return principal; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /authmore-admin/src/main/java/me/zbl/authmore/admin/user/UserDetailsRepo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.admin.user; 17 | 18 | import me.zbl.authmore.UserDetails; 19 | import org.springframework.data.mongodb.repository.MongoRepository; 20 | import org.springframework.stereotype.Repository; 21 | 22 | import java.util.List; 23 | import java.util.Optional; 24 | 25 | /** 26 | * @author ZHENG BAO LE 27 | * @since 2019-01-28 28 | */ 29 | @Repository 30 | public interface UserDetailsRepo extends MongoRepository { 31 | 32 | Optional findByUsername(String username); 33 | 34 | List findAllByOrderByIdDesc(); 35 | 36 | void deleteByIdIn(List id); 37 | } 38 | -------------------------------------------------------------------------------- /authmore-client-springboot-starter/src/main/java/me/zbl/authmore/configuration/EndpointsAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.configuration; 17 | 18 | import me.zbl.authmore.client.ImplicitAuthorizationEndpoint; 19 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 20 | import org.springframework.context.annotation.ComponentScan; 21 | import org.springframework.context.annotation.Configuration; 22 | 23 | /** 24 | * @author ZHENG BAO LE 25 | * @since 2019-03-07 26 | */ 27 | @Configuration 28 | @ConditionalOnClass({ImplicitAuthorizationEndpoint.class}) 29 | @ComponentScan(basePackageClasses = ImplicitAuthorizationEndpoint.class) 30 | public class EndpointsAutoConfiguration {} 31 | -------------------------------------------------------------------------------- /authmore-resource-sample/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | plugins { 17 | id 'org.springframework.boot' version '2.1.3.RELEASE' 18 | id 'java' 19 | } 20 | 21 | apply plugin: 'io.spring.dependency-management' 22 | 23 | repositories { 24 | mavenLocal() 25 | mavenCentral() 26 | } 27 | 28 | dependencies { 29 | implementation project(':authmore-resource-springboot-starter') 30 | implementation 'org.springframework.boot:spring-boot-starter-web' 31 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 32 | } 33 | 34 | signMavenJavaPublication.enabled = false 35 | publishMavenJavaPublicationToMavenRepository.enabled = false 36 | dockerBuildImage.enabled = false 37 | dockerPushImage.enabled = false -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/authorization/AuthenticationManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.authorization; 17 | 18 | import me.zbl.authmore.ClientDetails; 19 | import me.zbl.authmore.UserDetails; 20 | import me.zbl.authmore.oauth.OAuthException; 21 | 22 | /** 23 | * @author ZHENG BAO LE 24 | * @since 2019-02-15 25 | */ 26 | public interface AuthenticationManager { 27 | 28 | UserDetails userValidate(String principal, String credential) throws AuthenticationException; 29 | 30 | ClientDetails clientValidate(String clientId, String scope) throws OAuthException; 31 | 32 | ClientDetails clientValidate(String clientId, String redirectUri, String scope) throws AuthorizationException; 33 | } 34 | -------------------------------------------------------------------------------- /authmore-platform/src/main/resources/templates/signin.ftl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 用户登录 - Authmore 开放平台 6 | <#include "./dist.ftl"> 7 | 8 | 9 | <#include "./header.ftl"> 10 |
11 | 12 |

Authmore 开放平台

13 |

用 户 登 录

14 |
15 | <#if error?? > 16 | 22 | 23 | 33 | <#include "./footer.ftl"> 34 | 35 | 36 | -------------------------------------------------------------------------------- /authmore-common/src/main/java/me/zbl/authmore/common/ResponseContent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.common; 17 | 18 | /** 19 | * @author ZHENG BAO LE 20 | * @since 2019-01-28 21 | */ 22 | public class ResponseContent { 23 | 24 | private String status; 25 | private String msg; 26 | 27 | public ResponseContent(String status, String msg) { 28 | this.status = status; 29 | this.msg = msg; 30 | } 31 | 32 | public String getStatus() { 33 | return status; 34 | } 35 | 36 | public void setStatus(String status) { 37 | this.status = status; 38 | } 39 | 40 | public String getMsg() { 41 | return msg; 42 | } 43 | 44 | public void setMsg(String msg) { 45 | this.msg = msg; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /authmore-platform/src/main/java/me/zbl/authmore/platform/jwk/JWKSetEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.zbl.authmore.platform.jwk; 18 | 19 | import com.nimbusds.jose.jwk.JWKSet; 20 | import org.springframework.web.bind.annotation.GetMapping; 21 | import org.springframework.web.bind.annotation.RestController; 22 | 23 | import java.util.Map; 24 | 25 | /** 26 | * @author ZHENG BAO LE 27 | * @since 2019-05-14 28 | */ 29 | @RestController 30 | public class JWKSetEndpoint { 31 | 32 | private final JWKSet jwkSetBean; 33 | 34 | public JWKSetEndpoint(JWKSet jwkSet) { 35 | this.jwkSetBean = jwkSet; 36 | } 37 | 38 | @GetMapping("/oauth/jwks") 39 | public Map jwkSet() { 40 | return this.jwkSetBean.toJSONObject(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /authmore-admin/src/main/java/me/zbl/authmore/admin/PasswordEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.admin; 17 | 18 | import me.zbl.authmore.common.BasicController; 19 | import me.zbl.authmore.common.RandomSecret; 20 | import org.springframework.web.bind.annotation.GetMapping; 21 | import org.springframework.web.bind.annotation.RequestMapping; 22 | import org.springframework.web.bind.annotation.RestController; 23 | 24 | import java.util.Map; 25 | 26 | /** 27 | * @author ZHENG BAO LE 28 | * @since 2019-02-11 29 | */ 30 | @RestController 31 | @RequestMapping("/password") 32 | public class PasswordEndpoint extends BasicController { 33 | 34 | @GetMapping("/random") 35 | public Map randomPassword() { 36 | return map().put("result", RandomSecret.create()).map(); 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /authmore-common/src/test/java/me/zbl/authmore/common/UniqueTokenTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.zbl.authmore.common; 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import java.util.HashSet; 22 | import java.util.Set; 23 | 24 | import static org.junit.jupiter.api.Assertions.assertFalse; 25 | import static org.junit.jupiter.api.Assertions.assertNotNull; 26 | 27 | /** 28 | * @author ZHENG BAO LE 29 | * @since 2019-04-24 30 | */ 31 | class UniqueTokenTest { 32 | 33 | @Test 34 | void create() { 35 | Set set = new HashSet<>(); 36 | for (int i = 0; i < 10E6; i++) { 37 | String token = UniqueToken.create(); 38 | assertNotNull(token); 39 | assertFalse(set.contains(token)); 40 | set.add(token); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/authorization/AbstractCodeManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.authorization; 17 | 18 | import me.zbl.authmore.ClientDetails; 19 | import me.zbl.authmore.oauth.CodeManager; 20 | 21 | import java.util.Set; 22 | 23 | /** 24 | * @author ZHENG BAO LE 25 | * @since 2019-02-18 26 | */ 27 | public abstract class AbstractCodeManager implements CodeManager { 28 | 29 | @Override 30 | public void saveCodeBinding(ClientDetails client, String code, Set scopes, String redirectUri, String userId) { 31 | String clientId = client.getClientId(); 32 | CodeBinding codeBinding = new CodeBinding(code, clientId, scopes, redirectUri, userId); 33 | saveCode(codeBinding); 34 | } 35 | 36 | public abstract void saveCode(CodeBinding codeBinding); 37 | } 38 | -------------------------------------------------------------------------------- /authmore-admin/src/main/java/me/zbl/authmore/admin/AuthController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.admin; 17 | 18 | import me.zbl.authmore.PasswordHolder; 19 | import me.zbl.authmore.common.BasicController; 20 | import org.springframework.security.crypto.password.PasswordEncoder; 21 | 22 | /** 23 | * @author ZHENG BAO LE 24 | * @since 2019-02-05 25 | */ 26 | public class AuthController extends BasicController { 27 | 28 | private PasswordEncoder passwordEncoder; 29 | 30 | public AuthController(PasswordEncoder passwordEncoder) { 31 | this.passwordEncoder = passwordEncoder; 32 | } 33 | 34 | protected void encodePassword(PasswordHolder holder) { 35 | String raw = holder.getPassword(); 36 | String encoded = passwordEncoder.encode(raw); 37 | holder.setPassword(encoded); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/client/ClientCredentialsTokenManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.client; 17 | 18 | import org.springframework.web.client.RestTemplate; 19 | 20 | import static me.zbl.authmore.oauth.OAuthProperties.GrantTypes; 21 | 22 | /** 23 | * @author ZHENG BAO LE 24 | * @since 2019-03-02 25 | */ 26 | public final class ClientCredentialsTokenManager extends AbstractClientTokenManager { 27 | 28 | public ClientCredentialsTokenManager( 29 | RestTemplate client, 30 | String clientId, 31 | String clientSecret, 32 | String tokenIssueUrl) { 33 | super(client, clientId, clientSecret, tokenIssueUrl); 34 | } 35 | 36 | @Override 37 | protected final GrantTypes getGrantType() { 38 | return GrantTypes.CLIENT_CREDENTIALS; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /authmore-admin/src/main/java/me/zbl/authmore/admin/client/ClientDetailsRepo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.admin.client; 17 | 18 | import me.zbl.authmore.ClientDetails; 19 | import org.springframework.data.mongodb.repository.MongoRepository; 20 | import org.springframework.stereotype.Repository; 21 | 22 | import java.util.Collection; 23 | import java.util.List; 24 | import java.util.Optional; 25 | 26 | /** 27 | * @author ZHENG BAO LE 28 | * @since 2019-01-28 29 | */ 30 | @Repository 31 | public interface ClientDetailsRepo extends MongoRepository { 32 | 33 | Optional findByClientId(String clientId); 34 | 35 | Collection findByClientName(String clientName); 36 | 37 | List findAllByOrderByClientIdDesc(); 38 | 39 | void deleteByClientIdIn(List id); 40 | } 41 | -------------------------------------------------------------------------------- /authmore-platform/src/main/java/me/zbl/authmore/platform/Bootstrap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.platform; 17 | 18 | import me.zbl.authmore.platform.oauth.TokenManagerConfiguration; 19 | import org.springframework.boot.SpringApplication; 20 | import org.springframework.boot.autoconfigure.SpringBootApplication; 21 | import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; 22 | import org.springframework.boot.web.servlet.ServletComponentScan; 23 | import org.springframework.context.annotation.Import; 24 | 25 | @ServletComponentScan 26 | @SpringBootApplication(exclude = {SecurityAutoConfiguration.class}) 27 | @Import({TokenManagerConfiguration.class}) 28 | public class Bootstrap { 29 | 30 | public static void main(String[] args) { 31 | SpringApplication.run(Bootstrap.class, args); 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /authmore-client-sample/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | plugins { 17 | id 'java' 18 | id 'org.springframework.boot' version '2.1.3.RELEASE' 19 | } 20 | 21 | apply plugin: 'io.spring.dependency-management' 22 | 23 | repositories { 24 | mavenLocal() 25 | } 26 | 27 | dependencies { 28 | implementation project(':authmore-client-springboot-starter') 29 | implementation 'org.springframework.boot:spring-boot-starter-web' 30 | implementation 'org.springframework.boot:spring-boot-starter-freemarker' 31 | implementation 'org.springframework.boot:spring-boot-starter-actuator' 32 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 33 | } 34 | 35 | signMavenJavaPublication.enabled = false 36 | publishMavenJavaPublicationToMavenRepository.enabled = false 37 | dockerBuildImage.enabled = false 38 | dockerPushImage.enabled = false 39 | test.enabled = false -------------------------------------------------------------------------------- /authmore-admin/src/main/java/me/zbl/authmore/admin/user/UserDetailService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.admin.user; 17 | 18 | import org.springframework.security.core.userdetails.UserDetails; 19 | import org.springframework.security.core.userdetails.UserDetailsService; 20 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 21 | import org.springframework.stereotype.Component; 22 | 23 | /** 24 | * @author ZHENG BAO LE 25 | * @since 2019-01-28 26 | */ 27 | @Component 28 | public class UserDetailService implements UserDetailsService { 29 | 30 | private UserDetailsRepo users; 31 | 32 | public UserDetailService(UserDetailsRepo users) { 33 | this.users = users; 34 | } 35 | 36 | @Override 37 | public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException { 38 | return users.findByUsername(s).orElse(null); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /authmore-common/src/main/java/me/zbl/authmore/common/ResponseEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.common; 17 | 18 | import org.springframework.http.HttpStatus; 19 | import org.springframework.util.MultiValueMap; 20 | 21 | /** 22 | * @author ZHENG BAO LE 23 | * @since 2019-01-28 24 | */ 25 | public class ResponseEntity extends org.springframework.http.ResponseEntity { 26 | 27 | public ResponseEntity(HttpStatus status) { 28 | super(status); 29 | } 30 | 31 | public ResponseEntity(ResponseContent body, HttpStatus status) { 32 | super(body, status); 33 | } 34 | 35 | public ResponseEntity(MultiValueMap headers, HttpStatus status) { 36 | super(headers, status); 37 | } 38 | 39 | public ResponseEntity(ResponseContent body, MultiValueMap headers, HttpStatus status) { 40 | super(body, headers, status); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /authmore-core/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | plugins { 17 | id 'java' 18 | id 'maven-publish' 19 | } 20 | 21 | dependencies { 22 | implementation project(':authmore-common') 23 | testCompile group: 'junit', name: 'junit', version: '4.12' 24 | implementation 'org.springframework.security:spring-security-core:5.1.4.RELEASE' 25 | implementation 'com.nimbusds:nimbus-jose-jwt:6.0.2' 26 | implementation 'org.webjars:jquery:3.4.1' 27 | compileOnly 'org.springframework:spring-web:5.1.5.RELEASE' 28 | compileOnly 'org.springframework.security.oauth:spring-security-oauth2:2.3.3.RELEASE' 29 | compileOnly 'org.apache.tomcat.embed:tomcat-embed-core:9.0.14' 30 | compileOnly 'org.springframework.boot:spring-boot-starter-data-mongodb-reactive:2.1.2.RELEASE' 31 | compileOnly 'org.springframework.data:spring-data-redis:2.1.4.RELEASE' 32 | compileOnly "org.springframework.boot:spring-boot-configuration-processor:2.1.2.RELEASE" 33 | } -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | 3 | services: 4 | platform: 5 | image: jameszbl/authmore-platform 6 | command: ["--spring.profiles.active=prod"] 7 | environment: 8 | - token_type: JWT 9 | container_name: platform 10 | restart: unless-stopped 11 | networks: 12 | - authmore 13 | ports: 14 | - "8086:8086" 15 | depends_on: 16 | - mongo 17 | - redis 18 | 19 | admin: 20 | image: jameszbl/authmore-admin 21 | command: ["--spring.profiles.active=prod"] 22 | container_name: admin 23 | restart: unless-stopped 24 | networks: 25 | - authmore 26 | ports: 27 | - "8083:8083" 28 | depends_on: 29 | - mongo 30 | - redis 31 | 32 | ui: 33 | image: jameszbl/authmore-ui 34 | container_name: authmore-ui 35 | restart: unless-stopped 36 | networks: 37 | - authmore 38 | ports: 39 | - "3002:80" 40 | depends_on: 41 | - admin 42 | 43 | redis: 44 | image: redis 45 | ports: 46 | - "6379:6379" 47 | restart: unless-stopped 48 | container_name: authmore-redis 49 | networks: 50 | - authmore 51 | volumes: 52 | - redis-data:/data 53 | 54 | mongo: 55 | image: mongo 56 | ports: 57 | - "27017:27017" 58 | restart: unless-stopped 59 | container_name: authmore-mongo 60 | networks: 61 | - authmore 62 | volumes: 63 | - mongo-data:/data/db 64 | - mongo-config:/data/configdb 65 | 66 | networks: 67 | authmore: 68 | 69 | volumes: 70 | mongo-data: 71 | mongo-config: 72 | redis-data: 73 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/oauth/OAuthFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.oauth; 17 | 18 | import org.springframework.web.filter.OncePerRequestFilter; 19 | 20 | import javax.servlet.http.HttpServletResponse; 21 | import java.io.IOException; 22 | 23 | /** 24 | * @author ZHENG BAO LE 25 | * @since 2019-03-01 26 | */ 27 | public abstract class OAuthFilter extends OncePerRequestFilter { 28 | 29 | public void sendError(HttpServletResponse response) throws IOException { 30 | response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "oauth unauthorized"); 31 | } 32 | 33 | public void sendError(HttpServletResponse response, String message) throws IOException { 34 | response.sendError(HttpServletResponse.SC_UNAUTHORIZED, message); 35 | } 36 | 37 | public void sendError(HttpServletResponse response, String message, int status) throws IOException { 38 | response.sendError(status, message); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /authmore-platform/src/main/java/me/zbl/authmore/platform/authorization/ScopeConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.zbl.authmore.platform.authorization; 18 | 19 | import java.util.Arrays; 20 | 21 | /** 22 | * @author ZHENG BAO LE 23 | * @since 2019-05-30 24 | */ 25 | public enum ScopeConstants { 26 | 27 | AVATAR("头像"), 28 | EMAIL("邮件"), 29 | PROFILE("个人资料"), 30 | NICKNAME("昵称"), 31 | GENDER("性别"), 32 | AGE("年龄"), 33 | ADDRESS("地址"), 34 | UNKNOWN("其它范围"); 35 | 36 | private String name; 37 | 38 | ScopeConstants(String name) { 39 | this.name = name; 40 | } 41 | 42 | public String findByKey() { 43 | return name; 44 | } 45 | 46 | public static String findByKey(String key) { 47 | return Arrays.stream(ScopeConstants.values()).filter(v -> v.name().equals(key)) 48 | .findFirst() 49 | .orElse(ScopeConstants.UNKNOWN) 50 | .findByKey(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /authmore-admin/src/main/java/me/zbl/authmore/admin/client/ClientDetailService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.admin.client; 17 | 18 | import org.springframework.security.oauth2.provider.ClientDetails; 19 | import org.springframework.security.oauth2.provider.ClientDetailsService; 20 | import org.springframework.security.oauth2.provider.ClientRegistrationException; 21 | import org.springframework.stereotype.Component; 22 | 23 | /** 24 | * @author ZHENG BAO LE 25 | * @since 2019-01-28 26 | */ 27 | @Component 28 | public class ClientDetailService implements ClientDetailsService { 29 | 30 | private ClientDetailsRepo clientDetailsRepo; 31 | 32 | public ClientDetailService(ClientDetailsRepo clientDetailsRepo) { 33 | this.clientDetailsRepo = clientDetailsRepo; 34 | } 35 | 36 | @Override 37 | public ClientDetails loadClientByClientId(String id) throws ClientRegistrationException { 38 | return clientDetailsRepo.findByClientId(id).orElse(null); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/oauth/TokenManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.oauth; 17 | 18 | import me.zbl.authmore.ClientDetails; 19 | 20 | import java.util.Set; 21 | 22 | /** 23 | * @author ZHENG BAO LE 24 | * @since 2019-02-21 25 | */ 26 | public interface TokenManager { 27 | 28 | TokenResponse create(ClientDetails client, String userId, Set scopes); 29 | 30 | TokenResponse refresh(String refreshToken); 31 | 32 | AccessTokenBinding findAccessToken(String token); 33 | 34 | RefreshTokenBinding findRefreshToken(String token); 35 | 36 | RefreshTokenBinding freshRefreshTokenBinding(ClientDetails client, RefreshTokenBinding refreshTokenBinding); 37 | 38 | void saveAccessToken(AccessTokenBinding accessTokenBinding); 39 | 40 | void saveRefreshToken(RefreshTokenBinding refreshTokenBinding); 41 | 42 | void expireAccessToken(String token, long expireIn); 43 | 44 | void expireRefreshToken(String token, long expireIn); 45 | } 46 | -------------------------------------------------------------------------------- /authmore-common/src/main/java/me/zbl/authmore/common/BasicController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.common; 17 | 18 | import org.springframework.http.HttpStatus; 19 | 20 | import java.util.Map; 21 | 22 | /** 23 | * @author ZHENG BAO LE 24 | * @since 2019-01-28 25 | */ 26 | public class BasicController { 27 | 28 | public ResponseEntity success() { 29 | return new ResponseEntity(new ResponseContent("", "success"), HttpStatus.OK); 30 | } 31 | 32 | public ResponseEntity error() { 33 | return new ResponseEntity(new ResponseContent("", "error"), HttpStatus.INTERNAL_SERVER_ERROR); 34 | } 35 | 36 | public ResponseEntity badRequest() { 37 | return new ResponseEntity(new ResponseContent("", "invalid request"), HttpStatus.BAD_REQUEST); 38 | } 39 | 40 | public Map exist(boolean exist) { 41 | return map().put("result", exist).map(); 42 | } 43 | 44 | public ResultBuilder map() { 45 | return new ResultBuilder(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /authmore-client-sample/src/main/java/me/zbl/authmore/clientsample/ClientCredentialsEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.zbl.authmore.clientsample; 18 | 19 | import me.zbl.authmore.client.ClientRestTemplate; 20 | import org.springframework.beans.factory.annotation.Autowired; 21 | import org.springframework.web.bind.annotation.GetMapping; 22 | import org.springframework.web.bind.annotation.RestController; 23 | 24 | /** 25 | * @author ZHENG BAO LE 26 | * @since 2019-05-18 27 | */ 28 | @RestController 29 | public class ClientCredentialsEndpoint { 30 | 31 | private final ClientRestTemplate grantedClient; 32 | 33 | @Autowired 34 | public ClientCredentialsEndpoint(ClientRestTemplate grantedClient) { 35 | this.grantedClient = grantedClient; 36 | } 37 | 38 | @GetMapping(value = "/client", produces = {"application/json"}) 39 | public Object clientCredentials() { 40 | return this.grantedClient.getForObject("http://resource.authmore/inbox", String.class); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /authmore-platform/src/main/java/me/zbl/authmore/platform/oauth/TokenRefreshTokenIssuer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.platform.oauth; 17 | 18 | import me.zbl.authmore.ClientDetails; 19 | import me.zbl.authmore.oauth.OAuthUtil; 20 | import me.zbl.authmore.oauth.TokenManager; 21 | import me.zbl.authmore.oauth.TokenResponse; 22 | import org.springframework.stereotype.Component; 23 | 24 | import static me.zbl.authmore.oauth.OAuthProperties.GrantTypes.REFRESH_TOKEN; 25 | 26 | /** 27 | * @author ZHENG BAO LE 28 | * @since 2019-03-03 29 | */ 30 | @Component 31 | public final class TokenRefreshTokenIssuer { 32 | 33 | private final TokenManager tokenManager; 34 | 35 | public TokenRefreshTokenIssuer(TokenManager tokenManager) { 36 | this.tokenManager = tokenManager; 37 | } 38 | 39 | public TokenResponse issue(ClientDetails client, String refreshToken) { 40 | OAuthUtil.validateClientAndGrantType(client, REFRESH_TOKEN); 41 | return tokenManager.refresh(refreshToken); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/client/ImplicitAuthorizationEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.zbl.authmore.client; 18 | 19 | import org.springframework.beans.factory.annotation.Autowired; 20 | import org.springframework.stereotype.Controller; 21 | import org.springframework.ui.Model; 22 | import org.springframework.web.bind.annotation.GetMapping; 23 | 24 | /** 25 | * @author ZHENG BAO LE 26 | * @since 2019-05-17 27 | */ 28 | @Controller 29 | public class ImplicitAuthorizationEndpoint { 30 | 31 | private final ClientConfigurationProperties clientProperties; 32 | 33 | @Autowired 34 | public ImplicitAuthorizationEndpoint(ClientConfigurationProperties clientProperties) { 35 | this.clientProperties = clientProperties; 36 | } 37 | 38 | @GetMapping("/implicit.html") 39 | public String view(Model model) { 40 | String callBackUri = clientProperties.getImplicitTokenUri(); 41 | model.addAttribute("callBackUri", callBackUri); 42 | return "implicit"; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /authmore-platform/src/main/java/me/zbl/authmore/platform/authorization/UserSessionManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.platform.authorization; 17 | 18 | import me.zbl.authmore.UserDetails; 19 | import me.zbl.authmore.authorization.SessionManager; 20 | import org.springframework.stereotype.Service; 21 | 22 | import javax.servlet.http.HttpSession; 23 | 24 | import static me.zbl.authmore.authorization.SessionProperties.CURRENT_USER; 25 | import static me.zbl.authmore.authorization.SessionProperties.CURRENT_USER_DETAILS; 26 | 27 | /** 28 | * @author ZHENG BAO LE 29 | * @since 2019-02-15 30 | */ 31 | @Service 32 | public class UserSessionManager implements SessionManager { 33 | 34 | private HttpSession session; 35 | 36 | public UserSessionManager(HttpSession session) { 37 | this.session = session; 38 | } 39 | 40 | @Override 41 | public void signin(UserDetails user) { 42 | session.setAttribute(CURRENT_USER_DETAILS, user); 43 | session.setAttribute(CURRENT_USER, user.getUsername()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /authmore-common/src/main/java/me/zbl/authmore/common/RandomSecret.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.common; 17 | 18 | import java.util.Random; 19 | 20 | /** 21 | * @author ZHENG BAO LE 22 | * @since 2019-02-10 23 | */ 24 | public class RandomSecret { 25 | 26 | private RandomSecret() {} 27 | 28 | public static String create() { 29 | return create(32); 30 | } 31 | 32 | public static String create(int length) { 33 | int p = 0; 34 | char[] table = new char[62]; 35 | StringBuilder sb = new StringBuilder(); 36 | Random random = new Random(); 37 | for (char i = '0'; i <= '9'; i++) { 38 | table[p++] = i; 39 | } 40 | for (char i = 'A'; i <= 'Z'; i++) { 41 | table[p++] = i; 42 | } 43 | for (char i = 'a'; i <= 'z'; i++) { 44 | table[p++] = i; 45 | } 46 | for (int i = 0; i < length; i++) { 47 | int po = random.nextInt(62); 48 | sb.append(String.valueOf(table[po])); 49 | } 50 | return sb.toString(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /authmore-resource-sample/src/main/java/me/zbl/authmore/sample/InboxResourceEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.zbl.authmore.sample; 18 | 19 | import me.zbl.authmore.resource.AuthorityRequired; 20 | import me.zbl.authmore.resource.ScopeRequired; 21 | import org.springframework.web.bind.annotation.GetMapping; 22 | import org.springframework.web.bind.annotation.RestController; 23 | 24 | import java.util.Arrays; 25 | 26 | /** 27 | * @author ZHENG BAO LE 28 | * @since 2019-04-18 29 | */ 30 | @RestController 31 | public class InboxResourceEndpoint { 32 | 33 | @GetMapping("/inbox") 34 | @ScopeRequired("EMAIL") 35 | @AuthorityRequired("READ") 36 | public Inbox inbox() { 37 | return new Inbox(Arrays.asList( 38 | new Email().setSubject("Hi, Tom! ").setFrom("James").setTo("Tom").setContent("Hello, Tom!"), 39 | new Email().setSubject("Hi, James! ").setFrom("Tom").setTo("James").setContent("Hi, James!"), 40 | new Email().setSubject("Go hiking! ").setFrom("Tony").setTo("James").setContent("James, Let's go hiking!"))); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /authmore-resource-sample/src/main/java/me/zbl/authmore/sample/ResourceServerConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.sample; 17 | 18 | import me.zbl.authmore.resource.ResourceServerFilter; 19 | import org.springframework.boot.web.servlet.FilterRegistrationBean; 20 | import org.springframework.context.annotation.Bean; 21 | import org.springframework.context.annotation.Configuration; 22 | 23 | import javax.servlet.Filter; 24 | 25 | /** 26 | * @author ZHENG BAO LE 27 | * @since 2019-02-28 28 | */ 29 | @Configuration 30 | public class ResourceServerConfiguration { 31 | 32 | private final ResourceServerFilter resourceServerFilter; 33 | 34 | public ResourceServerConfiguration(ResourceServerFilter resourceServerFilter) { 35 | this.resourceServerFilter = resourceServerFilter; 36 | } 37 | 38 | @Bean 39 | public FilterRegistrationBean filterRegistrationBean() { 40 | FilterRegistrationBean bean = new FilterRegistrationBean<>(); 41 | bean.addUrlPatterns("/*"); 42 | bean.setFilter(resourceServerFilter); 43 | return bean; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/oauth/OAuthErrorResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.oauth; 17 | 18 | import me.zbl.authmore.ErrorResponse; 19 | import org.springframework.web.bind.MissingServletRequestParameterException; 20 | 21 | /** 22 | * @author ZHENG BAO LE 23 | * @since 2019-02-19 24 | */ 25 | public final class OAuthErrorResponse implements ErrorResponse { 26 | 27 | private final String error; 28 | private final String error_description; 29 | 30 | public OAuthErrorResponse(OAuthException e) { 31 | this(e.getMessage(), e.getErrorDescription()); 32 | } 33 | 34 | public OAuthErrorResponse(MissingServletRequestParameterException e) { 35 | this("invalid request parameters", e.getMessage()); 36 | } 37 | 38 | public OAuthErrorResponse(String error, String error_description) { 39 | this.error = error; 40 | this.error_description = error_description; 41 | } 42 | 43 | public String getError() { 44 | return error; 45 | } 46 | 47 | @Override 48 | public String getError_description() { 49 | return error_description; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /authmore-resource-sample/src/main/java/me/zbl/authmore/sample/Email.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.zbl.authmore.sample; 18 | 19 | /** 20 | * @author ZHENG BAO LE 21 | * @since 2019-04-18 22 | */ 23 | public class Email { 24 | 25 | private String subject; 26 | private String from; 27 | private String to; 28 | private String content; 29 | 30 | public String getSubject() { 31 | return subject; 32 | } 33 | 34 | public Email setSubject(String subject) { 35 | this.subject = subject; 36 | return this; 37 | } 38 | 39 | public String getFrom() { 40 | return from; 41 | } 42 | 43 | public Email setFrom(String from) { 44 | this.from = from; 45 | return this; 46 | } 47 | 48 | public String getTo() { 49 | return to; 50 | } 51 | 52 | public Email setTo(String to) { 53 | this.to = to; 54 | return this; 55 | } 56 | 57 | public String getContent() { 58 | return content; 59 | } 60 | 61 | public Email setContent(String content) { 62 | this.content = content; 63 | return this; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /authmore-client-sample/src/main/java/me/zbl/authmore/clientsample/Email.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.zbl.authmore.clientsample; 18 | 19 | /** 20 | * @author ZHENG BAO LE 21 | * @since 2019-04-18 22 | */ 23 | public class Email { 24 | 25 | private String subject; 26 | private String from; 27 | private String to; 28 | private String content; 29 | 30 | public String getSubject() { 31 | return subject; 32 | } 33 | 34 | public Email setSubject(String subject) { 35 | this.subject = subject; 36 | return this; 37 | } 38 | 39 | public String getFrom() { 40 | return from; 41 | } 42 | 43 | public Email setFrom(String from) { 44 | this.from = from; 45 | return this; 46 | } 47 | 48 | public String getTo() { 49 | return to; 50 | } 51 | 52 | public Email setTo(String to) { 53 | this.to = to; 54 | return this; 55 | } 56 | 57 | public String getContent() { 58 | return content; 59 | } 60 | 61 | public Email setContent(String content) { 62 | this.content = content; 63 | return this; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /authmore-platform/src/main/java/me/zbl/authmore/platform/authorization/UserDetailsEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.platform.authorization; 17 | 18 | import me.zbl.authmore.UserDetails; 19 | import me.zbl.authmore.oauth.OAuthException; 20 | import me.zbl.authmore.resource.ScopeRequired; 21 | import org.springframework.web.bind.annotation.GetMapping; 22 | import org.springframework.web.bind.annotation.RequestParam; 23 | import org.springframework.web.bind.annotation.RestController; 24 | 25 | import static me.zbl.authmore.oauth.OAuthProperties.SCOPE_USER_DETAILS; 26 | 27 | /** 28 | * @author ZHENG BAO LE 29 | * @since 2019-02-25 30 | */ 31 | @RestController 32 | public class UserDetailsEndpoint { 33 | 34 | private final UserDetailsRepository users; 35 | 36 | public UserDetailsEndpoint(UserDetailsRepository users) { 37 | this.users = users; 38 | } 39 | 40 | @GetMapping("/user/details") 41 | @ScopeRequired({SCOPE_USER_DETAILS}) 42 | public UserDetails userDetails( 43 | @RequestParam("user_id") String userId) { 44 | return users.findById(userId).orElseThrow(() -> new OAuthException("no such user")); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/client/RefreshTokenManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.client; 17 | 18 | import me.zbl.authmore.common.Assert; 19 | import me.zbl.authmore.oauth.OAuthProperties; 20 | import org.springframework.web.client.RestTemplate; 21 | 22 | import java.util.Map; 23 | 24 | /** 25 | * @author ZHENG BAO LE 26 | * @since 2019-03-02 27 | */ 28 | public final class RefreshTokenManager extends AbstractClientTokenManager { 29 | 30 | public RefreshTokenManager( 31 | RestTemplate client, 32 | String clientId, 33 | String clientSecret, 34 | String tokenIssueUrl) { 35 | super(client, clientId, clientSecret, tokenIssueUrl); 36 | } 37 | 38 | @Override 39 | protected void enhanceQueryParams(Map params) { 40 | super.enhanceQueryParams(params); 41 | String refreshToken = params.get(OAuthProperties.PARAM_REFRESH_TOKEN); 42 | Assert.notEmpty(refreshToken, refreshToken); 43 | } 44 | 45 | @Override 46 | protected final OAuthProperties.GrantTypes getGrantType() { 47 | return OAuthProperties.GrantTypes.REFRESH_TOKEN; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /authmore-admin/src/main/java/me/zbl/authmore/admin/endpoint/JwkSetEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.admin.endpoint; 17 | 18 | import com.nimbusds.jose.jwk.JWKSet; 19 | import com.nimbusds.jose.jwk.RSAKey; 20 | import org.springframework.security.oauth2.provider.endpoint.FrameworkEndpoint; 21 | import org.springframework.web.bind.annotation.GetMapping; 22 | import org.springframework.web.bind.annotation.ResponseBody; 23 | 24 | import java.security.KeyPair; 25 | import java.security.Principal; 26 | import java.security.interfaces.RSAPublicKey; 27 | import java.util.Map; 28 | 29 | /** 30 | * @author ZHENG BAO LE 31 | * @since 2019-01-25 32 | */ 33 | @FrameworkEndpoint 34 | public class JwkSetEndpoint { 35 | 36 | private KeyPair keyPair; 37 | 38 | public JwkSetEndpoint(KeyPair keyPair) { 39 | this.keyPair = keyPair; 40 | } 41 | 42 | @GetMapping("/auth/jwk") 43 | @ResponseBody 44 | public Map getKey(Principal principal) { 45 | RSAPublicKey publicKey = (RSAPublicKey) this.keyPair.getPublic(); 46 | RSAKey key = new RSAKey.Builder(publicKey).build(); 47 | return new JWKSet(key).toJSONObject(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /authmore-admin/src/main/java/me/zbl/authmore/admin/client/ClientCreateResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.admin.client; 17 | 18 | import me.zbl.authmore.ClientDetails; 19 | 20 | /** 21 | * @author ZHENG BAO LE 22 | * @since 2019-02-09 23 | */ 24 | public class ClientCreateResult { 25 | 26 | private String clientId; 27 | private String clientSecret; 28 | 29 | private ClientCreateResult() { } 30 | 31 | public static ClientCreateResult build(ClientDetails clientDetails, String originalSecret) { 32 | return new ClientCreateResult(clientDetails.getClientId(), originalSecret); 33 | } 34 | 35 | private ClientCreateResult(String clientId, String clientSecret) { 36 | this.clientId = clientId; 37 | this.clientSecret = clientSecret; 38 | } 39 | 40 | public String getClientId() { 41 | return clientId; 42 | } 43 | 44 | public void setClientId(String clientId) { 45 | this.clientId = clientId; 46 | } 47 | 48 | public String getClientSecret() { 49 | return clientSecret; 50 | } 51 | 52 | public void setClientSecret(String clientSecret) { 53 | this.clientSecret = clientSecret; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /authmore-platform/src/main/java/me/zbl/authmore/platform/oauth/TokenClientCredentialsTokenIssuer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.platform.oauth; 17 | 18 | import me.zbl.authmore.ClientDetails; 19 | import me.zbl.authmore.oauth.OAuthUtil; 20 | import me.zbl.authmore.oauth.TokenManager; 21 | import me.zbl.authmore.oauth.TokenResponse; 22 | import org.springframework.stereotype.Component; 23 | 24 | import java.util.Set; 25 | 26 | import static me.zbl.authmore.oauth.OAuthProperties.GrantTypes.CLIENT_CREDENTIALS; 27 | 28 | /** 29 | * @author ZHENG BAO LE 30 | * @since 2019-03-03 31 | */ 32 | @Component 33 | public final class TokenClientCredentialsTokenIssuer { 34 | 35 | private final TokenManager tokenManager; 36 | 37 | public TokenClientCredentialsTokenIssuer(TokenManager tokenManager) { 38 | this.tokenManager = tokenManager; 39 | } 40 | 41 | public TokenResponse issue(ClientDetails client, String scope) { 42 | OAuthUtil.validateClientAndGrantType(client, CLIENT_CREDENTIALS); 43 | OAuthUtil.validateClientAndScope(client, scope); 44 | Set scopes = OAuthUtil.scopeSet(scope); 45 | return tokenManager.create(client, null, scopes); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /authmore-platform/src/test/java/me/zbl/authmore/platform/RSAKeyPairTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.zbl.authmore.platform; 18 | 19 | import com.nimbusds.jose.JOSEException; 20 | import com.nimbusds.jose.jwk.KeyType; 21 | import com.nimbusds.jose.jwk.KeyUse; 22 | import com.nimbusds.jose.jwk.RSAKey; 23 | import com.nimbusds.jose.jwk.gen.RSAKeyGenerator; 24 | import org.junit.Test; 25 | 26 | import java.util.UUID; 27 | 28 | import static org.junit.Assert.assertEquals; 29 | 30 | /** 31 | * @author ZHENG BAO LE 32 | * @since 2019-05-14 33 | */ 34 | public class RSAKeyPairTest { 35 | 36 | @Test 37 | public void testJwkPairGeneration() throws JOSEException { 38 | 39 | String keyId = UUID.randomUUID().toString(); 40 | // Generate 2048-bit RSA key pair in JWK format, attach some metadata 41 | RSAKey jwk = new RSAKeyGenerator(2048) 42 | .keyUse(KeyUse.SIGNATURE) // indicate the intended use of the key 43 | .keyID(keyId) // give the key a unique ID 44 | .generate(); 45 | 46 | assertEquals(jwk.getKeyType(), KeyType.RSA); 47 | assertEquals(jwk.getKeyID(), keyId); 48 | assertEquals(jwk.getKeyUse(), KeyUse.SIGNATURE); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /authmore-admin/src/main/java/me/zbl/authmore/admin/client/ClientInitializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.admin.client; 17 | 18 | import me.zbl.authmore.ClientDetails; 19 | import org.springframework.beans.factory.SmartInitializingSingleton; 20 | import org.springframework.stereotype.Component; 21 | 22 | /** 23 | * @author ZHENG BAO LE 24 | * @since 2019-01-28 25 | */ 26 | @Component 27 | public class ClientInitializer implements SmartInitializingSingleton { 28 | 29 | private static final String ROOT_APP_ID = "5cb0dd412dc963313f1a90b1"; 30 | private ClientDetailsRepo clientDetailsRepo; 31 | 32 | public ClientInitializer(ClientDetailsRepo clientDetailsRepo) { 33 | this.clientDetailsRepo = clientDetailsRepo; 34 | } 35 | 36 | @Override 37 | public void afterSingletonsInstantiated() { 38 | ClientDetails client = new ClientDetails(ROOT_APP_ID, 39 | "authorization_code,password,implicit,client_credentials,refresh_token", "PROFILE", 40 | "{pbkdf2}30d47c8ef17066e65750bb6469b951dbaf8b40d4cf4b421490ffff92da00804700c8b8fb92cc9ce0", 41 | "", 999999, 42 | "SAMPLE", "SA"); 43 | client.setClientName("平台管理"); 44 | clientDetailsRepo.save(client); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /authmore-platform/src/main/java/me/zbl/authmore/platform/authorization/RedisCodeManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.platform.authorization; 17 | 18 | import me.zbl.authmore.authorization.AbstractCodeManager; 19 | import me.zbl.authmore.authorization.CodeBinding; 20 | import me.zbl.authmore.oauth.OAuthException; 21 | 22 | import static me.zbl.authmore.oauth.OAuthException.INVALID_CODE; 23 | 24 | /** 25 | * @author ZHENG BAO LE 26 | * @since 2019-02-18 27 | */ 28 | public class RedisCodeManager extends AbstractCodeManager { 29 | 30 | private final CodeRepository authorizationCodes; 31 | 32 | public RedisCodeManager(CodeRepository authorizationCodes) { 33 | super(); 34 | this.authorizationCodes = authorizationCodes; 35 | } 36 | 37 | @Override 38 | public void saveCode(CodeBinding codeBinding) { 39 | authorizationCodes.save(codeBinding); 40 | } 41 | 42 | @Override 43 | public CodeBinding getCodeDetails(String clientId, String code) { 44 | return authorizationCodes.findById(code) 45 | .orElseThrow(() -> new OAuthException(INVALID_CODE)); 46 | } 47 | 48 | @Override 49 | public void expireCode(String code) { 50 | authorizationCodes.deleteById(code); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /authmore-client-sample/src/main/java/me/zbl/authmore/clientsample/ClientSampleApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.clientsample; 17 | 18 | import org.springframework.boot.SpringApplication; 19 | import org.springframework.boot.autoconfigure.SpringBootApplication; 20 | 21 | /** 22 | * Sample application for authmore-client-springboot-starter 23 | *

24 | * Document for testing: 25 | *

26 | * { 27 | * "_id":"5cb7e7bcee173c60c379e04e", 28 | * "authorizedGrantTypes":"authorization_code,password,implicit,client_credentials", 29 | * "scoped":true,"scope":"PROFILE,EMAIL", 30 | * "resourceIds":"MAILBOX", 31 | * "isSecretRequired":true, 32 | * "clientSecret":"{pbkdf2}cce0073b0e62e2922fe0e9d145da19dc4f3c63c1af95009fd2d1492ecf8c4a5b84a1a72d6013fb1e", 33 | * "authorities":"READ", 34 | * "registeredRedirectUri":"http://client.authmore/inbox,http://client.authmore/implicit.html", 35 | * "accessTokenValiditySeconds":99999, 36 | * "isAutoApprove":true, 37 | * "clientName":"Mailbox Reader", 38 | * "_class":"me.zbl.authmore.core.ClientDetails" 39 | * } 40 | *

41 | */ 42 | @SpringBootApplication 43 | public class ClientSampleApplication { 44 | 45 | public static void main(String[] args) { 46 | SpringApplication.run(ClientSampleApplication.class, args); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/oauth/RefreshTokenBinding.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.oauth; 17 | 18 | import org.springframework.data.annotation.Id; 19 | import org.springframework.data.redis.core.RedisHash; 20 | 21 | import java.io.Serializable; 22 | import java.util.Set; 23 | 24 | /** 25 | * @author ZHENG BAO LE 26 | * @since 2019-02-26 27 | */ 28 | @RedisHash(value = OAuthProperties.KEY_PREFIX_REFRESH_TOKEN_BINDING) 29 | public final class RefreshTokenBinding implements Serializable { 30 | 31 | @Id 32 | private final String refreshToken; 33 | private final String clientId; 34 | private final Set scopes; 35 | private final String userId; 36 | 37 | public RefreshTokenBinding(String refreshToken, String clientId, Set scopes, String userId) { 38 | this.refreshToken = refreshToken; 39 | this.clientId = clientId; 40 | this.scopes = scopes; 41 | this.userId = userId; 42 | } 43 | 44 | public String getRefreshToken() { 45 | return refreshToken; 46 | } 47 | 48 | public String getClientId() { 49 | return clientId; 50 | } 51 | 52 | public Set getScopes() { 53 | return scopes; 54 | } 55 | 56 | public String getUserId() { 57 | return userId; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/client/PasswordTokenManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.client; 17 | 18 | import me.zbl.authmore.common.Assert; 19 | import me.zbl.authmore.oauth.OAuthProperties; 20 | import org.springframework.web.client.RestTemplate; 21 | 22 | import java.util.Map; 23 | 24 | /** 25 | * @author ZHENG BAO LE 26 | * @since 2019-03-02 27 | */ 28 | public final class PasswordTokenManager extends AbstractClientTokenManager { 29 | 30 | public PasswordTokenManager( 31 | RestTemplate client, 32 | String clientId, 33 | String clientSecret, 34 | String tokenIssueUrl) { 35 | super(client, clientId, clientSecret, tokenIssueUrl); 36 | } 37 | 38 | @Override 39 | protected void enhanceQueryParams(Map params) { 40 | super.enhanceQueryParams(params); 41 | String userName = params.get(OAuthProperties.PARAM_USERNAME); 42 | String password = params.get(OAuthProperties.PARAM_PASSWORD); 43 | Assert.notEmpty(userName, "username cannot be empty"); 44 | Assert.notEmpty(password, "password cannot be empty"); 45 | } 46 | 47 | @Override 48 | protected final OAuthProperties.GrantTypes getGrantType() { 49 | return OAuthProperties.GrantTypes.PASSWORD; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /authmore-platform/src/main/java/me/zbl/authmore/platform/ErrorEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.platform; 17 | 18 | import me.zbl.authmore.ErrorResponse; 19 | import me.zbl.authmore.oauth.OAuthErrorResponse; 20 | import org.springframework.boot.autoconfigure.web.servlet.error.AbstractErrorController; 21 | import org.springframework.boot.web.servlet.error.ErrorAttributes; 22 | import org.springframework.web.bind.annotation.RequestMapping; 23 | import org.springframework.web.bind.annotation.RestController; 24 | 25 | import javax.servlet.http.HttpServletRequest; 26 | import java.util.Map; 27 | 28 | /** 29 | * @author ZHENG BAO LE 30 | * @since 2019-03-05 31 | */ 32 | @RestController 33 | public class ErrorEndpoint extends AbstractErrorController { 34 | 35 | public ErrorEndpoint(ErrorAttributes errorAttributes) { 36 | super(errorAttributes); 37 | } 38 | 39 | @RequestMapping("/error") 40 | public ErrorResponse error(HttpServletRequest request) { 41 | Map errorAttributes = super.getErrorAttributes(request, false); 42 | String message = (String) errorAttributes.getOrDefault("message", "unknown error"); 43 | return new OAuthErrorResponse(message, "no description"); 44 | } 45 | 46 | @Override 47 | public String getErrorPath() { 48 | return "/error"; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /authmore-client-sample/src/main/java/me/zbl/authmore/clientsample/PasswordEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.clientsample; 17 | 18 | import me.zbl.authmore.client.ClientRestTemplate; 19 | import me.zbl.authmore.client.PasswordTokenManager; 20 | import me.zbl.authmore.oauth.TokenResponse; 21 | import org.springframework.web.bind.annotation.GetMapping; 22 | import org.springframework.web.bind.annotation.RestController; 23 | import org.springframework.web.client.RestTemplate; 24 | 25 | import java.util.HashMap; 26 | import java.util.Map; 27 | 28 | /** 29 | * @author ZHENG BAO LE 30 | * @since 2019-03-01 31 | */ 32 | @RestController 33 | public class PasswordEndpoint { 34 | 35 | private final PasswordTokenManager passwordTokenManager; 36 | 37 | public PasswordEndpoint(PasswordTokenManager passwordTokenManager) { 38 | this.passwordTokenManager = passwordTokenManager; 39 | } 40 | 41 | @GetMapping(value = "/password", produces = {"application/json"}) 42 | public Object password() { 43 | Map params = new HashMap<>(); 44 | params.put("username", "james"); 45 | params.put("password", "123456"); 46 | TokenResponse token = passwordTokenManager.getToken("EMAIL", params); 47 | RestTemplate template = new ClientRestTemplate(token.getAccess_token()); 48 | return template.getForObject("http://resource.authmore/inbox", String.class); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/client/AuthorizationCodeTokenManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.client; 17 | 18 | import me.zbl.authmore.common.Assert; 19 | import me.zbl.authmore.oauth.OAuthProperties; 20 | import org.springframework.web.client.RestTemplate; 21 | 22 | import java.util.Map; 23 | 24 | import static me.zbl.authmore.oauth.OAuthProperties.GrantTypes; 25 | 26 | /** 27 | * @author ZHENG BAO LE 28 | * @since 2019-03-02 29 | */ 30 | public final class AuthorizationCodeTokenManager extends AbstractClientTokenManager { 31 | 32 | private String redirectUri; 33 | 34 | public AuthorizationCodeTokenManager( 35 | RestTemplate client, 36 | String clientId, 37 | String clientSecret, 38 | String tokenIssueUrl, 39 | String redirectUri) { 40 | super(client, clientId, clientSecret, tokenIssueUrl); 41 | this.redirectUri = redirectUri; 42 | } 43 | 44 | @Override 45 | protected void enhanceQueryParams(Map params) { 46 | super.enhanceQueryParams(params); 47 | params.put(OAuthProperties.PARAM_REDIRECT_URI, redirectUri); 48 | String code = params.get(OAuthProperties.PARAM_CODE); 49 | Assert.notEmpty(code, "code cannot be empty"); 50 | } 51 | 52 | @Override 53 | protected final GrantTypes getGrantType() { 54 | return GrantTypes.AUTHORIZATION_CODE; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /authmore-common/src/test/java/me/zbl/authmore/common/RandomSecretTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.common; 17 | 18 | import org.apache.log4j.BasicConfigurator; 19 | import org.junit.jupiter.api.BeforeEach; 20 | import org.junit.jupiter.api.Test; 21 | import org.slf4j.Logger; 22 | import org.slf4j.LoggerFactory; 23 | 24 | import java.util.HashSet; 25 | 26 | import static org.junit.jupiter.api.Assertions.*; 27 | 28 | /** 29 | * @author ZHENG BAO LE 30 | * @since 2019-02-10 31 | */ 32 | public class RandomSecretTest { 33 | 34 | private static final Logger LOGGER = LoggerFactory.getLogger(RandomSecretTest.class); 35 | 36 | @BeforeEach 37 | void setup() { 38 | BasicConfigurator.configure(); 39 | } 40 | 41 | @Test 42 | void build() { 43 | String last = null; 44 | HashSet digests = new HashSet<>(); 45 | for (int i = 0; i < 100; i++) { 46 | String pwd = RandomSecret.create(); 47 | char[] chars = pwd.toCharArray(); 48 | assertNotNull(pwd); 49 | assertEquals(32, pwd.length()); 50 | assertNotEquals(last, pwd); 51 | for (int j = 0; j < pwd.length(); j++) { 52 | char c = chars[j]; 53 | assertTrue(c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z'); 54 | } 55 | assertFalse(digests.contains(pwd)); 56 | digests.add(pwd); 57 | last = pwd; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /authmore-admin/src/main/java/me/zbl/authmore/admin/user/UserInitializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.admin.user; 17 | 18 | import me.zbl.authmore.UserDetails; 19 | import me.zbl.authmore.common.RandomSecret; 20 | import org.springframework.beans.factory.SmartInitializingSingleton; 21 | import org.springframework.dao.DuplicateKeyException; 22 | import org.springframework.security.crypto.password.PasswordEncoder; 23 | import org.springframework.stereotype.Component; 24 | 25 | /** 26 | * @author ZHENG BAO LE 27 | * @since 2019-01-28 28 | */ 29 | @Component 30 | public class UserInitializer implements SmartInitializingSingleton { 31 | 32 | private UserDetailsRepo users; 33 | private PasswordEncoder passwordEncoder; 34 | 35 | public UserInitializer(UserDetailsRepo users, PasswordEncoder passwordEncoder) { 36 | this.users = users; 37 | this.passwordEncoder = passwordEncoder; 38 | } 39 | 40 | @Override 41 | public void afterSingletonsInstantiated() { 42 | String randomPassword = RandomSecret.create(); 43 | String rootUsername = "root"; 44 | UserDetails user = users.findByUsername(rootUsername).orElse( 45 | new UserDetails("root", "SA")) 46 | .setUserPassword(passwordEncoder.encode(randomPassword)); 47 | try { 48 | users.save(user); 49 | } catch (DuplicateKeyException ignored) { 50 | } 51 | 52 | System.out.println("\n\nAuthmore root password: " + randomPassword + "\n\n"); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /authmore-platform/src/main/java/me/zbl/authmore/platform/jwk/JWKConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.zbl.authmore.platform.jwk; 18 | 19 | import com.nimbusds.jose.jwk.JWK; 20 | import com.nimbusds.jose.jwk.JWKSet; 21 | import com.nimbusds.jose.jwk.KeyUse; 22 | import com.nimbusds.jose.jwk.RSAKey; 23 | import org.springframework.context.annotation.Bean; 24 | import org.springframework.context.annotation.Configuration; 25 | 26 | import java.security.KeyPair; 27 | import java.security.KeyPairGenerator; 28 | import java.security.NoSuchAlgorithmException; 29 | import java.security.interfaces.RSAPrivateKey; 30 | import java.security.interfaces.RSAPublicKey; 31 | import java.util.UUID; 32 | 33 | /** 34 | * @author ZHENG BAO LE 35 | * @since 2019-05-14 36 | */ 37 | @Configuration 38 | public class JWKConfiguration { 39 | 40 | @Bean 41 | public JWKSet jwkSet() throws NoSuchAlgorithmException { 42 | 43 | KeyPair keyPair = keyPair(); 44 | JWK jwk = new RSAKey.Builder((RSAPublicKey) keyPair.getPublic()) 45 | .privateKey((RSAPrivateKey) keyPair.getPrivate()) 46 | .keyUse(KeyUse.SIGNATURE) 47 | .keyID(UUID.randomUUID().toString()) 48 | .build(); 49 | return new JWKSet(jwk); 50 | } 51 | 52 | @Bean 53 | public KeyPair keyPair() throws NoSuchAlgorithmException { 54 | KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA"); 55 | gen.initialize(2048); 56 | return gen.generateKeyPair(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/authorization/CodeBinding.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.authorization; 17 | 18 | import me.zbl.authmore.oauth.OAuthProperties; 19 | import org.springframework.data.annotation.Id; 20 | import org.springframework.data.redis.core.RedisHash; 21 | 22 | import java.io.Serializable; 23 | import java.util.Set; 24 | 25 | /** 26 | * @author ZHENG BAO LE 27 | * @since 2019-02-19 28 | */ 29 | @RedisHash(value = OAuthProperties.KEY_PREFIX_CODE_BINDING, timeToLive = OAuthProperties.CODE_VALIDITY_SECONDS) 30 | public final class CodeBinding implements Serializable { 31 | 32 | @Id 33 | private final String code; 34 | private final String clientId; 35 | private final Set scopes; 36 | private final String redirectUri; 37 | private final String userId; 38 | 39 | public CodeBinding(String code, String clientId, Set scopes, String redirectUri, String userId) { 40 | this.code = code; 41 | this.clientId = clientId; 42 | this.scopes = scopes; 43 | this.redirectUri = redirectUri; 44 | this.userId = userId; 45 | } 46 | 47 | public String getCode() { 48 | return code; 49 | } 50 | 51 | public String getClientId() { 52 | return clientId; 53 | } 54 | 55 | public Set getScopes() { 56 | return scopes; 57 | } 58 | 59 | public String getRedirectUri() { 60 | return redirectUri; 61 | } 62 | 63 | public String getUserId() { 64 | return userId; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /authmore-platform/src/main/java/me/zbl/authmore/platform/oauth/TokenConfigurationProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.zbl.authmore.platform.oauth; 18 | 19 | import org.springframework.boot.context.properties.ConfigurationProperties; 20 | import org.springframework.stereotype.Component; 21 | 22 | import static org.springframework.util.StringUtils.isEmpty; 23 | 24 | /** 25 | * @author ZHENG BAO LE 26 | * @since 2019-05-30 27 | */ 28 | @Component 29 | @ConfigurationProperties(prefix = "token") 30 | public class TokenConfigurationProperties { 31 | 32 | private final static String ENV_TOKEN_TYPE = "token_type"; 33 | 34 | private String tokenType = System.getenv(ENV_TOKEN_TYPE); 35 | 36 | enum TokenPolicy { 37 | REDIS, JWT 38 | } 39 | 40 | private TokenPolicy policy; 41 | 42 | public TokenPolicy getPolicy() { 43 | String tokenTypeName = getTokenTypeName(); 44 | if (isEmpty(tokenTypeName)) { 45 | return policy; 46 | } 47 | switch (tokenTypeName) { 48 | case "jwt": 49 | return TokenPolicy.JWT; 50 | case "redis": 51 | return TokenPolicy.REDIS; 52 | default: 53 | return policy; 54 | } 55 | } 56 | 57 | private String getTokenTypeName() { 58 | String name = null; 59 | if (!isEmpty(tokenType)) { 60 | name = tokenType.toLowerCase(); 61 | } 62 | return name; 63 | } 64 | 65 | public void setPolicy(TokenPolicy policy) { 66 | this.policy = policy; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/resource/ResourceServerConfigurationProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.resource; 17 | 18 | import org.springframework.boot.context.properties.ConfigurationProperties; 19 | 20 | /** 21 | * @author ZHENG BAO LE 22 | * @since 2019-02-28 23 | */ 24 | @ConfigurationProperties(prefix = "authmore.resource") 25 | public class ResourceServerConfigurationProperties { 26 | 27 | private String resourceId; 28 | 29 | private String tokenInfoUrl; 30 | 31 | private String clientId; 32 | 33 | private String clientSecret; 34 | 35 | private String jwkSetUrl; 36 | 37 | public String getResourceId() { 38 | return resourceId; 39 | } 40 | 41 | public void setResourceId(String resourceId) { 42 | this.resourceId = resourceId; 43 | } 44 | 45 | public String getTokenInfoUrl() { 46 | return tokenInfoUrl; 47 | } 48 | 49 | public void setTokenInfoUrl(String tokenInfoUrl) { 50 | this.tokenInfoUrl = tokenInfoUrl; 51 | } 52 | 53 | public String getClientId() { 54 | return clientId; 55 | } 56 | 57 | public void setClientId(String clientId) { 58 | this.clientId = clientId; 59 | } 60 | 61 | public String getClientSecret() { 62 | return clientSecret; 63 | } 64 | 65 | public void setClientSecret(String clientSecret) { 66 | this.clientSecret = clientSecret; 67 | } 68 | 69 | public String getJwkSetUrl() { 70 | return jwkSetUrl; 71 | } 72 | 73 | public void setJwkSetUrl(String jwkSetUrl) { 74 | this.jwkSetUrl = jwkSetUrl; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /authmore-client-springboot-starter/src/main/java/me/zbl/authmore/configuration/AuthorizeAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.configuration; 17 | 18 | import me.zbl.authmore.client.AuthorizationTemplate; 19 | import me.zbl.authmore.client.ClientConfigurationProperties; 20 | import me.zbl.authmore.client.ClientRestTemplate; 21 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 22 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 23 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 24 | import org.springframework.context.annotation.Bean; 25 | import org.springframework.context.annotation.Configuration; 26 | import org.springframework.security.authentication.AuthenticationManager; 27 | 28 | /** 29 | * @author ZHENG BAO LE 30 | * @since 2019-03-07 31 | */ 32 | @Configuration 33 | @ConditionalOnClass({ClientRestTemplate.class}) 34 | @EnableConfigurationProperties({ClientConfigurationProperties.class}) 35 | public class AuthorizeAutoConfiguration { 36 | 37 | private final ClientConfigurationProperties clientProperties; 38 | 39 | public AuthorizeAutoConfiguration(ClientConfigurationProperties clientProperties) { 40 | this.clientProperties = clientProperties; 41 | } 42 | 43 | @Bean 44 | @ConditionalOnMissingBean({AuthorizationTemplate.class}) 45 | public AuthorizationTemplate authorizationTemplate() { 46 | return new AuthorizationTemplate(clientProperties); 47 | } 48 | 49 | @Bean 50 | public AuthenticationManager authenticationManager() { 51 | return authentication -> null; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/oauth/OAuthException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.oauth; 17 | 18 | /** 19 | * @author ZHENG BAO LE 20 | * @since 2019-02-14 21 | */ 22 | public class OAuthException extends RuntimeException { 23 | 24 | public static final String ERROR = "error"; 25 | public static final String DESCRIPTION = "error_description"; 26 | public static final String URI = "error_uri"; 27 | public static final String INVALID_REQUEST = "invalid_request"; 28 | public static final String INVALID_CLIENT = "invalid_client"; 29 | public static final String INVALID_GRANT = "invalid_grant"; 30 | public static final String UNAUTHORIZED_CLIENT = "unauthorized_client"; 31 | public static final String UNSUPPORTED_GRANT_TYPE = "unsupported_grant_type"; 32 | public static final String INVALID_SCOPE = "invalid_scope"; 33 | public static final String INSUFFICIENT_SCOPE = "insufficient_scope"; 34 | public static final String INVALID_TOKEN = "invalid_token"; 35 | public static final String REDIRECT_URI_MISMATCH = "redirect_uri_mismatch"; 36 | public static final String UNSUPPORTED_RESPONSE_TYPE = "unsupported_response_type"; 37 | public static final String ACCESS_DENIED = "access_denied"; 38 | public static final String INVALID_CODE = "invalid_code"; 39 | 40 | public OAuthException() { 41 | super(ERROR); 42 | } 43 | 44 | public OAuthException(String message) { 45 | super(message); 46 | } 47 | 48 | public OAuthException(String message, Throwable cause) { 49 | super(message, cause); 50 | } 51 | 52 | public String getErrorDescription() { 53 | return ""; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /authmore-admin/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | buildscript { 17 | ext { 18 | springBootVersion = '2.1.2.RELEASE' 19 | } 20 | repositories { 21 | mavenCentral() 22 | } 23 | dependencies { 24 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 25 | } 26 | } 27 | 28 | apply plugin: 'java' 29 | apply plugin: 'org.springframework.boot' 30 | apply plugin: 'io.spring.dependency-management' 31 | apply plugin: "maven-publish" 32 | 33 | jar { 34 | enabled = true 35 | } 36 | 37 | dependencies { 38 | implementation project(':authmore-core') 39 | implementation project(':authmore-common') 40 | implementation 'org.springframework.boot:spring-boot-starter-data-redis-reactive' 41 | implementation 'org.springframework.boot:spring-boot-starter-security' 42 | implementation 'org.springframework.boot:spring-boot-starter-web' 43 | implementation 'org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.1.2.RELEASE' 44 | implementation 'org.springframework.security:spring-security-oauth2-jose' 45 | implementation 'org.springframework.boot:spring-boot-configuration-processor' 46 | implementation 'org.springframework.boot:spring-boot-starter-data-mongodb-reactive' 47 | testCompile 'org.springframework.boot:spring-boot-starter-test:2.1.2.RELEASE' 48 | testCompile 'org.springframework.security:spring-security-test:5.1.3.RELEASE' 49 | } 50 | 51 | docker { 52 | springBootApplication { 53 | ports = [8083] 54 | tag = "${registryRepository}/authmore-admin" 55 | } 56 | } 57 | 58 | signMavenJavaPublication.enabled = false 59 | publishMavenJavaPublicationToMavenRepository.enabled = false -------------------------------------------------------------------------------- /authmore-platform/src/main/java/me/zbl/authmore/platform/oauth/TokenAuthorizationCodeTokenIssuer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.platform.oauth; 17 | 18 | import me.zbl.authmore.ClientDetails; 19 | import me.zbl.authmore.authorization.CodeBinding; 20 | import me.zbl.authmore.oauth.CodeManager; 21 | import me.zbl.authmore.oauth.OAuthException; 22 | import me.zbl.authmore.oauth.TokenManager; 23 | import me.zbl.authmore.oauth.TokenResponse; 24 | import org.springframework.stereotype.Component; 25 | 26 | import java.util.Set; 27 | 28 | import static org.springframework.util.StringUtils.isEmpty; 29 | 30 | /** 31 | * @author ZHENG BAO LE 32 | * @since 2019-03-02 33 | */ 34 | @Component 35 | final class TokenAuthorizationCodeTokenIssuer { 36 | 37 | private final CodeManager codeManager; 38 | private final TokenManager tokenManager; 39 | 40 | public TokenAuthorizationCodeTokenIssuer(CodeManager codeManager, TokenManager tokenManager) { 41 | this.codeManager = codeManager; 42 | this.tokenManager = tokenManager; 43 | } 44 | 45 | public TokenResponse issue(ClientDetails client, String redirectUri, String code) { 46 | CodeBinding codeBinding = codeManager.getCodeDetails(client.getClientId(), code); 47 | Set scopes = codeBinding.getScopes(); 48 | String requestRedirectUri = codeBinding.getRedirectUri(); 49 | if (isEmpty(redirectUri) || !redirectUri.equals(requestRedirectUri)) { 50 | throw new OAuthException(OAuthException.REDIRECT_URI_MISMATCH); 51 | } 52 | codeManager.expireCode(code); 53 | String userId = codeBinding.getUserId(); 54 | return tokenManager.create(client, userId, scopes); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Authmore-Logo 4 | 5 |

6 | 7 |

8 | 基于 OAuth2.0 协议的开放平台认证授权开发套件 9 |

10 | 11 |

12 | 13 | Maven Central 14 | 15 | 16 | 17 | Travis-CI 18 | 19 | 20 | 21 | Apache2 License 22 | 23 |

24 | 25 | # 简介 | Intro 26 | 27 | 基于 OAuth2.0 协议的开放平台认证授权开发套件, 包含授权服务和开放平台 Docker 镜像,基于 Spring Boot Starter 的资源服务工具包和客户端(第三方应用)工具包 28 | 29 | # 优点 | Advantages 30 | 31 | - **简洁**:专注核心功能 —— 社会化网络下的跨应用认证授权,基于 Spring Boot Starter 的工具包,为开发者提供最简洁的配置。 32 | - **快速**:Authmore 提供了客户端和资源服务端 SDK 及认证中心 Docker 镜像,一键部署,开箱即用。 33 | - **高效**:基于 React.js 和 Ant Design 的认证中心管理系统,帮助开发者随时随地地管理应用,使数据操作透明化。 34 | 35 | # 文档 | Documentation 36 | 37 | 集成和配置详细指南请参考 [Authmore 最新开发手册](https://doc.authmore.letec.top) 38 | 39 | # 原理 | Principle 40 | 41 | ![项目架构原理](.doc/principle.svg) 42 | 43 | # 结构目录 | Architecture 44 | 45 | ![项目结构说明](.doc/structure.png) 46 | 47 | # 最新版本 | Latest Version 48 | 49 | > 提供最新版开放平台管理应用的 Docker 镜像,当然你也可以在开发环境下对源码打包部署 50 | 51 | * **认证平台 Doccker 镜像** 52 | ``` 53 | jameszbl/authmore-platform:latest 54 | 55 | jameszbl/authmore-admin:latest 56 | 57 | jameszbl/authmore-ui:latest 58 | ``` 59 | * **客户端 SDK** 60 | ```xml 61 | 62 | com.github.jameszbl 63 | authmore-client-springboot-starter 64 | latest version 65 | 66 | ``` 67 | 68 | * **资源服务 SDK** 69 | ```xml 70 | 71 | com.github.jameszbl 72 | authmore-resource-springboot-starter 73 | latest version 74 | 75 | ``` 76 | 77 | # 版权 | License 78 | 79 | [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0) 80 | 81 | # 关注我 | About Me 82 | 83 | [摆码王子的小屋](https://b.letec.top) 84 | -------------------------------------------------------------------------------- /authmore-platform/src/main/java/me/zbl/authmore/platform/oauth/ExceptionHandlers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.platform.oauth; 17 | 18 | import me.zbl.authmore.authorization.AuthorizationException; 19 | import me.zbl.authmore.oauth.OAuthErrorResponse; 20 | import me.zbl.authmore.oauth.OAuthException; 21 | import org.springframework.http.HttpStatus; 22 | import org.springframework.ui.Model; 23 | import org.springframework.web.bind.MissingServletRequestParameterException; 24 | import org.springframework.web.bind.annotation.ControllerAdvice; 25 | import org.springframework.web.bind.annotation.ExceptionHandler; 26 | import org.springframework.web.bind.annotation.ResponseBody; 27 | import org.springframework.web.bind.annotation.ResponseStatus; 28 | 29 | /** 30 | * @author ZHENG BAO LE 31 | * @since 2019-02-18 32 | */ 33 | @ControllerAdvice 34 | public class ExceptionHandlers { 35 | 36 | @ResponseStatus(HttpStatus.BAD_REQUEST) 37 | @ExceptionHandler({AuthorizationException.class}) 38 | public String authorizationException(AuthorizationException exception, Model model) { 39 | String error = exception.getMessage(); 40 | model.addAttribute("error", error); 41 | return "error"; 42 | } 43 | 44 | @ResponseStatus(HttpStatus.BAD_REQUEST) 45 | @ResponseBody 46 | @ExceptionHandler({OAuthException.class}) 47 | public OAuthErrorResponse oAuthException(OAuthException exception) { 48 | return new OAuthErrorResponse(exception); 49 | } 50 | 51 | @ResponseStatus(HttpStatus.BAD_REQUEST) 52 | @ResponseBody 53 | @ExceptionHandler({MissingServletRequestParameterException.class}) 54 | public OAuthErrorResponse badRequest(MissingServletRequestParameterException exception) { 55 | return new OAuthErrorResponse(exception); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /authmore-platform/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | plugins { 17 | id 'org.springframework.boot' version '2.1.2.RELEASE' 18 | id 'maven-publish' 19 | id 'java' 20 | } 21 | 22 | apply plugin: 'io.spring.dependency-management' 23 | 24 | ext { 25 | set('springCloudVersion', 'Greenwich.RELEASE') 26 | } 27 | 28 | dependencies { 29 | implementation project(':authmore-core') 30 | implementation project(':authmore-common') 31 | implementation 'org.springframework.boot:spring-boot-starter-web' 32 | implementation 'org.springframework.boot:spring-boot-starter-data-mongodb-reactive' 33 | implementation 'org.springframework.boot:spring-boot-starter-freemarker' 34 | implementation 'org.springframework.security.oauth:spring-security-oauth2:2.3.3.RELEASE' 35 | implementation 'org.springframework.session:spring-session-data-redis' 36 | implementation 'org.springframework.boot:spring-boot-starter-data-redis-reactive' 37 | implementation 'com.nimbusds:nimbus-jose-jwt:6.0.2' 38 | implementation 'org.webjars:jquery:3.4.1' 39 | implementation 'org.webjars:bootstrap:4.3.1' 40 | runtimeOnly 'org.springframework.boot:spring-boot-devtools' 41 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 42 | testImplementation 'org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure' 43 | compileOnly "org.springframework.boot:spring-boot-configuration-processor:2.1.2.RELEASE" 44 | } 45 | 46 | dependencyManagement { 47 | imports { 48 | mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" 49 | } 50 | } 51 | 52 | docker { 53 | springBootApplication { 54 | ports = [8086] 55 | tag = "${registryRepository}/authmore-platform" 56 | } 57 | } 58 | 59 | jar { 60 | enabled = true 61 | } -------------------------------------------------------------------------------- /authmore-platform/src/main/java/me/zbl/authmore/platform/authorization/AuthenticationFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.platform.authorization; 17 | 18 | import me.zbl.authmore.UserDetails; 19 | import me.zbl.authmore.authorization.SessionProperties; 20 | import org.springframework.web.filter.OncePerRequestFilter; 21 | 22 | import javax.servlet.FilterChain; 23 | import javax.servlet.ServletException; 24 | import javax.servlet.annotation.WebFilter; 25 | import javax.servlet.http.HttpServletRequest; 26 | import javax.servlet.http.HttpServletResponse; 27 | import javax.servlet.http.HttpSession; 28 | import java.io.IOException; 29 | 30 | /** 31 | * @author ZHENG BAO LE 32 | * @since 2019-02-14 33 | */ 34 | @WebFilter(urlPatterns = {"/authorize"}) 35 | public final class AuthenticationFilter extends OncePerRequestFilter { 36 | 37 | @Override 38 | protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) 39 | throws IOException, ServletException { 40 | HttpSession session = request.getSession(true); 41 | UserDetails user = (UserDetails) session.getAttribute(SessionProperties.CURRENT_USER_DETAILS); 42 | if (null == user) { 43 | redirectToSignin(request, response); 44 | return; 45 | } 46 | 47 | filterChain.doFilter(request, response); 48 | } 49 | 50 | private void redirectToSignin(HttpServletRequest request, HttpServletResponse response) throws IOException { 51 | String requestURI = request.getRequestURI(); 52 | String queryString = request.getQueryString(); 53 | HttpSession session = request.getSession(); 54 | session.setAttribute(SessionProperties.LAST_URL, requestURI + "?" + queryString); 55 | response.sendRedirect("/signin"); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /authmore-client-sample/src/main/java/me/zbl/authmore/clientsample/ImplicitEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.zbl.authmore.clientsample; 18 | 19 | import me.zbl.authmore.client.AuthorizationTemplate; 20 | import me.zbl.authmore.client.ClientRestTemplate; 21 | import me.zbl.authmore.oauth.OAuthProperties; 22 | import me.zbl.authmore.oauth.TokenResponse; 23 | import org.springframework.beans.factory.annotation.Autowired; 24 | import org.springframework.web.bind.annotation.GetMapping; 25 | import org.springframework.web.bind.annotation.PostMapping; 26 | import org.springframework.web.bind.annotation.RequestBody; 27 | import org.springframework.web.bind.annotation.RestController; 28 | 29 | import javax.servlet.http.HttpServletResponse; 30 | import java.io.IOException; 31 | 32 | /** 33 | * @author ZHENG BAO LE 34 | * @since 2019-05-18 35 | */ 36 | @RestController 37 | public class ImplicitEndpoint { 38 | 39 | private final AuthorizationTemplate authorizationTemplate; 40 | private static final String SCOPES = "PROFILE+EMAIL"; 41 | 42 | @Autowired 43 | public ImplicitEndpoint(AuthorizationTemplate authorizationTemplate) { 44 | this.authorizationTemplate = authorizationTemplate; 45 | } 46 | 47 | @GetMapping("/implicit") 48 | public void implicit(HttpServletResponse response) throws IOException { 49 | authorizationTemplate.redirectToUserAuthorize(response, OAuthProperties.ResponseTypes.TOKEN, SCOPES); 50 | } 51 | 52 | @PostMapping(value = "/token", produces = {"application/json"}) 53 | public Object token(@RequestBody TokenResponse tokenResponse) { 54 | String token = tokenResponse.getAccess_token(); 55 | ClientRestTemplate restTemplate = new ClientRestTemplate(token); 56 | return restTemplate.getForObject("http://resource.authmore/inbox", String.class); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /authmore-platform/src/main/java/me/zbl/authmore/platform/oauth/TokenPasswordTokenIssuer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.platform.oauth; 17 | 18 | import me.zbl.authmore.ClientDetails; 19 | import me.zbl.authmore.UserDetails; 20 | import me.zbl.authmore.oauth.*; 21 | import me.zbl.authmore.platform.authorization.UserDetailsRepository; 22 | import org.springframework.security.crypto.password.PasswordEncoder; 23 | import org.springframework.stereotype.Component; 24 | 25 | import java.util.Set; 26 | 27 | /** 28 | * @author ZHENG BAO LE 29 | * @since 2019-03-03 30 | */ 31 | @Component 32 | public final class TokenPasswordTokenIssuer { 33 | 34 | private final UserDetailsRepository users; 35 | private final PasswordEncoder passwordEncoder; 36 | private final TokenManager tokenManager; 37 | 38 | public TokenPasswordTokenIssuer( 39 | UserDetailsRepository users, 40 | PasswordEncoder passwordEncoder, 41 | TokenManager tokenManager) { 42 | this.users = users; 43 | this.passwordEncoder = passwordEncoder; 44 | this.tokenManager = tokenManager; 45 | } 46 | 47 | public TokenResponse issue(ClientDetails client, String username, String password, String scope) { 48 | OAuthUtil.validateClientAndGrantType(client, OAuthProperties.GrantTypes.PASSWORD); 49 | UserDetails user = users.findByUsername(username) 50 | .orElseThrow(() -> new OAuthException("invalid username")); 51 | boolean matches = passwordEncoder.matches(password, user.getPassword()); 52 | if (!matches) 53 | throw new OAuthException("invalid password"); 54 | OAuthUtil.validateClientAndScope(client, scope); 55 | String userId = user.getId(); 56 | Set scopes = OAuthUtil.scopeSet(scope); 57 | return tokenManager.create(client, userId, scopes); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS="-Xmx64m" 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /authmore-platform/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /authmore-admin/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS="-Xmx64m" 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /authmore-client-sample/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /authmore-resource-sample/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/client/ClientRestTemplate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.client; 17 | 18 | import me.zbl.authmore.common.Assert; 19 | import org.springframework.http.HttpHeaders; 20 | import org.springframework.http.HttpRequest; 21 | import org.springframework.http.client.ClientHttpRequestExecution; 22 | import org.springframework.http.client.ClientHttpRequestInterceptor; 23 | import org.springframework.http.client.ClientHttpResponse; 24 | import org.springframework.web.client.RestTemplate; 25 | 26 | import java.io.IOException; 27 | import java.util.stream.Collectors; 28 | import java.util.stream.Stream; 29 | 30 | /** 31 | * @author ZHENG BAO LE 32 | * @since 2019-03-01 33 | */ 34 | public class ClientRestTemplate extends RestTemplate { 35 | 36 | public ClientRestTemplate() {} 37 | 38 | public ClientRestTemplate(String token) { 39 | Assert.notEmpty(token, "empty token"); 40 | addTokenInterceptor(token); 41 | } 42 | 43 | private void addTokenInterceptor(String token) { 44 | TokenInterceptor tokenInterceptor = new TokenInterceptor(token); 45 | setInterceptors(Stream.of(tokenInterceptor).collect(Collectors.toList())); 46 | } 47 | 48 | private class TokenInterceptor implements ClientHttpRequestInterceptor { 49 | 50 | private final String token; 51 | 52 | private TokenInterceptor(String token) { 53 | this.token = token; 54 | } 55 | 56 | @Override 57 | public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) 58 | throws IOException { 59 | Assert.notEmpty(token, "token cannot be empty"); 60 | HttpHeaders headers = request.getHeaders(); 61 | headers.add(HttpHeaders.AUTHORIZATION, "Bearer " + token); 62 | return execution.execute(request, body); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/oauth/AccessTokenBinding.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.oauth; 17 | 18 | import org.springframework.data.annotation.Id; 19 | import org.springframework.data.redis.core.RedisHash; 20 | 21 | import java.io.Serializable; 22 | import java.util.Set; 23 | 24 | /** 25 | * @author ZHENG BAO LE 26 | * @since 2019-02-21 27 | */ 28 | @RedisHash(value = OAuthProperties.KEY_PREFIX_ACCESS_TOKEN_BINDING, 29 | timeToLive = OAuthProperties.DEFAULT_ACCESS_TOKEN_VALIDITY_SECONDS) 30 | public final class AccessTokenBinding implements Serializable { 31 | 32 | @Id 33 | private String accessToken; 34 | private String clientId; 35 | private Set scopes; 36 | private String userId; 37 | private Long expire; 38 | 39 | public AccessTokenBinding() {} 40 | 41 | public AccessTokenBinding(String accessToken, String clientId, Set scopes, String userId) { 42 | this.accessToken = accessToken; 43 | this.clientId = clientId; 44 | this.scopes = scopes; 45 | this.userId = userId; 46 | } 47 | 48 | public AccessTokenBinding(RefreshTokenBinding refreshTokenBinding, String accessToken) { 49 | this.accessToken = accessToken; 50 | this.clientId = refreshTokenBinding.getClientId(); 51 | this.scopes = refreshTokenBinding.getScopes(); 52 | this.userId = refreshTokenBinding.getUserId(); 53 | } 54 | 55 | public String getAccessToken() { 56 | return accessToken; 57 | } 58 | 59 | public String getClientId() { 60 | return clientId; 61 | } 62 | 63 | public Set getScopes() { 64 | return scopes; 65 | } 66 | 67 | public String getUserId() { 68 | return userId; 69 | } 70 | 71 | public Long getExpire() { 72 | return expire; 73 | } 74 | 75 | public void setExpire(Long expire) { 76 | this.expire = expire; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /authmore-platform/src/main/resources/public/app-icon.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/PasswordEncoderFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore; 17 | 18 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 19 | import org.springframework.security.crypto.password.DelegatingPasswordEncoder; 20 | import org.springframework.security.crypto.password.PasswordEncoder; 21 | import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder; 22 | import org.springframework.security.crypto.scrypt.SCryptPasswordEncoder; 23 | 24 | import java.util.HashMap; 25 | import java.util.Map; 26 | 27 | /** 28 | * @author ZHENG BAO LE 29 | * @since 2019-02-05 30 | */ 31 | public class PasswordEncoderFactory { 32 | 33 | @SuppressWarnings("deprecation") 34 | public static PasswordEncoder createDelegatingPasswordEncoder() { 35 | String encodingId = "pbkdf2"; 36 | Map encoders = new HashMap<>(); 37 | encoders.put(encodingId, new BCryptPasswordEncoder()); 38 | encoders.put("ldap", new org.springframework.security.crypto.password.LdapShaPasswordEncoder()); 39 | encoders.put("MD4", new org.springframework.security.crypto.password.Md4PasswordEncoder()); 40 | encoders.put("MD5", new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("MD5")); 41 | encoders.put("noop", org.springframework.security.crypto.password.NoOpPasswordEncoder.getInstance()); 42 | encoders.put("pbkdf2", new Pbkdf2PasswordEncoder()); 43 | encoders.put("scrypt", new SCryptPasswordEncoder()); 44 | encoders.put("SHA-1", new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("SHA-1")); 45 | encoders.put("SHA-256", new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("SHA-256")); 46 | encoders.put("sha256", new org.springframework.security.crypto.password.StandardPasswordEncoder()); 47 | 48 | return new DelegatingPasswordEncoder(encodingId, encoders); 49 | } 50 | 51 | private PasswordEncoderFactory() {} 52 | } 53 | -------------------------------------------------------------------------------- /authmore-core/src/main/java/me/zbl/authmore/client/AuthorizationTemplate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ZHENG BAO LE 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.zbl.authmore.client; 17 | 18 | import me.zbl.authmore.common.Assert; 19 | import me.zbl.authmore.oauth.OAuthProperties; 20 | import me.zbl.authmore.oauth.OAuthProperties.ResponseTypes; 21 | import me.zbl.authmore.oauth.RequestUtil; 22 | 23 | import javax.servlet.http.HttpServletResponse; 24 | import java.io.IOException; 25 | import java.util.HashMap; 26 | import java.util.Map; 27 | 28 | /** 29 | * @author ZHENG BAO LE 30 | * @since 2019-03-07 31 | */ 32 | public class AuthorizationTemplate implements AuthorizationOperations { 33 | 34 | private final String authorizeUrl; 35 | private final String clientId; 36 | private final String redirectUrl; 37 | private final String implicitRedirectUrl; 38 | 39 | public AuthorizationTemplate(ClientConfigurationProperties client) { 40 | this.authorizeUrl = client.getAuthorizeUri(); 41 | this.clientId = client.getClientId(); 42 | this.redirectUrl = client.getRedirectUri(); 43 | this.implicitRedirectUrl = client.getImplicitRedirectUri(); 44 | } 45 | 46 | @Override 47 | public void redirectToUserAuthorize(HttpServletResponse response, ResponseTypes type, String scope) 48 | throws IOException { 49 | String redirect; 50 | if (type == ResponseTypes.TOKEN) { 51 | redirect = implicitRedirectUrl; 52 | } else { 53 | redirect = redirectUrl; 54 | } 55 | Assert.notEmpty(authorizeUrl, "authorize url is required"); 56 | Assert.notEmpty(redirect, "redirect url is required"); 57 | Map params = new HashMap<>(); 58 | params.put(OAuthProperties.PARAM_RESPONSE_TYPE, type.getName()); 59 | params.put(OAuthProperties.PARAM_CLIENT_ID, clientId); 60 | params.put(OAuthProperties.PARAM_REDIRECT_URI, redirect); 61 | params.put(OAuthProperties.PARAM_SCOPE, scope); 62 | response.sendRedirect(authorizeUrl + "?" + RequestUtil.queryStringOf(params)); 63 | } 64 | } 65 | --------------------------------------------------------------------------------