├── .gitignore ├── LICENSE.txt ├── README.md ├── cola-auth ├── cola-auth-ac │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── honvay │ │ └── cola │ │ └── auth │ │ └── ac │ │ ├── AcAuthenticationConfiguration.java │ │ ├── AcAuthenticationFilter.java │ │ ├── AcAuthenticationToken.java │ │ ├── AcProperties.java │ │ ├── configrer │ │ ├── AcChannelSecurityConfigurer.java │ │ └── AcLoginConfigurer.java │ │ └── provider │ │ └── AcAuthenticationProvider.java ├── cola-auth-base │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── honvay │ │ └── cola │ │ └── auth │ │ └── base │ │ ├── component │ │ └── UserDetailsServiceImpl.java │ │ ├── configuration │ │ └── BaseSecurityConfiguration.java │ │ ├── controller │ │ └── AuthController.java │ │ ├── listener │ │ ├── AuthenticationFailureEventListener.java │ │ └── AuthenticationSuccessEventListener.java │ │ └── utils │ │ └── Utils.java ├── cola-auth-captcha │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── honvay │ │ └── cola │ │ └── auth │ │ └── captcha │ │ ├── controller │ │ └── CaptchaController.java │ │ └── filter │ │ └── CaptchaAuthenticationFilter.java ├── cola-auth-channel │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── honvay │ │ └── cola │ │ └── auth │ │ └── channel │ │ └── config │ │ ├── AbstractChannelSecurityConfigurer.java │ │ └── ChannelSecurityConfigurer.java ├── cola-auth-client │ ├── cola-auth-client-app │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── honvay │ │ │ └── cola │ │ │ └── auth │ │ │ └── common │ │ │ └── client │ │ │ └── app │ │ │ ├── SsoAuthClient.java │ │ │ ├── SsoClientAutoConfiguration.java │ │ │ └── SsoClientProperties.java │ ├── cola-auth-client-common │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── honvay │ │ │ └── cola │ │ │ └── auth │ │ │ └── client │ │ │ └── common │ │ │ ├── SsoUserExtractor.java │ │ │ └── oauth2 │ │ │ ├── ac │ │ │ ├── AcAccessTokenProvider.java │ │ │ └── AcResourceDetails.java │ │ │ ├── openid │ │ │ ├── OpenIdAccessTokenProvider.java │ │ │ └── OpenIdResourceDetails.java │ │ │ └── sms │ │ │ ├── SmsAccessTokenProvider.java │ │ │ └── SmsResourceDetails.java │ ├── cola-auth-client-web │ │ └── pom.xml │ └── pom.xml ├── cola-auth-core │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── honvay │ │ └── cola │ │ └── auth │ │ └── core │ │ └── model │ │ └── AuthenticatedUser.java ├── cola-auth-jwt │ ├── cola-auth-jwt-ac │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── honvay │ │ │ └── cola │ │ │ └── auth │ │ │ └── jwt │ │ │ └── ac │ │ │ └── AuthorizationCodeJwtConfiguration.java │ ├── cola-auth-jwt-base │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── honvay │ │ │ └── cola │ │ │ └── auth │ │ │ └── jwt │ │ │ ├── DefaultJwtTokenStore.java │ │ │ ├── JwtProperties.java │ │ │ ├── JwtTokenProvider.java │ │ │ ├── JwtTokenStore.java │ │ │ ├── config │ │ │ └── JwtSecurityConfiguration.java │ │ │ ├── filter │ │ │ └── JwtAuthenticationFilter.java │ │ │ ├── handler │ │ │ ├── JwtAuthenticationEntryPoint.java │ │ │ ├── JwtAuthenticationFailureHandler.java │ │ │ ├── JwtAuthenticationSuccessHandler.java │ │ │ └── JwtLogoutSuccessHandler.java │ │ │ └── listener │ │ │ └── JwtAuthenticationSuccessEventListener.java │ ├── cola-auth-jwt-openid │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── honvay │ │ │ └── cola │ │ │ └── auth │ │ │ └── jwt │ │ │ └── openid │ │ │ └── OpenIdJwtConfiguration.java │ ├── cola-auth-jwt-sms │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── honvay │ │ │ └── cola │ │ │ └── auth │ │ │ └── jwt │ │ │ └── sms │ │ │ └── SmsJwtConfiguration.java │ └── pom.xml ├── cola-auth-oauth2 │ ├── cola-auth-oauth2-ac │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── honvay │ │ │ └── cola │ │ │ └── auto │ │ │ └── oauth2 │ │ │ └── ac │ │ │ ├── config │ │ │ └── AcOAuth2Configuration.java │ │ │ └── granter │ │ │ └── AcTokenGranter.java │ ├── cola-auth-oauth2-base │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── honvay │ │ │ └── cola │ │ │ └── auth │ │ │ └── oauth2 │ │ │ ├── configuration │ │ │ ├── AuthorizationServerConfiguration.java │ │ │ └── ResourceServerConfiguration.java │ │ │ └── controller │ │ │ └── OAuth2Controller.java │ ├── cola-auth-oauth2-openid │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── honvay │ │ │ └── cola │ │ │ └── auth │ │ │ └── oauth2 │ │ │ └── openid │ │ │ ├── config │ │ │ └── OpenIdOAuth2Configuration.java │ │ │ └── granter │ │ │ └── OpenIdTokenGranter.java │ ├── cola-auth-oauth2-sms │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── honvay │ │ │ └── cola │ │ │ └── auth │ │ │ └── oauth2 │ │ │ └── sms │ │ │ ├── config │ │ │ └── SmsOAuth2Configuration.java │ │ │ └── granter │ │ │ └── SmsTokenGranter.java │ └── pom.xml ├── cola-auth-openid │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── honvay │ │ └── cola │ │ └── auth │ │ └── openid │ │ ├── OpenIdAuthenticationConfiguration.java │ │ ├── OpenIdAuthenticationFilter.java │ │ ├── OpenIdAuthenticationToken.java │ │ ├── OpenIdProperties.java │ │ ├── configrer │ │ ├── OpenIdChannelSecurityConfigurer.java │ │ └── OpenIdLoginConfigurer.java │ │ └── provider │ │ └── OpenIdAuthenticationProvider.java ├── cola-auth-sms │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── honvay │ │ └── cola │ │ └── auth │ │ └── web │ │ └── sms │ │ ├── SmsAuthenticationConfiguration.java │ │ ├── SmsCredentialController.java │ │ ├── SmsCredentialProperties.java │ │ ├── SmsUserDetailsService.java │ │ ├── authentication │ │ ├── SmsAuthenticationFilter.java │ │ ├── SmsAuthenticationProvider.java │ │ └── SmsAuthenticationToken.java │ │ ├── configurer │ │ ├── SmsChannelSecurityConfigurer.java │ │ └── SmsLoginConfigurer.java │ │ └── userdetails │ │ └── SmsUserDetailsServiceImpl.java ├── cola-auth-social │ ├── cola-auth-social-alipay │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── honvay │ │ │ └── cola │ │ │ └── auth │ │ │ └── social │ │ │ └── alipay │ │ │ ├── AlipayProperties.java │ │ │ ├── api │ │ │ ├── Alipay.java │ │ │ ├── AlipayUserInfo.java │ │ │ └── impl │ │ │ │ └── AlipayImpl.java │ │ │ ├── config │ │ │ └── AlipayConnectConfiguration.java │ │ │ └── connect │ │ │ ├── AlipayAdapater.java │ │ │ ├── AlipayConnectionFactory.java │ │ │ ├── AlipayOAuth2AuthenticationService.java │ │ │ ├── AlipayOAuth2Template.java │ │ │ └── AlipayServiceProvider.java │ ├── cola-auth-social-base │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── honvay │ │ │ └── cola │ │ │ └── auth │ │ │ └── social │ │ │ └── core │ │ │ ├── SocialAuthenticatedUser.java │ │ │ ├── SocialAutoConfiguration.java │ │ │ ├── SocialProperties.java │ │ │ ├── connection │ │ │ ├── JpaConnectionRepository.java │ │ │ └── JpaUsersConnectRepository.java │ │ │ ├── domain │ │ │ └── UserConnection.java │ │ │ ├── repository │ │ │ └── UserConnectionRepository.java │ │ │ └── userdetails │ │ │ └── SocialUserDetailsServiceImpl.java │ ├── cola-auth-social-qq │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── honvay │ │ │ └── cola │ │ │ └── auth │ │ │ └── social │ │ │ └── qq │ │ │ ├── QQProperties.java │ │ │ ├── api │ │ │ ├── QQ.java │ │ │ ├── QQUserInfo.java │ │ │ └── impl │ │ │ │ └── QQImpl.java │ │ │ ├── config │ │ │ └── QQConnectConfiguration.java │ │ │ └── connect │ │ │ ├── QQAdapter.java │ │ │ ├── QQConnectionFactory.java │ │ │ ├── QQOAuth2Template.java │ │ │ └── QQServiceProvider.java │ ├── cola-auth-social-web │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── honvay │ │ │ └── cola │ │ │ └── auth │ │ │ └── social │ │ │ ├── SocialChannelSecurityConfigurer.java │ │ │ ├── SocialConnectController.java │ │ │ ├── SocialConnectionSignUp.java │ │ │ ├── SocialSecurityConfigurer.java │ │ │ ├── SocialSignUpController.java │ │ │ ├── SocialUserInfo.java │ │ │ ├── SocialWebAutoConfiguration.java │ │ │ └── view │ │ │ ├── SocialConnectStatusController.java │ │ │ ├── SocialConnectStatusView.java │ │ │ └── SocialConnectView.java │ ├── cola-auth-social-wechat │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── honvay │ │ │ └── cola │ │ │ └── auth │ │ │ └── social │ │ │ └── wechat │ │ │ ├── WechatProperties.java │ │ │ ├── api │ │ │ ├── Wechat.java │ │ │ ├── WechatUserInfo.java │ │ │ └── impl │ │ │ │ └── WechatImpl.java │ │ │ ├── config │ │ │ └── WechatConnectionConfiguration.java │ │ │ └── connect │ │ │ ├── WechatAccessGrant.java │ │ │ ├── WechatAdapter.java │ │ │ ├── WechatConnectionFactory.java │ │ │ ├── WechatOAuth2Template.java │ │ │ └── WechatServiceProvider.java │ ├── cola-auth-social-wechatmp │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── honvay │ │ │ └── cola │ │ │ └── auth │ │ │ └── social │ │ │ └── wechatmp │ │ │ ├── WechatMpProperties.java │ │ │ ├── api │ │ │ ├── WechatMp.java │ │ │ ├── WechatMpUserInfo.java │ │ │ └── impl │ │ │ │ └── WechatMpImpl.java │ │ │ ├── config │ │ │ └── WechatMpConnectionConfiguration.java │ │ │ └── connect │ │ │ ├── WechatMpAccessGrant.java │ │ │ ├── WechatMpAdapter.java │ │ │ ├── WechatMpConnectionFactory.java │ │ │ ├── WechatMpOAuth2Template.java │ │ │ └── WechatMpServiceProvider.java │ └── pom.xml ├── cola-auth-web │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── honvay │ │ └── cola │ │ └── auth │ │ └── web │ │ ├── WebAuthenticationConstant.java │ │ ├── configuration │ │ ├── WebSecurityConfiguration.java │ │ └── WebSessionConfiguration.java │ │ ├── controller │ │ ├── LoginController.java │ │ ├── SessionController.java │ │ └── SessionInvalidController.java │ │ └── handler │ │ ├── WebAuthenticationFailureHandler.java │ │ └── WebAuthenticationSuccessHandler.java └── pom.xml ├── cola-framework ├── cola-framework-core │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── honvay │ │ └── cola │ │ └── framework │ │ └── core │ │ ├── ErrorConstants.java │ │ ├── ErrorMessage.java │ │ ├── ServiceAssert.java │ │ ├── exception │ │ └── ServiceException.java │ │ └── protocol │ │ └── Result.java ├── cola-framework-util │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── honvay │ │ └── cola │ │ └── framework │ │ └── util │ │ ├── ImageUtils.java │ │ ├── PatternUtils.java │ │ └── RandomUtils.java ├── cola-framework-web │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── honvay │ │ └── cola │ │ └── framework │ │ └── web │ │ └── GlobalControllerAdvise.java └── pom.xml ├── cola-notify ├── cola-notify-api │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── honvay │ │ └── cola │ │ └── nc │ │ └── api │ │ ├── NotificationService.java │ │ ├── exchanger │ │ └── NotificationExchanger.java │ │ └── model │ │ ├── EmailNotification.java │ │ └── Notification.java ├── cola-notify-email │ ├── cola-notify-email-api │ │ └── pom.xml │ ├── cola-notify-email-provider │ │ └── pom.xml │ └── pom.xml ├── cola-notify-provider │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── honvay │ │ └── cola │ │ └── nc │ │ └── provider │ │ ├── NotificationController.java │ │ ├── NotificationDispatcher.java │ │ ├── NotificationTask.java │ │ └── NotificationThreadFactory.java ├── cola-notify-sms │ ├── cola-notify-sms-aliyun │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── honvay │ │ │ └── cola │ │ │ └── notify │ │ │ └── sms │ │ │ └── aliyun │ │ │ ├── AliyunSmsSender.java │ │ │ └── config │ │ │ ├── AliyunSmsProperties.java │ │ │ └── AliyunSmsSenderConfiguration.java │ ├── cola-notify-sms-api │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── honvay │ │ │ └── cola │ │ │ └── notify │ │ │ └── sms │ │ │ └── api │ │ │ ├── SmsNotification.java │ │ │ └── sender │ │ │ ├── SmsParameter.java │ │ │ ├── SmsSendResult.java │ │ │ └── SmsSender.java │ ├── cola-notify-sms-provider │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── honvay │ │ │ └── cola │ │ │ └── nc │ │ │ └── sms │ │ │ ├── SmsNotificationAutoConfiguration.java │ │ │ └── exchanger │ │ │ └── SmsNotificationExchanger.java │ └── pom.xml ├── cola-notify-wechat │ └── pom.xml └── pom.xml ├── cola-samples ├── cola-sample-jwt │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── honvay │ │ │ └── cola │ │ │ └── sample │ │ │ └── jwt │ │ │ ├── JwtAuthController.java │ │ │ └── JwtSampleApplication.java │ │ └── resources │ │ └── application.yml ├── cola-sample-oauth2 │ └── pom.xml ├── cola-sample-sso │ ├── cola-sample-sso-app │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── honvay │ │ │ │ └── cola │ │ │ │ └── sso │ │ │ │ └── smaple │ │ │ │ └── app │ │ │ │ ├── AuthController.java │ │ │ │ ├── ResourceServerConfiguration.java │ │ │ │ └── SimpleAppApplication.java │ │ │ └── resources │ │ │ └── application.yml │ ├── cola-sample-sso-server │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── honvay │ │ │ │ └── cola │ │ │ │ └── sample │ │ │ │ └── sso │ │ │ │ ├── IndexController.java │ │ │ │ ├── SecurityConfiguration.java │ │ │ │ └── SsoServerSampleApplication.java │ │ │ └── resources │ │ │ ├── application.yml │ │ │ └── templates │ │ │ ├── connect │ │ │ ├── alipayConnect.html │ │ │ ├── alipayConnected.html │ │ │ ├── qqConnect.html │ │ │ ├── qqConnected.html │ │ │ ├── status.html │ │ │ ├── wechatConnect.html │ │ │ └── wechatConnected.html │ │ │ ├── error.html │ │ │ ├── form.html │ │ │ ├── index.html │ │ │ ├── login.html │ │ │ ├── loginBySms.html │ │ │ ├── social │ │ │ └── signup.html │ │ │ └── static │ │ │ └── css │ │ │ └── style.css │ ├── cola-sample-sso-web │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── honvay │ │ │ │ └── cola │ │ │ │ └── sso │ │ │ │ └── sample │ │ │ │ └── web │ │ │ │ ├── SsoWebSampleApplication.java │ │ │ │ └── WebSecurityConfiguration.java │ │ │ └── resources │ │ │ ├── application.yml │ │ │ └── templates │ │ │ └── index.html │ └── pom.xml ├── cola-sample-web │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── honvay │ │ │ └── cola │ │ │ └── sample │ │ │ └── web │ │ │ ├── SecurityConfiguration.java │ │ │ └── WebSampleApplication.java │ │ └── resources │ │ ├── application.yml │ │ └── templates │ │ ├── error.html │ │ ├── form.html │ │ ├── index.html │ │ ├── login.html │ │ ├── loginBySms.html │ │ └── static │ │ └── css │ │ └── style.css ├── cola-samples-social │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── honvay │ │ │ └── cola │ │ │ └── sample │ │ │ └── social │ │ │ ├── IndexController.java │ │ │ ├── SecurityConfiguration.java │ │ │ └── SocialSampleApplication.java │ │ └── resources │ │ ├── application.yml │ │ └── templates │ │ ├── connect │ │ ├── alipayConnect.html │ │ ├── alipayConnected.html │ │ ├── qqConnect.html │ │ ├── qqConnected.html │ │ ├── status.html │ │ ├── wechatConnect.html │ │ └── wechatConnected.html │ │ ├── error.html │ │ ├── form.html │ │ ├── index.html │ │ ├── login.html │ │ ├── loginBySms.html │ │ ├── social │ │ └── signup.html │ │ └── static │ │ └── css │ │ └── style.css └── pom.xml ├── cola-security ├── cola-security-api │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── honvay │ │ └── cola │ │ └── sc │ │ └── api │ │ ├── CredentialService.java │ │ ├── PasswordStrategy.java │ │ ├── enums │ │ └── SecurityErrorEnum.java │ │ ├── exception │ │ └── PasswordInvalidException.java │ │ └── model │ │ ├── CredentialConfig.java │ │ ├── CredentialNotify.java │ │ ├── CredentialType.java │ │ └── CredentialValidation.java ├── cola-security-provider │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── honvay │ │ │ │ └── cola │ │ │ │ └── sc │ │ │ │ └── provider │ │ │ │ ├── SecurityCenterAutoConfiguration.java │ │ │ │ ├── credential │ │ │ │ ├── CredentialProperties.java │ │ │ │ └── CredentialServiceImpl.java │ │ │ │ └── password │ │ │ │ ├── DefaultPasswordStrategy.java │ │ │ │ ├── InvalidPasswordException.java │ │ │ │ ├── PasswordProperties.java │ │ │ │ └── PasswordStrength.java │ │ └── resources │ │ │ └── messages-zh_CN.properties │ │ └── test │ │ └── java │ │ └── com │ │ └── honvay │ │ └── cola │ │ └── sc │ │ └── provider │ │ ├── CredentialServiceImplTest.java │ │ └── TestContext.java └── pom.xml ├── cola-user ├── cola-user-admin │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── honvay │ │ └── cola │ │ └── uc │ │ └── admin │ │ └── UserController.java ├── cola-user-api │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── honvay │ │ └── cola │ │ └── uc │ │ └── api │ │ ├── UserService.java │ │ ├── enums │ │ ├── UserErrorMessage.java │ │ └── UserStatus.java │ │ └── model │ │ ├── UpdatePasswordDto.java │ │ ├── UserAddDto.java │ │ ├── UserDto.java │ │ └── UserUpdateDto.java ├── cola-user-provider │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── honvay │ │ └── cola │ │ └── uc │ │ └── provider │ │ ├── domain │ │ └── User.java │ │ ├── event │ │ └── PasswordChangedEvent.java │ │ ├── impl │ │ └── UserServiceImpl.java │ │ └── repository │ │ └── UserRepository.java ├── cola-user-web │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── honvay │ │ │ └── cola │ │ │ └── uc │ │ │ └── web │ │ │ ├── controller │ │ │ ├── SignUpController.java │ │ │ └── UserController.java │ │ │ └── model │ │ │ ├── PhoneNumberBindDto.java │ │ │ ├── SmsSignUpDto.java │ │ │ └── UsernamePasswordSignUpDto.java │ │ └── test │ │ └── java │ │ └── com │ │ └── honvay │ │ └── cola │ │ └── uc │ │ └── web │ │ └── controller │ │ ├── UsernamePasswordSignUpDtoControllerTest.java │ │ └── WebConfiguration.java └── pom.xml ├── pom.xml └── sql └── cola.sql /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 leecho 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cola 2 | ## 简介 3 | Cola是一个互联网应用基础组件,基于SpringBoot2/SpringSecurity/SpringSession/SpringSocial/SpringSecurityOAuth2构建,着重于解决互联网应用分布式集群场景下的身份认证,并提供丰富的认证方式和社会化认证集成。也包含其他支撑系统,例如:用户中心、安全中心、通知中心。能够满足所有互联网应用的所有认证需求,并通过基础组件来支撑互联网应用快速开发。 4 | 5 | ## 组件列表 6 | | 组件代码 | 组件名称 | 说明 | 7 | | ------ | ------ | ------ | 8 | | cola-auth | 认证组件 | 提供认证服务 | 9 | | cola-user | 用户中心 | 提供用户服务 | 10 | | cola-security | 安全中心 | 提供凭证验证等安全服务 | 11 | | cola-notify | 通知中心 | 提供消息通知服务 | 12 | 13 | ## 认证模式 14 | - Web Session认证 15 | - Jwt Token认证 16 | - OAuth2 Token认证 17 | ## 登录方式 18 | - 账号密码登录 19 | - 短信验证码登录 20 | - 第三方集成登录(支付宝、微信、QQ) 21 | 22 | 通过Cola可快速的多种构建认证服务 23 | ## 认证服务 24 | - SSO 基于OAuth2构建SSO平台 25 | - Spring Cloud微服务集群认证服务 26 | - OpenAPI 基于OAuth2构建开放平台 27 | 28 | 通过对SpringSecurityOAuth2进行增强,支持短信验证码、第三方登录等授权模式 29 | ## OAuth2扩展授权模式 30 | - 通过短信验证码获取Token 31 | - 通过第三方OpenId获取Token 32 | - 通过第三方AuthorizationCode获取Token 33 | 34 | ## 实例项目 35 | | 项目 | 认证模式 | 适用场景 | 36 | | ------ | ------ | ------ | 37 | | cola-sample-jwt | JWT |APP/小程序 | 38 | | cola-sample-oauth2 | OAuth2 | APP/小程序/开放平台和微服务平台的认证服务 | 39 | | cola-sample-sso | Session&OAuth2 | Web应用/APP/小程序集成认证 | 40 | | cola-sample-web | Session | Web应用 | 41 | | cola-sample-social | Session | Web应用/SSO服务 | 42 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-ac/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-auth 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-auth-ac 13 | 14 | 15 | 16 | com.honvay 17 | cola-auth-social-base 18 | 19 | 20 | com.honvay 21 | cola-auth-core 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | provided 27 | 28 | 29 | com.honvay 30 | cola-auth-channel 31 | 32 | 33 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-ac/src/main/java/com/honvay/cola/auth/ac/AcProperties.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.ac; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | 6 | /** 7 | * @author LIQIU 8 | * created on 2018/12/27 9 | **/ 10 | @Data 11 | @ConfigurationProperties(prefix = "security.ac") 12 | public class AcProperties { 13 | 14 | private String loginSuccessUrl = "/"; 15 | 16 | private String loginProcessUrl = "/loginByAuthorizationCode"; 17 | 18 | private String loginFailureUrl = "/loginByAuthorizationCode?error"; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-ac/src/main/java/com/honvay/cola/auth/ac/configrer/AcChannelSecurityConfigurer.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.ac.configrer; 2 | 3 | import com.honvay.cola.auth.ac.AcProperties; 4 | import com.honvay.cola.auth.ac.provider.AcAuthenticationProvider; 5 | import com.honvay.cola.auth.channel.config.AbstractChannelSecurityConfigurer; 6 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 7 | import org.springframework.security.config.annotation.web.builders.WebSecurity; 8 | 9 | /** 10 | * @author LIQIU 11 | * created on 2018/12/23 12 | **/ 13 | public class AcChannelSecurityConfigurer extends AbstractChannelSecurityConfigurer { 14 | 15 | private AcAuthenticationProvider acAuthenticationProvider; 16 | private AcProperties acProperties; 17 | 18 | public AcChannelSecurityConfigurer(AcLoginConfigurer adapter, 19 | AcAuthenticationProvider acAuthenticationProvider, 20 | AcProperties acProperties) { 21 | super(adapter); 22 | this.acAuthenticationProvider = acAuthenticationProvider; 23 | this.acProperties = acProperties; 24 | } 25 | 26 | @Override 27 | public void config(HttpSecurity httpSecurity) throws Exception { 28 | httpSecurity.authenticationProvider(acAuthenticationProvider); 29 | httpSecurity.authorizeRequests().antMatchers(acProperties.getLoginProcessUrl()).permitAll(); 30 | } 31 | 32 | @Override 33 | public void configure(WebSecurity webSecurity) { 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-base/src/main/java/com/honvay/cola/auth/base/controller/AuthController.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.base.controller; 2 | 3 | import com.honvay.cola.auth.core.model.AuthenticatedUser; 4 | import com.honvay.cola.framework.core.protocol.Result; 5 | import org.springframework.security.core.annotation.AuthenticationPrincipal; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | /** 10 | * @author LIQIU 11 | * created on 2018/12/25 12 | **/ 13 | @RestController 14 | public class AuthController { 15 | 16 | @RequestMapping("/user/current") 17 | public Result current(@AuthenticationPrincipal AuthenticatedUser authenticatedUser) { 18 | return Result.success(authenticatedUser); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-base/src/main/java/com/honvay/cola/auth/base/listener/AuthenticationFailureEventListener.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.base.listener; 2 | 3 | import com.honvay.cola.uc.api.UserService; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.context.ApplicationListener; 7 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 8 | import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent; 9 | import org.springframework.stereotype.Component; 10 | 11 | /** 12 | * 认证失败逻辑处理,页面登录和Token认证都会走这个逻辑 13 | * 14 | * @author LIQIU 15 | * created on 2018-11-19 16 | **/ 17 | @Component 18 | @Slf4j 19 | public class AuthenticationFailureEventListener implements ApplicationListener { 20 | 21 | @Autowired 22 | private UserService userService; 23 | 24 | @Override 25 | public void onApplicationEvent(AuthenticationFailureBadCredentialsEvent authenticationFailureBadCredentialsEvent) { 26 | //只有账号密码登录才回更新登录失败次数 27 | if (authenticationFailureBadCredentialsEvent.getAuthentication().getClass().equals(UsernamePasswordAuthenticationToken.class)) { 28 | userService.processLoginFail(authenticationFailureBadCredentialsEvent.getAuthentication().getName()); 29 | log.info("Authentication failure: " + authenticationFailureBadCredentialsEvent.getAuthentication().getName()); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-base/src/main/java/com/honvay/cola/auth/base/listener/AuthenticationSuccessEventListener.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.base.listener; 2 | 3 | import com.honvay.cola.uc.api.UserService; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.context.ApplicationListener; 7 | import org.springframework.security.authentication.event.AuthenticationSuccessEvent; 8 | import org.springframework.security.core.Authentication; 9 | import org.springframework.stereotype.Component; 10 | 11 | /** 12 | * @author LIQIU 13 | * created on 2018-11-19 14 | **/ 15 | @Component 16 | @Slf4j 17 | public class AuthenticationSuccessEventListener implements ApplicationListener { 18 | 19 | @Autowired 20 | private UserService userService; 21 | 22 | @Override 23 | public void onApplicationEvent(AuthenticationSuccessEvent event) { 24 | if (event.getClass().equals(AuthenticationSuccessEvent.class)) { 25 | Authentication authentication = event.getAuthentication(); 26 | this.userService.processLoginSuccess(authentication.getName(), null, null); 27 | log.info("Authentication success:" + authentication.getName() + " ," + AuthenticationSuccessEvent.class); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-captcha/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-auth 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-auth-captcha 13 | 14 | 15 | 16 | com.honvay 17 | cola-framework-util 18 | 19 | 20 | org.springframework.boot 21 | spring-boot-starter-security 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | 27 | 28 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-captcha/src/main/java/com/honvay/cola/auth/captcha/controller/CaptchaController.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.captcha.controller; 2 | 3 | import com.honvay.cola.auth.captcha.filter.CaptchaAuthenticationFilter; 4 | import com.honvay.cola.framework.util.ImageUtils; 5 | import com.honvay.cola.framework.util.RandomUtils; 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | import java.io.IOException; 12 | 13 | /** 14 | * @author LIQIU 15 | * created on 2018/12/26 16 | **/ 17 | @Controller 18 | public class CaptchaController { 19 | 20 | @RequestMapping("/captcha") 21 | public void captcha(HttpServletRequest request, HttpServletResponse response) throws IOException { 22 | String code = RandomUtils.generateString(4); 23 | request.getSession().setAttribute(CaptchaAuthenticationFilter.LOGIN_CAPTCHA_SESSION_KEY, code); 24 | ImageUtils.outputImage(200, 60, response.getOutputStream(), code); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-channel/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-auth 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-auth-channel 13 | 14 | 15 | 16 | org.springframework.security 17 | spring-security-config 18 | 19 | 20 | org.springframework.security 21 | spring-security-web 22 | 23 | 24 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-channel/src/main/java/com/honvay/cola/auth/channel/config/AbstractChannelSecurityConfigurer.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.channel.config; 2 | 3 | import org.springframework.security.config.annotation.SecurityConfigurerAdapter; 4 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 5 | import org.springframework.security.web.DefaultSecurityFilterChain; 6 | 7 | /** 8 | * @author LIQIU 9 | * created on 2018/12/23 10 | **/ 11 | public abstract class AbstractChannelSecurityConfigurer implements ChannelSecurityConfigurer { 12 | 13 | private SecurityConfigurerAdapter adapter; 14 | 15 | protected AbstractChannelSecurityConfigurer(SecurityConfigurerAdapter adapter) { 16 | this.adapter = adapter; 17 | } 18 | 19 | @Override 20 | public void configure(HttpSecurity http) throws Exception { 21 | if (adapter != null) { 22 | http.apply(adapter); 23 | } 24 | config(http); 25 | } 26 | 27 | /** 28 | * 立即配置Security 29 | * 30 | * @param http 31 | * @throws Exception 32 | */ 33 | public abstract void config(HttpSecurity http) throws Exception; 34 | 35 | @Override 36 | public int getOrder() { 37 | return 100; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-channel/src/main/java/com/honvay/cola/auth/channel/config/ChannelSecurityConfigurer.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.channel.config; 2 | 3 | import org.springframework.core.Ordered; 4 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 5 | import org.springframework.security.config.annotation.web.builders.WebSecurity; 6 | 7 | /** 8 | * @author LIQIU 9 | * created on 2018/12/23 10 | **/ 11 | public interface ChannelSecurityConfigurer extends Ordered { 12 | 13 | /** 14 | * 配置HttpSecurity,会立即配置 15 | * 16 | * @param httpSecurity 17 | * @throws Exception 18 | */ 19 | default void configure(HttpSecurity httpSecurity) throws Exception { 20 | 21 | } 22 | 23 | /** 24 | * 配置HttpSecurity,会立即配置 25 | * 26 | * @param webSecurity 27 | * @throws Exception 28 | */ 29 | default void configure(WebSecurity webSecurity) throws Exception { 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-client/cola-auth-client-app/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-auth-client 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-auth-client-app 13 | 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-starter-web 18 | 19 | 20 | com.honvay 21 | cola-auth-core 22 | 23 | 24 | com.honvay 25 | cola-auth-client-common 26 | 27 | 28 | com.honvay 29 | cola-framework-core 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-client/cola-auth-client-app/src/main/java/com/honvay/cola/auth/common/client/app/SsoClientAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.common.client.app; 2 | 3 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | /** 8 | * @author LIQIU 9 | * created on 2018-11-26 10 | **/ 11 | @Configuration 12 | @EnableConfigurationProperties(SsoClientProperties.class) 13 | public class SsoClientAutoConfiguration { 14 | 15 | @Bean 16 | public SsoAuthClient ssoAuthClient(SsoClientProperties properties) { 17 | return new SsoAuthClient(properties); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-client/cola-auth-client-app/src/main/java/com/honvay/cola/auth/common/client/app/SsoClientProperties.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.common.client.app; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | import org.springframework.security.oauth2.client.resource.BaseOAuth2ProtectedResourceDetails; 5 | 6 | /** 7 | * @author LIQIU 8 | * created on 2018-11-27 9 | **/ 10 | @ConfigurationProperties(prefix = "security.oauth2.client") 11 | public class SsoClientProperties extends BaseOAuth2ProtectedResourceDetails { 12 | 13 | /** 14 | * 删除token URL 15 | */ 16 | private String revokeTokenUri; 17 | 18 | public String getRevokeTokenUri() { 19 | return revokeTokenUri; 20 | } 21 | 22 | public void setRevokeTokenUri(String revokeTokenUri) { 23 | this.revokeTokenUri = revokeTokenUri; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-client/cola-auth-client-common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-auth-client 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-auth-client-common 13 | 14 | 15 | 16 | org.springframework.security.oauth.boot 17 | spring-security-oauth2-autoconfigure 18 | 19 | 20 | com.honvay 21 | cola-auth-core 22 | 23 | 24 | commons-beanutils 25 | commons-beanutils 26 | 1.9.3 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-client/cola-auth-client-common/src/main/java/com/honvay/cola/auth/client/common/SsoUserExtractor.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.client.common; 2 | 3 | import com.honvay.cola.auth.core.model.AuthenticatedUser; 4 | import org.apache.commons.beanutils.BeanUtils; 5 | import org.springframework.boot.autoconfigure.security.oauth2.resource.FixedPrincipalExtractor; 6 | import org.springframework.boot.autoconfigure.security.oauth2.resource.PrincipalExtractor; 7 | import org.springframework.security.oauth2.common.exceptions.InvalidTokenException; 8 | import org.springframework.stereotype.Component; 9 | 10 | import java.util.Map; 11 | 12 | /** 13 | * @author LIQIU 14 | * created on 2018-11-26 15 | **/ 16 | @Component 17 | public class SsoUserExtractor implements PrincipalExtractor { 18 | 19 | private FixedPrincipalExtractor fixedPrincipalExtractor = new FixedPrincipalExtractor(); 20 | 21 | @Override 22 | public Object extractPrincipal(Map map) { 23 | Object authentication = map.get("userAuthentication"); 24 | if (authentication == null) { 25 | throw new InvalidTokenException("userAuthentication is empty"); 26 | } 27 | Object principal = ((Map) authentication).get("principal"); 28 | AuthenticatedUser user = new AuthenticatedUser(); 29 | if (principal == null) { 30 | throw new InvalidTokenException("principal is empty"); 31 | } 32 | try { 33 | BeanUtils.populate(user, (Map) principal); 34 | } catch (Exception e) { 35 | throw new InvalidTokenException("populate user error: " + e.getMessage()); 36 | } 37 | return user; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-client/cola-auth-client-common/src/main/java/com/honvay/cola/auth/client/common/oauth2/ac/AcResourceDetails.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.client.common.oauth2.ac; 2 | 3 | import org.springframework.security.oauth2.client.resource.BaseOAuth2ProtectedResourceDetails; 4 | 5 | /** 6 | * @author LIQIU 7 | * created on 2019/1/15 8 | **/ 9 | public class AcResourceDetails extends BaseOAuth2ProtectedResourceDetails { 10 | 11 | private String authorizationCode; 12 | 13 | private String provider; 14 | 15 | public String getAuthorizationCode() { 16 | return authorizationCode; 17 | } 18 | 19 | public void setAuthorizationCode(String authorizationCode) { 20 | this.authorizationCode = authorizationCode; 21 | } 22 | 23 | public String getProvider() { 24 | return provider; 25 | } 26 | 27 | public void setProvider(String provider) { 28 | this.provider = provider; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-client/cola-auth-client-common/src/main/java/com/honvay/cola/auth/client/common/oauth2/openid/OpenIdResourceDetails.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.client.common.oauth2.openid; 2 | 3 | import org.springframework.security.oauth2.client.resource.BaseOAuth2ProtectedResourceDetails; 4 | 5 | /** 6 | * @author LIQIU 7 | * created on 2018-11-27 8 | **/ 9 | public class OpenIdResourceDetails extends BaseOAuth2ProtectedResourceDetails { 10 | 11 | private String openId; 12 | 13 | private String provider; 14 | 15 | public String getOpenId() { 16 | return openId; 17 | } 18 | 19 | public void setOpenId(String openId) { 20 | this.openId = openId; 21 | } 22 | 23 | public String getProvider() { 24 | return provider; 25 | } 26 | 27 | public void setProvider(String provider) { 28 | this.provider = provider; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-client/cola-auth-client-common/src/main/java/com/honvay/cola/auth/client/common/oauth2/sms/SmsResourceDetails.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.client.common.oauth2.sms; 2 | 3 | import org.springframework.security.oauth2.client.resource.BaseOAuth2ProtectedResourceDetails; 4 | 5 | /** 6 | * @author LIQIU 7 | * created on 2018-11-27 8 | **/ 9 | public class SmsResourceDetails extends BaseOAuth2ProtectedResourceDetails { 10 | 11 | private String phoneNumber; 12 | 13 | private String credential; 14 | 15 | public String getPhoneNumber() { 16 | return phoneNumber; 17 | } 18 | 19 | public void setPhoneNumber(String phoneNumber) { 20 | this.phoneNumber = phoneNumber; 21 | } 22 | 23 | public String getCredential() { 24 | return credential; 25 | } 26 | 27 | public void setCredential(String credential) { 28 | this.credential = credential; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-client/cola-auth-client-web/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-auth-client 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-auth-client-web 13 | 14 | 15 | 16 | org.springframework.security.oauth.boot 17 | spring-security-oauth2-autoconfigure 18 | 19 | 20 | org.springframework.boot 21 | spring-boot-starter-web 22 | 23 | 24 | com.honvay 25 | cola-auth-client-common 26 | 27 | 28 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-auth 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-auth-client 13 | pom 14 | 15 | cola-auth-client-app 16 | cola-auth-client-common 17 | cola-auth-client-web 18 | 19 | 20 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-core/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-auth 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-auth-core 13 | 14 | 15 | 16 | org.projectlombok 17 | lombok 18 | 19 | 20 | org.springframework.security 21 | spring-security-core 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-jwt/cola-auth-jwt-ac/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-auth-jwt 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-auth-jwt-ac 13 | 14 | 15 | 16 | com.honvay 17 | cola-auth-ac 18 | 19 | 20 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-jwt/cola-auth-jwt-ac/src/main/java/com/honvay/cola/auth/jwt/ac/AuthorizationCodeJwtConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.jwt.ac; 2 | 3 | import com.honvay.cola.auth.ac.configrer.AcLoginConfigurer; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.context.ApplicationEventPublisher; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 9 | import org.springframework.security.web.authentication.AuthenticationFailureHandler; 10 | import org.springframework.security.web.authentication.AuthenticationSuccessHandler; 11 | 12 | /** 13 | * @author LIQIU 14 | * created on 2018/12/29 15 | **/ 16 | @Configuration 17 | public class AuthorizationCodeJwtConfiguration { 18 | 19 | @Autowired 20 | private ApplicationEventPublisher applicationEventPublisher; 21 | 22 | @Bean 23 | public AcLoginConfigurer acLoginConfigurer(AuthenticationSuccessHandler successHandler, 24 | AuthenticationFailureHandler failureHandler) { 25 | AcLoginConfigurer configurer = new AcLoginConfigurer<>(); 26 | configurer.successHandler(successHandler) 27 | .failureHandler(failureHandler) 28 | .eventPublisher(applicationEventPublisher) 29 | .permitAll(); 30 | return configurer; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-jwt/cola-auth-jwt-base/src/main/java/com/honvay/cola/auth/jwt/DefaultJwtTokenStore.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.jwt; 2 | 3 | import org.springframework.security.core.Authentication; 4 | 5 | import java.util.HashMap; 6 | 7 | /** 8 | * @author LIQIU 9 | * created on 2018/12/26 10 | **/ 11 | public class DefaultJwtTokenStore implements JwtTokenStore { 12 | 13 | private HashMap repository = new HashMap<>(); 14 | 15 | @Override 16 | public void save(String token, Authentication authentication) { 17 | repository.put(token, authentication); 18 | } 19 | 20 | @Override 21 | public Authentication get(String token) { 22 | return repository.get(token); 23 | } 24 | 25 | @Override 26 | public void remove(String token) { 27 | repository.remove(token); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-jwt/cola-auth-jwt-base/src/main/java/com/honvay/cola/auth/jwt/JwtProperties.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.jwt; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | 6 | import java.time.Duration; 7 | 8 | /** 9 | * @author LIQIU 10 | * created on 2018/12/26 11 | **/ 12 | @Data 13 | @ConfigurationProperties(prefix = "security.jwt") 14 | public class JwtProperties { 15 | 16 | private String signingKey; 17 | 18 | private Duration expiration = Duration.ofHours(2); 19 | 20 | private Boolean autoRefresh = true; 21 | 22 | private Duration refreshPoint = Duration.ofMinutes(30); 23 | 24 | private String refreshTokenHeader = "refreshToken"; 25 | } 26 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-jwt/cola-auth-jwt-base/src/main/java/com/honvay/cola/auth/jwt/JwtTokenStore.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.jwt; 2 | 3 | import org.springframework.security.core.Authentication; 4 | 5 | /** 6 | * @author LIQIU 7 | * created on 2018/12/26 8 | **/ 9 | public interface JwtTokenStore { 10 | 11 | void save(String token, Authentication authentication); 12 | 13 | Authentication get(String token); 14 | 15 | void remove(String token); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-jwt/cola-auth-jwt-base/src/main/java/com/honvay/cola/auth/jwt/handler/JwtAuthenticationEntryPoint.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.jwt.handler; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import com.honvay.cola.framework.core.protocol.Result; 5 | import org.springframework.http.MediaType; 6 | import org.springframework.security.core.AuthenticationException; 7 | import org.springframework.security.web.AuthenticationEntryPoint; 8 | 9 | import javax.servlet.ServletException; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | import java.io.IOException; 13 | 14 | /** 15 | * @author LIQIU 16 | * created on 2018/12/26 17 | **/ 18 | public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint { 19 | 20 | @Override 21 | public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { 22 | ObjectMapper objectMapper = new ObjectMapper(); 23 | response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE); 24 | response.setStatus(HttpServletResponse.SC_BAD_REQUEST); 25 | objectMapper.writeValue(response.getOutputStream(), Result.fail(authException.getMessage())); 26 | response.getOutputStream().close(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-jwt/cola-auth-jwt-base/src/main/java/com/honvay/cola/auth/jwt/handler/JwtAuthenticationFailureHandler.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.jwt.handler; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import com.honvay.cola.framework.core.protocol.Result; 5 | import org.springframework.http.MediaType; 6 | import org.springframework.security.core.AuthenticationException; 7 | import org.springframework.security.web.authentication.AuthenticationFailureHandler; 8 | 9 | import javax.servlet.ServletException; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | import java.io.IOException; 13 | 14 | /** 15 | * @author LIQIU 16 | * created on 2018/12/26 17 | **/ 18 | public class JwtAuthenticationFailureHandler implements AuthenticationFailureHandler { 19 | @Override 20 | public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { 21 | 22 | exception.printStackTrace(); 23 | 24 | ObjectMapper objectMapper = new ObjectMapper(); 25 | response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE); 26 | response.setStatus(HttpServletResponse.SC_FORBIDDEN); 27 | objectMapper.writeValue(response.getOutputStream(), Result.fail(exception.getMessage())); 28 | response.getOutputStream().close(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-jwt/cola-auth-jwt-base/src/main/java/com/honvay/cola/auth/jwt/handler/JwtAuthenticationSuccessHandler.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.jwt.handler; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import com.honvay.cola.auth.jwt.JwtTokenProvider; 5 | import com.honvay.cola.framework.core.protocol.Result; 6 | import org.springframework.http.MediaType; 7 | import org.springframework.security.core.Authentication; 8 | import org.springframework.security.web.authentication.AuthenticationSuccessHandler; 9 | 10 | import javax.servlet.ServletException; 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | import java.io.IOException; 14 | 15 | /** 16 | * @author LIQIU 17 | * created on 2018/12/26 18 | **/ 19 | public class JwtAuthenticationSuccessHandler implements AuthenticationSuccessHandler { 20 | 21 | private JwtTokenProvider jwtTokenProvider; 22 | 23 | public JwtAuthenticationSuccessHandler(JwtTokenProvider jwtTokenProvider) { 24 | this.jwtTokenProvider = jwtTokenProvider; 25 | } 26 | 27 | @Override 28 | public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { 29 | String token = jwtTokenProvider.generate(authentication); 30 | ObjectMapper objectMapper = new ObjectMapper(); 31 | response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE); 32 | objectMapper.writeValue(response.getOutputStream(), Result.success("登录成功", token)); 33 | response.getOutputStream().close(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-jwt/cola-auth-jwt-base/src/main/java/com/honvay/cola/auth/jwt/handler/JwtLogoutSuccessHandler.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.jwt.handler; 2 | 3 | import org.springframework.security.core.Authentication; 4 | import org.springframework.security.web.authentication.logout.LogoutSuccessHandler; 5 | 6 | import javax.servlet.ServletException; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | import java.io.IOException; 10 | 11 | /** 12 | * @author LIQIU 13 | * created on 2018/12/26 14 | **/ 15 | public class JwtLogoutSuccessHandler implements LogoutSuccessHandler { 16 | @Override 17 | public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { 18 | //退出登录,删除缓存 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-jwt/cola-auth-jwt-base/src/main/java/com/honvay/cola/auth/jwt/listener/JwtAuthenticationSuccessEventListener.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.jwt.listener; 2 | 3 | import com.honvay.cola.auth.jwt.JwtTokenStore; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.context.ApplicationEvent; 7 | import org.springframework.context.ApplicationListener; 8 | import org.springframework.security.authentication.event.AuthenticationSuccessEvent; 9 | import org.springframework.security.authentication.event.InteractiveAuthenticationSuccessEvent; 10 | import org.springframework.security.core.Authentication; 11 | import org.springframework.security.web.authentication.WebAuthenticationDetails; 12 | import org.springframework.stereotype.Component; 13 | 14 | /** 15 | * @author LIQIU 16 | * created on 2018-11-19 17 | **/ 18 | @Slf4j 19 | @Component 20 | public class JwtAuthenticationSuccessEventListener implements ApplicationListener { 21 | 22 | @Autowired 23 | private JwtTokenStore jwtTokenStore; 24 | 25 | @Override 26 | public void onApplicationEvent(AuthenticationSuccessEvent event) { 27 | jwtTokenStore.save(event.getAuthentication().getName(), event.getAuthentication()); 28 | if (log.isDebugEnabled()) { 29 | log.debug("Jwt token: [{}] store success", event.getAuthentication().getName()); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-jwt/cola-auth-jwt-openid/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-auth-jwt 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-auth-jwt-openid 13 | 14 | 15 | 16 | com.honvay 17 | cola-auth-openid 18 | 19 | 20 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-jwt/cola-auth-jwt-openid/src/main/java/com/honvay/cola/auth/jwt/openid/OpenIdJwtConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.jwt.openid; 2 | 3 | import com.honvay.cola.auth.openid.configrer.OpenIdLoginConfigurer; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.context.ApplicationEventPublisher; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 9 | import org.springframework.security.web.authentication.AuthenticationFailureHandler; 10 | import org.springframework.security.web.authentication.AuthenticationSuccessHandler; 11 | 12 | /** 13 | * @author LIQIU 14 | * created on 2018/12/29 15 | **/ 16 | @Configuration 17 | public class OpenIdJwtConfiguration { 18 | 19 | @Autowired 20 | private ApplicationEventPublisher applicationEventPublisher; 21 | 22 | @Bean 23 | public OpenIdLoginConfigurer openIDLoginConfigurer(AuthenticationSuccessHandler successHandler, 24 | AuthenticationFailureHandler failureHandler) { 25 | OpenIdLoginConfigurer configurer = new OpenIdLoginConfigurer<>(); 26 | configurer.successHandler(successHandler) 27 | .failureHandler(failureHandler) 28 | .eventPublisher(applicationEventPublisher) 29 | .permitAll(); 30 | return configurer; 31 | } 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-jwt/cola-auth-jwt-sms/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-auth-jwt 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-auth-jwt-sms 13 | 14 | 15 | 16 | com.honvay 17 | cola-auth-sms 18 | 19 | 20 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-jwt/cola-auth-jwt-sms/src/main/java/com/honvay/cola/auth/jwt/sms/SmsJwtConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.jwt.sms; 2 | 3 | import com.honvay.cola.auth.web.sms.configurer.SmsLoginConfigurer; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.context.ApplicationEventPublisher; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 9 | import org.springframework.security.web.authentication.AuthenticationFailureHandler; 10 | import org.springframework.security.web.authentication.AuthenticationSuccessHandler; 11 | 12 | /** 13 | * @author LIQIU 14 | * created on 2018/12/29 15 | **/ 16 | @Configuration 17 | public class SmsJwtConfiguration { 18 | 19 | @Autowired 20 | private ApplicationEventPublisher applicationEventPublisher; 21 | 22 | @Bean 23 | public SmsLoginConfigurer smsLoginConfigurer(AuthenticationSuccessHandler successHandler, 24 | AuthenticationFailureHandler failureHandler) { 25 | SmsLoginConfigurer configurer = new SmsLoginConfigurer<>(); 26 | configurer.successHandler(successHandler) 27 | .failureHandler(failureHandler) 28 | .eventPublisher(applicationEventPublisher) 29 | .permitAll(); 30 | return configurer; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-jwt/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-auth 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-auth-jwt 13 | pom 14 | 15 | cola-auth-jwt-base 16 | cola-auth-jwt-sms 17 | cola-auth-jwt-ac 18 | cola-auth-jwt-openid 19 | 20 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-oauth2/cola-auth-oauth2-ac/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-auth-oauth2 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-auth-oauth2-ac 13 | 14 | 15 | 16 | com.honvay 17 | cola-auth-ac 18 | 19 | 20 | org.springframework.security.oauth.boot 21 | spring-security-oauth2-autoconfigure 22 | provided 23 | 24 | 25 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-oauth2/cola-auth-oauth2-ac/src/main/java/com/honvay/cola/auto/oauth2/ac/config/AcOAuth2Configuration.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auto.oauth2.ac.config; 2 | 3 | import com.honvay.cola.auto.oauth2.ac.granter.AcTokenGranter; 4 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.security.authentication.AuthenticationManager; 8 | import org.springframework.security.oauth2.provider.ClientDetailsService; 9 | import org.springframework.security.oauth2.provider.request.DefaultOAuth2RequestFactory; 10 | import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices; 11 | 12 | /** 13 | * @author LIQIU 14 | * created on 2018/12/29 15 | **/ 16 | @Configuration 17 | public class AcOAuth2Configuration { 18 | 19 | @Bean 20 | @ConditionalOnBean({AuthenticationManager.class, AuthorizationServerTokenServices.class, ClientDetailsService.class}) 21 | public AcTokenGranter acTokenGranter(AuthenticationManager authenticationManager, 22 | AuthorizationServerTokenServices tokenServices, 23 | ClientDetailsService clientDetailsService) { 24 | return new AcTokenGranter(authenticationManager, tokenServices, clientDetailsService, new DefaultOAuth2RequestFactory(clientDetailsService)); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-oauth2/cola-auth-oauth2-base/src/main/java/com/honvay/cola/auth/oauth2/configuration/ResourceServerConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.oauth2.configuration; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 5 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; 6 | import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; 7 | 8 | /** 9 | * @author LIQIU 10 | */ 11 | @Configuration 12 | @EnableResourceServer 13 | public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter { 14 | 15 | @Override 16 | public void configure(HttpSecurity http) throws Exception { 17 | http.oauth2ResourceServer().jwt(); 18 | http.requestMatchers().antMatchers("/api/**") 19 | .and() 20 | .authorizeRequests() 21 | .anyRequest().authenticated(); 22 | } 23 | } -------------------------------------------------------------------------------- /cola-auth/cola-auth-oauth2/cola-auth-oauth2-openid/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-auth-oauth2 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-auth-oauth2-openid 13 | 14 | 15 | 16 | com.honvay 17 | cola-auth-openid 18 | 19 | 20 | org.springframework.security.oauth.boot 21 | spring-security-oauth2-autoconfigure 22 | provided 23 | 24 | 25 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-oauth2/cola-auth-oauth2-openid/src/main/java/com/honvay/cola/auth/oauth2/openid/config/OpenIdOAuth2Configuration.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.oauth2.openid.config; 2 | 3 | import com.honvay.cola.auth.oauth2.openid.granter.OpenIdTokenGranter; 4 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.security.authentication.AuthenticationManager; 8 | import org.springframework.security.oauth2.provider.ClientDetailsService; 9 | import org.springframework.security.oauth2.provider.request.DefaultOAuth2RequestFactory; 10 | import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices; 11 | 12 | /** 13 | * @author LIQIU 14 | * created on 2018/12/29 15 | **/ 16 | @Configuration 17 | public class OpenIdOAuth2Configuration { 18 | 19 | @Bean 20 | @ConditionalOnBean({AuthenticationManager.class, AuthorizationServerTokenServices.class, ClientDetailsService.class}) 21 | public OpenIdTokenGranter openIdTokenGranter(AuthenticationManager authenticationManager, 22 | AuthorizationServerTokenServices tokenServices, 23 | ClientDetailsService clientDetailsService) { 24 | return new OpenIdTokenGranter(authenticationManager, tokenServices, clientDetailsService, new DefaultOAuth2RequestFactory(clientDetailsService)); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-oauth2/cola-auth-oauth2-sms/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-auth-oauth2 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-auth-oauth2-sms 13 | 14 | 15 | 16 | com.honvay 17 | cola-auth-sms 18 | 19 | 20 | org.springframework.security.oauth.boot 21 | spring-security-oauth2-autoconfigure 22 | provided 23 | 24 | 25 | org.springframework.security.oauth 26 | spring-security-oauth2 27 | 2.3.4.BUILD-SNAPSHOT 28 | compile 29 | 30 | 31 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-oauth2/cola-auth-oauth2-sms/src/main/java/com/honvay/cola/auth/oauth2/sms/config/SmsOAuth2Configuration.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.oauth2.sms.config; 2 | 3 | import com.honvay.cola.auth.oauth2.sms.granter.SmsTokenGranter; 4 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.security.authentication.AuthenticationManager; 8 | import org.springframework.security.oauth2.provider.ClientDetailsService; 9 | import org.springframework.security.oauth2.provider.request.DefaultOAuth2RequestFactory; 10 | import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices; 11 | 12 | /** 13 | * @author LIQIU 14 | * created on 2018/12/29 15 | **/ 16 | @Configuration 17 | public class SmsOAuth2Configuration { 18 | 19 | 20 | @Bean 21 | @ConditionalOnBean({AuthenticationManager.class, AuthorizationServerTokenServices.class, ClientDetailsService.class}) 22 | public SmsTokenGranter smsTokenGranter(AuthenticationManager authenticationManager, 23 | AuthorizationServerTokenServices tokenServices, 24 | ClientDetailsService clientDetailsService) { 25 | return new SmsTokenGranter(authenticationManager, tokenServices, clientDetailsService, new DefaultOAuth2RequestFactory(clientDetailsService)); 26 | } 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-oauth2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-auth 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-auth-oauth2 13 | pom 14 | 15 | cola-auth-oauth2-base 16 | cola-auth-oauth2-openid 17 | cola-auth-oauth2-ac 18 | cola-auth-oauth2-sms 19 | 20 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-openid/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-auth 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-auth-openid 13 | 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-starter-web 18 | provided 19 | 20 | 21 | com.honvay 22 | cola-auth-core 23 | 24 | 25 | com.honvay 26 | cola-auth-channel 27 | 28 | 29 | org.springframework.social 30 | spring-social-security 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-openid/src/main/java/com/honvay/cola/auth/openid/OpenIdAuthenticationToken.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.openid; 2 | 3 | import org.springframework.security.authentication.AbstractAuthenticationToken; 4 | import org.springframework.security.core.GrantedAuthority; 5 | 6 | import java.util.Collection; 7 | 8 | /** 9 | * 短信登录验证信息封装类 10 | * 11 | * @author TiHom 12 | */ 13 | public class OpenIdAuthenticationToken extends AbstractAuthenticationToken { 14 | 15 | private final Object principal; 16 | 17 | private String provider; 18 | 19 | public OpenIdAuthenticationToken(Object principal, String provider) { 20 | super(null); 21 | this.principal = principal; 22 | this.provider = provider; 23 | this.setAuthenticated(false); 24 | } 25 | 26 | public OpenIdAuthenticationToken(Object principal, Collection authorities) { 27 | super(authorities); 28 | this.principal = principal; 29 | super.setAuthenticated(true); 30 | } 31 | 32 | 33 | @Override 34 | public Object getCredentials() { 35 | return provider; 36 | } 37 | 38 | @Override 39 | public Object getPrincipal() { 40 | return this.principal; 41 | } 42 | 43 | @Override 44 | public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException { 45 | if (isAuthenticated) { 46 | throw new IllegalArgumentException("Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead"); 47 | } else { 48 | super.setAuthenticated(false); 49 | } 50 | } 51 | 52 | @Override 53 | public void eraseCredentials() { 54 | this.provider = null; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-openid/src/main/java/com/honvay/cola/auth/openid/OpenIdProperties.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.openid; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | 6 | /** 7 | * @author LIQIU 8 | * created on 2018/12/27 9 | **/ 10 | @Data 11 | @ConfigurationProperties(prefix = "security.openid") 12 | public class OpenIdProperties { 13 | 14 | private String loginSuccessUrl = "/"; 15 | 16 | private String loginProcessUrl = "/loginByOpenId"; 17 | 18 | private String loginFailureUrl = "/loginByOpenId?error"; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-openid/src/main/java/com/honvay/cola/auth/openid/configrer/OpenIdChannelSecurityConfigurer.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.openid.configrer; 2 | 3 | import com.honvay.cola.auth.channel.config.AbstractChannelSecurityConfigurer; 4 | import com.honvay.cola.auth.openid.OpenIdProperties; 5 | import com.honvay.cola.auth.openid.provider.OpenIdAuthenticationProvider; 6 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 7 | import org.springframework.security.config.annotation.web.builders.WebSecurity; 8 | 9 | /** 10 | * @author LIQIU 11 | * created on 2018/12/23 12 | **/ 13 | public class OpenIdChannelSecurityConfigurer extends AbstractChannelSecurityConfigurer { 14 | 15 | private OpenIdAuthenticationProvider openIdAuthenticationProvider; 16 | private OpenIdProperties openIdProperties; 17 | 18 | public OpenIdChannelSecurityConfigurer(OpenIdLoginConfigurer adapter, 19 | OpenIdAuthenticationProvider openIdAuthenticationProvider, 20 | OpenIdProperties openIdProperties) { 21 | super(adapter); 22 | this.openIdAuthenticationProvider = openIdAuthenticationProvider; 23 | this.openIdProperties = openIdProperties; 24 | } 25 | 26 | @Override 27 | public void config(HttpSecurity httpSecurity) throws Exception { 28 | httpSecurity.authenticationProvider(openIdAuthenticationProvider); 29 | httpSecurity.authorizeRequests().antMatchers(openIdProperties.getLoginProcessUrl()).permitAll(); 30 | } 31 | 32 | @Override 33 | public void configure(WebSecurity webSecurity) { 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-sms/src/main/java/com/honvay/cola/auth/web/sms/SmsCredentialProperties.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.web.sms; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | 6 | import java.time.Duration; 7 | 8 | /** 9 | * @author LIQIU 10 | * created on 2018-11-22 11 | **/ 12 | @Data 13 | @ConfigurationProperties(prefix = "security.sms") 14 | public class SmsCredentialProperties { 15 | 16 | private String loginSuccessUrl = "/"; 17 | 18 | private String loginProcessUrl = "/loginBySms"; 19 | 20 | private String loginFailureUrl = "/loginBySms?error"; 21 | 22 | private String sendSmsUrl = "/sendSms"; 23 | 24 | private String smsTemlateCode; 25 | 26 | private String smsSignName; 27 | 28 | private Integer credentialLength = 6; 29 | 30 | private Duration timeout = Duration.ofMinutes(3); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-sms/src/main/java/com/honvay/cola/auth/web/sms/SmsUserDetailsService.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.web.sms; 2 | 3 | import org.springframework.security.core.userdetails.UserDetails; 4 | 5 | /** 6 | * @author LIQIU 7 | * created on 2018-11-21 8 | **/ 9 | public interface SmsUserDetailsService { 10 | 11 | /** 12 | * 通过手机号获取用户信息 13 | * @param phoneNumber 手机号码 14 | * @return 用户信息 15 | */ 16 | UserDetails loadByPhoneNumber(String phoneNumber); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-sms/src/main/java/com/honvay/cola/auth/web/sms/userdetails/SmsUserDetailsServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.web.sms.userdetails; 2 | 3 | import com.honvay.cola.auth.core.model.AuthenticatedUser; 4 | import com.honvay.cola.auth.web.sms.SmsUserDetailsService; 5 | import com.honvay.cola.uc.api.UserService; 6 | import com.honvay.cola.uc.api.enums.UserStatus; 7 | import com.honvay.cola.uc.api.model.UserDto; 8 | import org.springframework.security.core.userdetails.UserDetails; 9 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 10 | 11 | /** 12 | * @author LIQIU 13 | * created on 2018/12/24 14 | **/ 15 | public class SmsUserDetailsServiceImpl implements SmsUserDetailsService { 16 | 17 | private UserService userService; 18 | 19 | public SmsUserDetailsServiceImpl(UserService userService) { 20 | this.userService = userService; 21 | } 22 | 23 | @Override 24 | public UserDetails loadByPhoneNumber(String phoneNumber) { 25 | 26 | UserDto userDto = userService.findByPhoneNumber(phoneNumber); 27 | if (userDto == null) { 28 | throw new UsernameNotFoundException("User " + phoneNumber + " can not be found"); 29 | } 30 | 31 | return AuthenticatedUser.builder() 32 | .id(userDto.getId()) 33 | .username(userDto.getUsername()) 34 | .password(userDto.getPassword()) 35 | .phoneNumber(userDto.getPhoneNumber()) 36 | .email(userDto.getEmail()) 37 | .avatar(userDto.getAvatar()) 38 | .locked(UserStatus.LOCKED.getValue().equals(userDto.getStatus())) 39 | .enable(UserStatus.ACTIVE.getValue().equals(userDto.getStatus())) 40 | .build(); 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-alipay/src/main/java/com/honvay/cola/auth/social/alipay/AlipayProperties.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social.alipay; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | 6 | /** 7 | * @author LIQIU 8 | * created on 2018-11-26 9 | **/ 10 | @Data 11 | @ConfigurationProperties(prefix = "spring.social.alipay") 12 | public class AlipayProperties { 13 | 14 | private String appId; 15 | 16 | private String appSecret; 17 | 18 | private String providerId = "alipay"; 19 | 20 | private String signType = "RSA2"; 21 | 22 | private String scope = "auth_user"; 23 | 24 | private String publicKey; 25 | 26 | private String privateKey; 27 | 28 | private String charset = "GBK"; 29 | 30 | private String format = "json"; 31 | 32 | private String gatewayUrl = "https://openapi.alipaydev.com/gateway.do"; 33 | } 34 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-alipay/src/main/java/com/honvay/cola/auth/social/alipay/api/Alipay.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social.alipay.api; 2 | 3 | /** 4 | * @author LIQIU 5 | * created on 2018-11-26 6 | **/ 7 | public interface Alipay { 8 | 9 | AlipayUserInfo getUserInfo(); 10 | } 11 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-alipay/src/main/java/com/honvay/cola/auth/social/alipay/api/AlipayUserInfo.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social.alipay.api; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @author LIQIU 7 | * created on 2018-11-26 8 | **/ 9 | @Data 10 | public class AlipayUserInfo { 11 | 12 | private String userId; 13 | 14 | private String avatar; 15 | 16 | private String nickName; 17 | } 18 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-alipay/src/main/java/com/honvay/cola/auth/social/alipay/connect/AlipayAdapater.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social.alipay.connect; 2 | 3 | import com.honvay.cola.auth.social.alipay.api.Alipay; 4 | import com.honvay.cola.auth.social.alipay.api.AlipayUserInfo; 5 | import org.springframework.social.connect.ApiAdapter; 6 | import org.springframework.social.connect.ConnectionValues; 7 | import org.springframework.social.connect.UserProfile; 8 | 9 | /** 10 | * @author LIQIU 11 | * created on 2018-11-26 12 | **/ 13 | public class AlipayAdapater implements ApiAdapter { 14 | @Override 15 | public boolean test(Alipay api) { 16 | return true; 17 | } 18 | 19 | @Override 20 | public void setConnectionValues(Alipay api, ConnectionValues values) { 21 | AlipayUserInfo alipayUserInfo = api.getUserInfo(); 22 | values.setDisplayName(alipayUserInfo.getNickName()); 23 | values.setImageUrl(alipayUserInfo.getAvatar()); 24 | values.setProviderUserId(alipayUserInfo.getUserId()); 25 | } 26 | 27 | @Override 28 | public UserProfile fetchUserProfile(Alipay api) { 29 | return null; 30 | } 31 | 32 | @Override 33 | public void updateStatus(Alipay api, String message) { 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-alipay/src/main/java/com/honvay/cola/auth/social/alipay/connect/AlipayConnectionFactory.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social.alipay.connect; 2 | 3 | import com.honvay.cola.auth.social.alipay.AlipayProperties; 4 | import com.honvay.cola.auth.social.alipay.api.Alipay; 5 | import org.springframework.social.connect.support.OAuth2ConnectionFactory; 6 | 7 | /** 8 | * @author LIQIU 9 | */ 10 | public class AlipayConnectionFactory extends OAuth2ConnectionFactory { 11 | @Override 12 | public boolean supportsStateParameter() { 13 | return false; 14 | } 15 | 16 | public AlipayConnectionFactory(AlipayProperties properties) { 17 | super(properties.getProviderId(), new AlipayServiceProvider(properties), new AlipayAdapater()); 18 | } 19 | } -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-alipay/src/main/java/com/honvay/cola/auth/social/alipay/connect/AlipayServiceProvider.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social.alipay.connect; 2 | 3 | import com.honvay.cola.auth.social.alipay.AlipayProperties; 4 | import com.honvay.cola.auth.social.alipay.api.Alipay; 5 | import com.honvay.cola.auth.social.alipay.api.impl.AlipayImpl; 6 | import org.springframework.social.oauth2.AbstractOAuth2ServiceProvider; 7 | 8 | /** 9 | * @author LIQIU 10 | */ 11 | public class AlipayServiceProvider extends AbstractOAuth2ServiceProvider { 12 | 13 | /** 14 | * 获取code 15 | */ 16 | private static final String ALIPAY_URL_AUTHORIZE = "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm"; 17 | /** 18 | * 获取access_token 也就是令牌 19 | */ 20 | private static final String ALIPAY_URL_ACCESS_TOKEN = "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm"; 21 | 22 | private AlipayProperties properties; 23 | 24 | public AlipayServiceProvider(AlipayProperties properties) { 25 | super(new AlipayOAuth2Template(properties, ALIPAY_URL_AUTHORIZE, ALIPAY_URL_ACCESS_TOKEN)); 26 | this.properties = properties; 27 | } 28 | 29 | @Override 30 | public Alipay getApi(String accessToken) { 31 | 32 | return new AlipayImpl(accessToken, properties); 33 | } 34 | } -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-base/src/main/java/com/honvay/cola/auth/social/core/SocialAuthenticatedUser.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social.core; 2 | 3 | import com.honvay.cola.auth.core.model.AuthenticatedUser; 4 | import org.springframework.social.security.SocialUserDetails; 5 | 6 | /** 7 | * @author LIQIU 8 | * created on 2018/12/25 9 | **/ 10 | public class SocialAuthenticatedUser extends AuthenticatedUser implements SocialUserDetails { 11 | @Override 12 | public String getUserId() { 13 | return this.getUsername(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-base/src/main/java/com/honvay/cola/auth/social/core/SocialProperties.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social.core; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | 6 | /** 7 | * @author LIQIU 8 | * created on 2018-11-14 9 | **/ 10 | @Data 11 | @ConfigurationProperties(prefix = "spring.social") 12 | public class SocialProperties { 13 | 14 | private String loginProcessUrl = "/social"; 15 | 16 | private String signupUrl = "/social/signup"; 17 | 18 | private String signupProcessUrl = "/social/signup"; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-base/src/main/java/com/honvay/cola/auth/social/core/domain/UserConnection.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social.core.domain; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import javax.persistence.*; 9 | 10 | /** 11 | * @author LIQIU 12 | */ 13 | @Data 14 | @Builder 15 | @AllArgsConstructor 16 | @NoArgsConstructor 17 | @Entity 18 | @Table(name = "cola_user_connection", 19 | uniqueConstraints = { 20 | @UniqueConstraint(name = "uniq_user_connection", columnNames = {"userId", "providerId", "providerUserId"}) 21 | }) 22 | public class UserConnection { 23 | 24 | @Id 25 | @GeneratedValue(strategy = GenerationType.IDENTITY) 26 | private Integer id; 27 | 28 | @Column(nullable = false) 29 | private String userId; 30 | 31 | @Column(nullable = false) 32 | private String providerUserId; 33 | 34 | @Column(nullable = false) 35 | private String providerId; 36 | 37 | private String providerUserName; 38 | 39 | private String imageUrl; 40 | 41 | private String secret; 42 | 43 | private String accessToken; 44 | 45 | private String refreshToken; 46 | 47 | private Long expireTime; 48 | 49 | } 50 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-qq/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-auth-social 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-auth-social-qq 13 | 14 | 15 | 16 | org.springframework.social 17 | spring-social-autoconfigure 18 | ${spring.social.version} 19 | 20 | 21 | org.projectlombok 22 | lombok 23 | 24 | 25 | org.apache.commons 26 | commons-lang3 27 | 3.4 28 | 29 | 30 | com.fasterxml.jackson.core 31 | jackson-databind 32 | 33 | 34 | org.slf4j 35 | slf4j-api 36 | 37 | 38 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-qq/src/main/java/com/honvay/cola/auth/social/qq/QQProperties.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social.qq; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | 6 | /** 7 | * @author LIQIU 8 | * created on 2018-11-13 9 | **/ 10 | @Data 11 | @ConfigurationProperties(prefix = "spring.social.qq") 12 | public class QQProperties { 13 | 14 | private String appId; 15 | 16 | private String appSecret; 17 | 18 | private String providerId = "qq"; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-qq/src/main/java/com/honvay/cola/auth/social/qq/api/QQ.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social.qq.api; 2 | 3 | /** 4 | * @author LIQIU 5 | */ 6 | public interface QQ { 7 | /** 8 | * 获取用户信息 9 | * @return 10 | */ 11 | QQUserInfo getUserInfo(); 12 | } -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-qq/src/main/java/com/honvay/cola/auth/social/qq/config/QQConnectConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social.qq.config; 2 | 3 | import com.honvay.cola.auth.social.qq.QQProperties; 4 | import com.honvay.cola.auth.social.qq.connect.QQConnectionFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.social.autoconfigure.SocialAutoConfigurerAdapter; 9 | import org.springframework.social.connect.ConnectionFactory; 10 | import org.springframework.social.connect.ConnectionFactoryLocator; 11 | import org.springframework.social.connect.UsersConnectionRepository; 12 | 13 | /** 14 | * @author LIQIU 15 | */ 16 | @Configuration 17 | @EnableConfigurationProperties(QQProperties.class) 18 | public class QQConnectConfiguration extends SocialAutoConfigurerAdapter { 19 | 20 | @Autowired 21 | private QQProperties qqProperties; 22 | 23 | @Override 24 | protected ConnectionFactory createConnectionFactory() { 25 | return new QQConnectionFactory(qqProperties.getProviderId(), qqProperties.getAppId(), qqProperties.getAppSecret()); 26 | } 27 | 28 | @Override 29 | public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator connectionFactoryLocator) { 30 | return null; 31 | } 32 | } -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-qq/src/main/java/com/honvay/cola/auth/social/qq/connect/QQAdapter.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social.qq.connect; 2 | 3 | import com.honvay.cola.auth.social.qq.api.QQ; 4 | import com.honvay.cola.auth.social.qq.api.QQUserInfo; 5 | import org.springframework.social.connect.ApiAdapter; 6 | import org.springframework.social.connect.ConnectionValues; 7 | import org.springframework.social.connect.UserProfile; 8 | 9 | /** 10 | * @author LIQIU 11 | */ 12 | public class QQAdapter implements ApiAdapter { 13 | @Override 14 | public boolean test(QQ api) { 15 | return true; 16 | } 17 | 18 | @Override 19 | public void setConnectionValues(QQ api, ConnectionValues values) { 20 | QQUserInfo userInfo = api.getUserInfo(); 21 | 22 | //openid 唯一标识 23 | values.setProviderUserId(userInfo.getOpenId()); 24 | values.setDisplayName(userInfo.getNickname()); 25 | values.setImageUrl(userInfo.getFigureurl_2()); 26 | values.setProfileUrl(null); 27 | } 28 | 29 | @Override 30 | public UserProfile fetchUserProfile(QQ api) { 31 | return null; 32 | } 33 | 34 | @Override 35 | public void updateStatus(QQ api, String message) { 36 | 37 | } 38 | } -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-qq/src/main/java/com/honvay/cola/auth/social/qq/connect/QQConnectionFactory.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social.qq.connect; 2 | 3 | import com.honvay.cola.auth.social.qq.api.QQ; 4 | import org.springframework.social.connect.support.OAuth2ConnectionFactory; 5 | 6 | /** 7 | * @author LIQIU 8 | */ 9 | public class QQConnectionFactory extends OAuth2ConnectionFactory { 10 | @Override 11 | public boolean supportsStateParameter() { 12 | return false; 13 | } 14 | 15 | public QQConnectionFactory(String providerId, String appId, String appSecret) { 16 | super(providerId, new QQServiceProvider(appId, appSecret), new QQAdapter()); 17 | } 18 | } -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-qq/src/main/java/com/honvay/cola/auth/social/qq/connect/QQServiceProvider.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social.qq.connect; 2 | 3 | import com.honvay.cola.auth.social.qq.api.QQ; 4 | import com.honvay.cola.auth.social.qq.api.impl.QQImpl; 5 | import org.springframework.social.oauth2.AbstractOAuth2ServiceProvider; 6 | 7 | /** 8 | * @author LIQIU 9 | */ 10 | public class QQServiceProvider extends AbstractOAuth2ServiceProvider { 11 | 12 | /** 13 | * 获取code 14 | */ 15 | private static final String QQ_URL_AUTHORIZE = "https://graph.qq.com/oauth2.0/authorize"; 16 | /** 17 | * 获取access_token 也就是令牌 18 | */ 19 | private static final String QQ_URL_ACCESS_TOKEN = "https://graph.qq.com/oauth2.0/token"; 20 | private String appId; 21 | 22 | public QQServiceProvider(String appId, String appSecret) { 23 | super(new QQOAuth2Template(appId, appSecret, QQ_URL_AUTHORIZE, QQ_URL_ACCESS_TOKEN)); 24 | this.appId = appId; 25 | } 26 | 27 | @Override 28 | public QQ getApi(String accessToken) { 29 | 30 | return new QQImpl(accessToken, appId); 31 | } 32 | } -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-web/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.honvay 7 | cola-auth-social 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-auth-social-web 13 | 14 | 15 | 16 | org.projectlombok 17 | lombok 18 | 19 | 20 | ${project.groupId} 21 | cola-auth-social-base 22 | 23 | 24 | com.honvay 25 | cola-auth-channel 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-security 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-web 34 | 35 | 36 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-web/src/main/java/com/honvay/cola/auth/social/SocialChannelSecurityConfigurer.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social; 2 | 3 | import com.honvay.cola.auth.channel.config.AbstractChannelSecurityConfigurer; 4 | import com.honvay.cola.auth.social.core.SocialProperties; 5 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 6 | import org.springframework.security.config.annotation.web.builders.WebSecurity; 7 | import org.springframework.social.security.SpringSocialConfigurer; 8 | 9 | /** 10 | * @author LIQIU 11 | * created on 2018/12/23 12 | **/ 13 | public class SocialChannelSecurityConfigurer extends AbstractChannelSecurityConfigurer { 14 | 15 | private SocialProperties socialProperties; 16 | 17 | 18 | public SocialChannelSecurityConfigurer(SocialProperties socialProperties, SpringSocialConfigurer springSocialConfigurer) { 19 | super(springSocialConfigurer); 20 | this.socialProperties = socialProperties; 21 | } 22 | 23 | @Override 24 | public void config(HttpSecurity httpSecurity) throws Exception { 25 | httpSecurity.authorizeRequests().antMatchers(socialProperties.getSignupProcessUrl()).permitAll(); 26 | } 27 | 28 | @Override 29 | public void configure(WebSecurity webSecurity) { 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-web/src/main/java/com/honvay/cola/auth/social/SocialConnectionSignUp.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social; 2 | 3 | import com.honvay.cola.uc.api.UserService; 4 | import com.honvay.cola.uc.api.enums.UserStatus; 5 | import com.honvay.cola.uc.api.model.UserAddDto; 6 | import com.honvay.cola.uc.api.model.UserDto; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.social.connect.Connection; 9 | import org.springframework.social.connect.ConnectionSignUp; 10 | 11 | /** 12 | * 自动转换用户ID,可以自动创建用户 13 | * 14 | * @author LIQIU 15 | */ 16 | 17 | /** 18 | * @Component 由用户主动绑定账号 19 | */ 20 | public class SocialConnectionSignUp implements ConnectionSignUp { 21 | 22 | @Autowired 23 | private UserService userService; 24 | 25 | @Override 26 | public String execute(Connection connection) { 27 | String username = "U" + System.currentTimeMillis(); 28 | UserAddDto user = UserAddDto.builder().username(username) 29 | .password("123") 30 | .name("EU" + System.currentTimeMillis()) 31 | .build(); 32 | userService.add(user); 33 | //根据社交用户信息,默认创建用户并返回用户唯一标识 34 | return username; 35 | } 36 | } -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-web/src/main/java/com/honvay/cola/auth/social/SocialSecurityConfigurer.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social; 2 | 3 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 4 | import org.springframework.social.security.SocialAuthenticationFilter; 5 | import org.springframework.social.security.SpringSocialConfigurer; 6 | 7 | /** 8 | * @author LIQIU 9 | * created on 2018-11-14 10 | **/ 11 | public class SocialSecurityConfigurer extends SpringSocialConfigurer{ 12 | 13 | private String filterProcessesUrl; 14 | 15 | public SocialSecurityConfigurer(String filterProcessesUrl) { 16 | this.filterProcessesUrl = filterProcessesUrl; 17 | } 18 | 19 | @Override 20 | public void configure(HttpSecurity http) throws Exception { 21 | String permitUrl = filterProcessesUrl; 22 | if (!permitUrl.endsWith("/")) { 23 | permitUrl += "/"; 24 | } 25 | permitUrl += "**"; 26 | http.authorizeRequests().antMatchers(permitUrl).permitAll(); 27 | super.configure(http); 28 | } 29 | 30 | @Override 31 | protected T postProcess(T object) { 32 | SocialAuthenticationFilter filter = (SocialAuthenticationFilter) super.postProcess(object); 33 | filter.setFilterProcessesUrl(filterProcessesUrl); 34 | return (T) filter; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-web/src/main/java/com/honvay/cola/auth/social/SocialUserInfo.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class SocialUserInfo { 7 | 8 | private String providerId; 9 | 10 | private String providerUserId; 11 | 12 | private String nickname; 13 | 14 | private String headImg; 15 | 16 | } -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-web/src/main/java/com/honvay/cola/auth/social/view/SocialConnectStatusController.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social.view; 2 | 3 | import com.honvay.cola.framework.core.protocol.Result; 4 | import org.springframework.http.MediaType; 5 | import org.springframework.http.ResponseEntity; 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | 9 | /** 10 | * @author LIQIU 11 | * created on 2018-11-24 12 | **/ 13 | @Controller 14 | @RequestMapping("/connect/status") 15 | public class SocialConnectStatusController { 16 | 17 | @RequestMapping(produces = MediaType.TEXT_HTML_VALUE) 18 | public String showStatusPage() { 19 | return "/connect/status"; 20 | } 21 | 22 | @RequestMapping 23 | public ResponseEntity showStatus() { 24 | return ResponseEntity.ok(Result.success()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-web/src/main/java/com/honvay/cola/auth/social/view/SocialConnectStatusView.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social.view; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import org.apache.commons.collections4.CollectionUtils; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.social.connect.Connection; 7 | import org.springframework.web.servlet.view.AbstractView; 8 | 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | import java.util.HashMap; 12 | import java.util.List; 13 | import java.util.Map; 14 | 15 | /** 16 | * @author LIQIU 17 | */ 18 | public class SocialConnectStatusView extends AbstractView { 19 | 20 | @Autowired 21 | private ObjectMapper objectMapper; 22 | 23 | @Override 24 | protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { 25 | Map>> connections = (Map>>) model.get("connectionMap"); 26 | 27 | Map result = new HashMap<>(); 28 | for (String key : connections.keySet()) { 29 | result.put(key, CollectionUtils.isNotEmpty(connections.get(key))); 30 | } 31 | 32 | response.setContentType("application/json;charset=UTF-8"); 33 | result.put("success", true); 34 | response.getWriter().write(objectMapper.writeValueAsString(result)); 35 | } 36 | } -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-web/src/main/java/com/honvay/cola/auth/social/view/SocialConnectView.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social.view; 2 | 3 | import org.springframework.web.servlet.view.AbstractView; 4 | 5 | import javax.servlet.http.HttpServletRequest; 6 | import javax.servlet.http.HttpServletResponse; 7 | import java.util.Map; 8 | 9 | /** 10 | * @author LIQIU 11 | */ 12 | public class SocialConnectView extends AbstractView { 13 | @Override 14 | protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { 15 | String msg = ""; 16 | response.setContentType("text/html;charset=UTF-8"); 17 | if (model.get("connections") == null) { 18 | msg = "unBindingSuccess"; 19 | } else { 20 | msg = "bindingSuccess"; 21 | } 22 | 23 | response.sendRedirect("/message/" + msg); 24 | } 25 | } -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-wechat/src/main/java/com/honvay/cola/auth/social/wechat/WechatProperties.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social.wechat; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | 6 | /** 7 | * @author LIQIU 8 | * created on 2018-11-15 9 | **/ 10 | @Data 11 | @ConfigurationProperties("spring.social.wechat") 12 | public class WechatProperties { 13 | 14 | private String appId; 15 | 16 | private String appSecret; 17 | 18 | private String providerId = "wechat"; 19 | 20 | private String scope = "snsapi_login"; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-wechat/src/main/java/com/honvay/cola/auth/social/wechat/api/Wechat.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social.wechat.api; 2 | 3 | /** 4 | * https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419316518&token=2d3bbb7b39c63ab8196e7aad045811f2d47e8602&lang=zh_CN 5 | * https://api.weixin.qq.com/sns/userinfo?access_token=ACCESS_TOKEN&openid=OPENID 6 | * 微信API调用接口 7 | * Created on 2018/1/11. 8 | * 9 | * @author LIQIU 10 | * @since 1.0 11 | */ 12 | public interface Wechat { 13 | WechatUserInfo getUserInfo(String openId); 14 | } 15 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-wechat/src/main/java/com/honvay/cola/auth/social/wechat/api/WechatUserInfo.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social.wechat.api; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * 微信返回的用户信息 7 | * Created on 2018/1/11. 8 | * 9 | * @author LIQIU 10 | * @since 1.0 11 | */ 12 | @Data 13 | public class WechatUserInfo { 14 | /** 15 | * 普通用户的标识,对当前开发者帐号唯一 16 | */ 17 | private String openid; 18 | /** 19 | * 普通用户昵称 20 | */ 21 | private String nickname; 22 | /** 23 | * 语言 24 | */ 25 | private String language; 26 | /** 27 | * 普通用户性别,1为男性,2为女性 28 | */ 29 | private String sex; 30 | /** 31 | * 普通用户个人资料填写的省份 32 | */ 33 | private String province; 34 | /** 35 | * 普通用户个人资料填写的城市 36 | */ 37 | private String city; 38 | /** 39 | * 国家,如中国为CN 40 | */ 41 | private String country; 42 | /** 43 | * 用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空 44 | */ 45 | private String headimgurl; 46 | /** 47 | * 用户特权信息,json数组,如微信沃卡用户为(chinaunicom) 48 | */ 49 | private String[] privilege; 50 | /** 51 | * 用户统一标识。针对一个微信开放平台帐号下的应用,同一用户的unionid是唯一的。 52 | */ 53 | private String unionid; 54 | } 55 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-wechat/src/main/java/com/honvay/cola/auth/social/wechat/connect/WechatAccessGrant.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social.wechat.connect; 2 | 3 | import lombok.Data; 4 | import org.springframework.social.oauth2.AccessGrant; 5 | 6 | /** 7 | * 微信的access_token信息。与标准OAuth2协议不同,微信在获取access_token时会同时返回openId,并没有单独的通过accessToke换取openId的服务 8 | * 9 | * 所以在这里继承了标准AccessGrant,添加了openId字段,作为对微信access_token信息的封装。 10 | * Created on 2018/1/11. 11 | * 12 | * @author LIQIU 13 | * @since 1.0 14 | */ 15 | @Data 16 | public class WechatAccessGrant extends AccessGrant { 17 | 18 | private String openId; 19 | 20 | public WechatAccessGrant() { 21 | super(""); 22 | } 23 | 24 | public WechatAccessGrant(String accessToken, String scope, String refreshToken, Long expiresIn) { 25 | super(accessToken, scope, refreshToken, expiresIn); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-wechat/src/main/java/com/honvay/cola/auth/social/wechat/connect/WechatAdapter.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social.wechat.connect; 2 | 3 | import com.honvay.cola.auth.social.wechat.api.Wechat; 4 | import com.honvay.cola.auth.social.wechat.api.WechatUserInfo; 5 | import org.springframework.social.connect.ApiAdapter; 6 | import org.springframework.social.connect.ConnectionValues; 7 | import org.springframework.social.connect.UserProfile; 8 | 9 | /** 10 | * 微信 api适配器,将微信 api的数据模型转为spring social的标准模型。 11 | * Created on 2018/1/11. 12 | * 13 | * @author LIQIU 14 | * @since 1.0 15 | */ 16 | public class WechatAdapter implements ApiAdapter { 17 | 18 | private String openId; 19 | 20 | public WechatAdapter() { 21 | } 22 | 23 | public WechatAdapter(String openId) { 24 | this.openId = openId; 25 | } 26 | 27 | @Override 28 | public boolean test(Wechat api) { 29 | return true; 30 | } 31 | 32 | @Override 33 | public void setConnectionValues(Wechat api, ConnectionValues values) { 34 | WechatUserInfo userInfo = api.getUserInfo(openId); 35 | values.setProviderUserId(userInfo.getUnionid()); 36 | values.setDisplayName(userInfo.getNickname()); 37 | values.setImageUrl(userInfo.getHeadimgurl()); 38 | } 39 | 40 | @Override 41 | public UserProfile fetchUserProfile(Wechat api) { 42 | return null; 43 | } 44 | 45 | @Override 46 | public void updateStatus(Wechat api, String message) { 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-wechat/src/main/java/com/honvay/cola/auth/social/wechat/connect/WechatServiceProvider.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social.wechat.connect; 2 | 3 | import com.honvay.cola.auth.social.wechat.api.Wechat; 4 | import com.honvay.cola.auth.social.wechat.api.impl.WechatImpl; 5 | import org.springframework.social.oauth2.AbstractOAuth2ServiceProvider; 6 | 7 | /** 8 | * 微信的OAuth2流程处理器的提供器,供spring social的connect体系调用 9 | * Created on 2018/1/11. 10 | * 11 | * @author zlf 12 | * @since 1.0 13 | */ 14 | public class WechatServiceProvider extends AbstractOAuth2ServiceProvider { 15 | 16 | /** 17 | * 微信获取授权码的url 18 | */ 19 | private static final String WEIXIN_URL_AUTHORIZE = "https://open.weixin.qq.com/connect/qrconnect"; 20 | /** 21 | * 微信获取accessToken的url(微信在获取accessToken时也已经返回openId) 22 | */ 23 | private static final String WEIXIN_URL_ACCESS_TOKEN = "https://api.weixin.qq.com/sns/oauth2/access_token"; 24 | 25 | public WechatServiceProvider(String appId, String appSecret) { 26 | super(new WechatOAuth2Template(appId, appSecret, WEIXIN_URL_AUTHORIZE, WEIXIN_URL_ACCESS_TOKEN)); 27 | } 28 | 29 | public WechatServiceProvider(String appId, String appSecret, String authorizeUrl) { 30 | super(new WechatOAuth2Template(appId, appSecret, authorizeUrl, WEIXIN_URL_ACCESS_TOKEN)); 31 | } 32 | 33 | @Override 34 | public Wechat getApi(String accessToken) { 35 | return new WechatImpl(accessToken); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-wechatmp/src/main/java/com/honvay/cola/auth/social/wechatmp/WechatMpProperties.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social.wechatmp; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | 6 | /** 7 | * @author LIQIU 8 | * created on 2018-11-15 9 | **/ 10 | @Data 11 | @ConfigurationProperties("spring.social.wechatmp") 12 | public class WechatMpProperties { 13 | 14 | private String appId; 15 | 16 | private String appSecret; 17 | 18 | private String providerId = "wechatmp"; 19 | 20 | private String scope = "snsapi_userinfo"; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-wechatmp/src/main/java/com/honvay/cola/auth/social/wechatmp/api/WechatMp.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social.wechatmp.api; 2 | 3 | /** 4 | * https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419316518&token=2d3bbb7b39c63ab8196e7aad045811f2d47e8602&lang=zh_CN 5 | * https://api.weixin.qq.com/sns/userinfo?access_token=ACCESS_TOKEN&openid=OPENID 6 | * 微信API调用接口 7 | * Created on 2018/1/11. 8 | * 9 | * @author LIQIU 10 | * @since 1.0 11 | */ 12 | public interface WechatMp { 13 | WechatMpUserInfo getUserInfo(String openId); 14 | } 15 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-wechatmp/src/main/java/com/honvay/cola/auth/social/wechatmp/api/WechatMpUserInfo.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social.wechatmp.api; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * 微信返回的用户信息 7 | * Created on 2018/1/11. 8 | * 9 | * @author LIQIU 10 | * @since 1.0 11 | */ 12 | @Data 13 | public class WechatMpUserInfo { 14 | /** 15 | * 普通用户的标识,对当前开发者帐号唯一 16 | */ 17 | private String openid; 18 | /** 19 | * 普通用户昵称 20 | */ 21 | private String nickname; 22 | /** 23 | * 语言 24 | */ 25 | private String language; 26 | /** 27 | * 普通用户性别,1为男性,2为女性 28 | */ 29 | private String sex; 30 | /** 31 | * 普通用户个人资料填写的省份 32 | */ 33 | private String province; 34 | /** 35 | * 普通用户个人资料填写的城市 36 | */ 37 | private String city; 38 | /** 39 | * 国家,如中国为CN 40 | */ 41 | private String country; 42 | /** 43 | * 用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空 44 | */ 45 | private String headimgurl; 46 | /** 47 | * 用户特权信息,json数组,如微信沃卡用户为(chinaunicom) 48 | */ 49 | private String[] privilege; 50 | /** 51 | * 用户统一标识。针对一个微信开放平台帐号下的应用,同一用户的unionid是唯一的。 52 | */ 53 | private String unionid; 54 | } 55 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-wechatmp/src/main/java/com/honvay/cola/auth/social/wechatmp/connect/WechatMpAccessGrant.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social.wechatmp.connect; 2 | 3 | import lombok.Data; 4 | import org.springframework.social.oauth2.AccessGrant; 5 | 6 | /** 7 | * 微信的access_token信息。与标准OAuth2协议不同,微信在获取access_token时会同时返回openId,并没有单独的通过accessToke换取openId的服务 8 | * 9 | * 所以在这里继承了标准AccessGrant,添加了openId字段,作为对微信access_token信息的封装。 10 | * Created on 2018/1/11. 11 | * 12 | * @author LIQIU 13 | * @since 1.0 14 | */ 15 | @Data 16 | public class WechatMpAccessGrant extends AccessGrant { 17 | 18 | private String openId; 19 | 20 | public WechatMpAccessGrant() { 21 | super(""); 22 | } 23 | 24 | public WechatMpAccessGrant(String accessToken, String scope, String refreshToken, Long expiresIn) { 25 | super(accessToken, scope, refreshToken, expiresIn); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-wechatmp/src/main/java/com/honvay/cola/auth/social/wechatmp/connect/WechatMpAdapter.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social.wechatmp.connect; 2 | 3 | import com.honvay.cola.auth.social.wechatmp.api.WechatMp; 4 | import com.honvay.cola.auth.social.wechatmp.api.WechatMpUserInfo; 5 | import org.springframework.social.connect.ApiAdapter; 6 | import org.springframework.social.connect.ConnectionValues; 7 | import org.springframework.social.connect.UserProfile; 8 | 9 | /** 10 | * 微信 api适配器,将微信 api的数据模型转为spring social的标准模型。 11 | * Created on 2018/1/11. 12 | * 13 | * @author LIQIU 14 | * @since 1.0 15 | */ 16 | public class WechatMpAdapter implements ApiAdapter { 17 | 18 | private String openId; 19 | 20 | public WechatMpAdapter() { 21 | } 22 | 23 | public WechatMpAdapter(String openId) { 24 | this.openId = openId; 25 | } 26 | 27 | @Override 28 | public boolean test(WechatMp api) { 29 | return true; 30 | } 31 | 32 | @Override 33 | public void setConnectionValues(WechatMp api, ConnectionValues values) { 34 | WechatMpUserInfo userInfo = api.getUserInfo(openId); 35 | values.setProviderUserId(userInfo.getUnionid()); 36 | values.setDisplayName(userInfo.getNickname()); 37 | values.setImageUrl(userInfo.getHeadimgurl()); 38 | } 39 | 40 | @Override 41 | public UserProfile fetchUserProfile(WechatMp api) { 42 | return null; 43 | } 44 | 45 | @Override 46 | public void updateStatus(WechatMp api, String message) { 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/cola-auth-social-wechatmp/src/main/java/com/honvay/cola/auth/social/wechatmp/connect/WechatMpServiceProvider.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.social.wechatmp.connect; 2 | 3 | 4 | import com.honvay.cola.auth.social.wechatmp.api.WechatMp; 5 | import com.honvay.cola.auth.social.wechatmp.api.impl.WechatMpImpl; 6 | import org.springframework.social.oauth2.AbstractOAuth2ServiceProvider; 7 | 8 | /** 9 | * 微信的OAuth2流程处理器的提供器,供spring social的connect体系调用 10 | * Created on 2018/1/11. 11 | * 12 | * @author zlf 13 | * @since 1.0 14 | */ 15 | public class WechatMpServiceProvider extends AbstractOAuth2ServiceProvider { 16 | 17 | /** 18 | * 微信获取授权码的url 19 | */ 20 | private static final String WEIXIN_URL_AUTHORIZE = "https://open.weixin.qq.com/connect/oauth2/authorize"; 21 | /** 22 | * 微信获取accessToken的url(微信在获取accessToken时也已经返回openId) 23 | */ 24 | private static final String WEIXIN_URL_ACCESS_TOKEN = "https://api.weixin.qq.com/sns/oauth2/access_token"; 25 | 26 | public WechatMpServiceProvider(String appId, String appSecret) { 27 | super(new WechatMpOAuth2Template(appId, appSecret, WEIXIN_URL_AUTHORIZE, WEIXIN_URL_ACCESS_TOKEN)); 28 | } 29 | 30 | public WechatMpServiceProvider(String appId, String appSecret, String authorizeUrl) { 31 | super(new WechatMpOAuth2Template(appId, appSecret, authorizeUrl, WEIXIN_URL_ACCESS_TOKEN)); 32 | } 33 | 34 | @Override 35 | public WechatMp getApi(String accessToken) { 36 | return new WechatMpImpl(accessToken); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-social/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.honvay 7 | cola-auth 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-auth-social 13 | 14 | cola-auth-social-qq 15 | cola-auth-social-wechat 16 | cola-auth-social-alipay 17 | cola-auth-social-web 18 | cola-auth-social-wechatmp 19 | cola-auth-social-base 20 | 21 | pom 22 | 23 | 24 | 25 | org.springframework.social 26 | spring-social-autoconfigure 27 | 28 | 29 | org.springframework.social 30 | spring-social-security 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-web/src/main/java/com/honvay/cola/auth/web/WebAuthenticationConstant.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.web; 2 | 3 | /** 4 | * @author LIQIU 5 | * created on 2018/12/26 6 | **/ 7 | public class WebAuthenticationConstant { 8 | 9 | /** 10 | * 需要验证码验证 11 | */ 12 | public static final String CAPTCHA_AUTHENTICATION_REQUIRED_KEY = "captcha_authentication_required"; 13 | /** 14 | * 认证失败原因 15 | */ 16 | public static final String AUTHENTICATION_FAIL_MESSAGE_KEY = "authentication_fail_message"; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-web/src/main/java/com/honvay/cola/auth/web/controller/LoginController.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.web.controller; 2 | 3 | import org.springframework.security.core.Authentication; 4 | import org.springframework.security.core.context.SecurityContextHolder; 5 | import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler; 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestMethod; 10 | 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | 14 | /** 15 | * @author LIQIU 16 | */ 17 | @Controller 18 | public class LoginController { 19 | 20 | 21 | @GetMapping("/login") 22 | public String loginPage() { 23 | return "login"; 24 | } 25 | 26 | @GetMapping("/loginBySms") 27 | public String loginBySmsPage() { 28 | return "loginBySms"; 29 | } 30 | 31 | 32 | @RequestMapping(value = "/logout", method = RequestMethod.GET) 33 | public String logoutPage(HttpServletRequest request, HttpServletResponse response) { 34 | Authentication auth = SecurityContextHolder.getContext().getAuthentication(); 35 | if (auth != null) { 36 | new SecurityContextLogoutHandler().logout(request, response, auth); 37 | } 38 | return "redirect:/login?logout"; 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-web/src/main/java/com/honvay/cola/auth/web/controller/SessionController.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.web.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.http.ResponseEntity; 5 | import org.springframework.security.core.session.SessionInformation; 6 | import org.springframework.security.core.session.SessionRegistry; 7 | import org.springframework.stereotype.Controller; 8 | import org.springframework.web.bind.annotation.PostMapping; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | 11 | import java.security.Principal; 12 | import java.util.List; 13 | 14 | /** 15 | * @author LIQIU 16 | * created on 2018-11-24 17 | **/ 18 | @Controller 19 | @RequestMapping("/session") 20 | public class SessionController { 21 | 22 | @Autowired 23 | private SessionRegistry sessionRegistry; 24 | 25 | @PostMapping("/revoke") 26 | public ResponseEntity revoke(Principal principal) { 27 | sessionRegistry.getAllPrincipals(); 28 | List sessionInformations = sessionRegistry 29 | .getAllSessions(principal, false); 30 | for (SessionInformation sessionInformation : sessionInformations) { 31 | sessionInformation.expireNow(); 32 | 33 | sessionRegistry.removeSessionInformation(sessionInformation 34 | .getSessionId()); 35 | 36 | } 37 | return ResponseEntity.ok().build(); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-web/src/main/java/com/honvay/cola/auth/web/controller/SessionInvalidController.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.web.controller; 2 | 3 | import com.honvay.cola.framework.core.protocol.Result; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.http.HttpStatus; 6 | import org.springframework.http.MediaType; 7 | import org.springframework.stereotype.Controller; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.ResponseBody; 10 | import org.springframework.web.bind.annotation.ResponseStatus; 11 | import org.springframework.web.servlet.View; 12 | import org.springframework.web.servlet.view.RedirectView; 13 | 14 | import javax.servlet.http.HttpServletRequest; 15 | 16 | /** 17 | * @author LIQIU 18 | * created on 2018-11-25 19 | **/ 20 | @Slf4j 21 | @Controller 22 | @RequestMapping("/session-invalid") 23 | public class SessionInvalidController { 24 | 25 | @RequestMapping(produces = MediaType.TEXT_HTML_VALUE) 26 | public View sessionInvalidPage(HttpServletRequest request) { 27 | log.info(request.getRequestURI()); 28 | log.info(request.getHeader("Refer")); 29 | return new RedirectView("/login?session"); 30 | } 31 | 32 | @ResponseBody 33 | @RequestMapping 34 | @ResponseStatus(HttpStatus.FORBIDDEN) 35 | public Result sessionInvalid() { 36 | return Result.success("会话已失效"); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-web/src/main/java/com/honvay/cola/auth/web/handler/WebAuthenticationFailureHandler.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.web.handler; 2 | 3 | import com.honvay.cola.auth.web.WebAuthenticationConstant; 4 | import org.springframework.security.core.AuthenticationException; 5 | import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import java.io.IOException; 11 | 12 | /** 13 | * @author LIQIU 14 | * created on 2018-11-24 15 | **/ 16 | public class WebAuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler { 17 | 18 | 19 | public WebAuthenticationFailureHandler(String defaultFailureUrl) { 20 | super(defaultFailureUrl); 21 | } 22 | 23 | @Override 24 | public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { 25 | request.getSession().setAttribute(WebAuthenticationConstant.AUTHENTICATION_FAIL_MESSAGE_KEY, exception.getMessage()); 26 | request.getSession().setAttribute(WebAuthenticationConstant.CAPTCHA_AUTHENTICATION_REQUIRED_KEY, true); 27 | super.onAuthenticationFailure(request, response, exception); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /cola-auth/cola-auth-web/src/main/java/com/honvay/cola/auth/web/handler/WebAuthenticationSuccessHandler.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.auth.web.handler; 2 | 3 | import com.honvay.cola.auth.web.WebAuthenticationConstant; 4 | import org.springframework.security.core.Authentication; 5 | import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import java.io.IOException; 11 | 12 | /** 13 | * @author LIQIU 14 | * created on 2018/12/26 15 | **/ 16 | public class WebAuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler { 17 | 18 | @Override 19 | public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { 20 | request.getSession().removeAttribute(WebAuthenticationConstant.AUTHENTICATION_FAIL_MESSAGE_KEY); 21 | request.getSession().removeAttribute(WebAuthenticationConstant.CAPTCHA_AUTHENTICATION_REQUIRED_KEY); 22 | super.onAuthenticationSuccess(request,response,authentication); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /cola-auth/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-auth 13 | pom 14 | 15 | cola-auth-base 16 | cola-auth-oauth2 17 | cola-auth-social 18 | cola-auth-core 19 | cola-auth-client 20 | cola-auth-sms 21 | cola-auth-openid 22 | cola-auth-web 23 | cola-auth-jwt 24 | cola-auth-captcha 25 | cola-auth-ac 26 | cola-auth-channel 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /cola-framework/cola-framework-core/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-framework 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-framework-core 13 | 14 | 15 | 16 | org.springframework 17 | spring-core 18 | provided 19 | 20 | 21 | -------------------------------------------------------------------------------- /cola-framework/cola-framework-core/src/main/java/com/honvay/cola/framework/core/ErrorMessage.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.framework.core; 2 | 3 | /** 4 | * @author LIQIU 5 | * created on 2018/12/24 6 | **/ 7 | public interface ErrorMessage { 8 | 9 | /** 10 | * 获取错误码 11 | * 12 | * @return 错误码 13 | */ 14 | String getCode(); 15 | 16 | /** 17 | * 获取错误信息 18 | * 19 | * @return 错误信息 20 | */ 21 | String getMessage(); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /cola-framework/cola-framework-core/src/main/java/com/honvay/cola/framework/core/exception/ServiceException.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.framework.core.exception; 2 | 3 | import com.honvay.cola.framework.core.ErrorMessage; 4 | 5 | /** 6 | * @author LIQIU 7 | * created on 2018/12/24 8 | **/ 9 | public class ServiceException extends RuntimeException { 10 | 11 | private String code; 12 | 13 | public ServiceException(String code, String message, Throwable throwable) { 14 | super(message, throwable); 15 | this.code = code; 16 | } 17 | 18 | public ServiceException(String code, String message) { 19 | this(code, message, null); 20 | } 21 | 22 | public ServiceException(ErrorMessage errorMessage) { 23 | this(errorMessage.getCode(), errorMessage.getMessage(), null); 24 | } 25 | 26 | public ServiceException(ErrorMessage errorMessage, Throwable throwable) { 27 | this(errorMessage.getCode(), errorMessage.getMessage(), throwable); 28 | } 29 | 30 | public ServiceException(ErrorMessage errorMessage, String message) { 31 | this(errorMessage.getCode(), message, null); 32 | } 33 | 34 | public ServiceException(ErrorMessage errorMessage, String message, Throwable throwable) { 35 | this(errorMessage.getCode(), message, throwable); 36 | } 37 | 38 | public String getCode() { 39 | return code; 40 | } 41 | 42 | public void setCode(String code) { 43 | this.code = code; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /cola-framework/cola-framework-util/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-framework 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-framework-util 13 | 14 | 15 | -------------------------------------------------------------------------------- /cola-framework/cola-framework-util/src/main/java/com/honvay/cola/framework/util/PatternUtils.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.framework.util; 2 | 3 | import java.util.regex.Matcher; 4 | import java.util.regex.Pattern; 5 | 6 | /** 7 | * 格式工具类,用于检查各种格式 8 | * 9 | * @author LIQIU 10 | * created on 2018/12/25 11 | **/ 12 | public class PatternUtils { 13 | 14 | private static Pattern PHONE_NUMBER_PATTERN; 15 | 16 | static { 17 | PHONE_NUMBER_PATTERN = Pattern.compile("^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(166)|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9]))\\d{8}$"); 18 | } 19 | 20 | 21 | public static final boolean isPhoneNumber(String phoneNumber) { 22 | if (phoneNumber.length() != 11) { 23 | return false; 24 | } else { 25 | Matcher m = PHONE_NUMBER_PATTERN.matcher(phoneNumber); 26 | return m.matches(); 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /cola-framework/cola-framework-util/src/main/java/com/honvay/cola/framework/util/RandomUtils.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.framework.util; 2 | 3 | import java.util.Random; 4 | 5 | /** 6 | * 验证码生成器 7 | * 8 | * @author LIQIU 9 | */ 10 | public class RandomUtils { 11 | 12 | public static final String VERIFY_CODES = "0123456789ABCDEFGHJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; 13 | public static final String NUMBER_VERIFY_CODES = "012345679"; 14 | private static Random random = new Random(); 15 | 16 | 17 | /** 18 | * 使用系统默认字符源生成验证码 19 | * 20 | * @param verifySize 验证码长度 21 | * @return 22 | */ 23 | public static String generateString(int verifySize) { 24 | return generateString(verifySize, VERIFY_CODES); 25 | } 26 | 27 | /** 28 | * 使用系统默认字符源生成数字验证码 29 | * 30 | * @param verifySize 验证码长度 31 | * @return 32 | */ 33 | public static String generateNumber(int verifySize) { 34 | return generateString(verifySize, NUMBER_VERIFY_CODES); 35 | } 36 | 37 | /** 38 | * 使用指定源生成验证码 39 | * 40 | * @param verifySize 验证码长度 41 | * @param sources 验证码字符源 42 | * @return 43 | */ 44 | public static String generateString(int verifySize, String sources) { 45 | if (sources == null || sources.length() == 0) { 46 | sources = VERIFY_CODES; 47 | } 48 | int codesLen = sources.length(); 49 | Random rand = new Random(System.currentTimeMillis()); 50 | StringBuilder verifyCode = new StringBuilder(verifySize); 51 | for (int i = 0; i < verifySize; i++) { 52 | verifyCode.append(sources.charAt(rand.nextInt(codesLen - 1))); 53 | } 54 | return verifyCode.toString(); 55 | } 56 | } -------------------------------------------------------------------------------- /cola-framework/cola-framework-web/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-framework 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-framework-web 13 | 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-starter-web 18 | 19 | 20 | -------------------------------------------------------------------------------- /cola-framework/cola-framework-web/src/main/java/com/honvay/cola/framework/web/GlobalControllerAdvise.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.framework.web; 2 | 3 | import org.springframework.web.bind.annotation.ControllerAdvice; 4 | 5 | /** 6 | * @author LIQIU 7 | * created on 2019/1/14 8 | **/ 9 | @ControllerAdvice 10 | public class GlobalControllerAdvise { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /cola-framework/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-framework 13 | pom 14 | 15 | cola-framework-util 16 | cola-framework-core 17 | cola-framework-web 18 | 19 | -------------------------------------------------------------------------------- /cola-notify/cola-notify-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-notify 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-notify-api 13 | 14 | 15 | 16 | org.projectlombok 17 | lombok 18 | 19 | 20 | -------------------------------------------------------------------------------- /cola-notify/cola-notify-api/src/main/java/com/honvay/cola/nc/api/NotificationService.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.nc.api; 2 | 3 | import com.honvay.cola.nc.api.model.Notification; 4 | 5 | /** 6 | * @author LIQIU 7 | * created on 2018/12/25 8 | **/ 9 | public interface NotificationService { 10 | 11 | /** 12 | * 通知 13 | * 14 | * @param notification 通知 15 | */ 16 | void notify(Notification notification); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /cola-notify/cola-notify-api/src/main/java/com/honvay/cola/nc/api/exchanger/NotificationExchanger.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.nc.api.exchanger; 2 | 3 | 4 | import com.honvay.cola.nc.api.model.Notification; 5 | 6 | /** 7 | * @author LIQIU 8 | * @date 2018-3-27 9 | **/ 10 | public interface NotificationExchanger { 11 | 12 | 13 | /** 14 | * 通知 15 | * 16 | * @param notification 路由通知 17 | * @return 18 | */ 19 | boolean exchange(T notification); 20 | } 21 | -------------------------------------------------------------------------------- /cola-notify/cola-notify-api/src/main/java/com/honvay/cola/nc/api/model/EmailNotification.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.nc.api.model; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @author LIQIU 7 | * @date 2018-3-27 8 | **/ 9 | @Data 10 | public class EmailNotification extends Notification{ 11 | 12 | private String receiver; 13 | 14 | private String title; 15 | 16 | private String content; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /cola-notify/cola-notify-api/src/main/java/com/honvay/cola/nc/api/model/Notification.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.nc.api.model; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | import java.util.Map; 7 | 8 | /** 9 | * @author LIQIU 10 | * @date 2018-3-27 11 | **/ 12 | @Data 13 | public class Notification implements Serializable { 14 | 15 | private Map params; 16 | 17 | private String receiver; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /cola-notify/cola-notify-email/cola-notify-email-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-notify-email 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-notify-email-api 13 | 14 | 15 | -------------------------------------------------------------------------------- /cola-notify/cola-notify-email/cola-notify-email-provider/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-notify-email 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-notify-email-provider 13 | 14 | 15 | -------------------------------------------------------------------------------- /cola-notify/cola-notify-email/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-notify 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-notify-email 13 | pom 14 | 15 | cola-notify-email-api 16 | cola-notify-email-provider 17 | 18 | 19 | 20 | 21 | com.honvay 22 | cola-notify-api 23 | 24 | 25 | com.fasterxml.jackson.core 26 | jackson-databind 27 | 28 | 29 | org.apache.commons 30 | commons-lang3 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-mail 35 | 36 | 37 | -------------------------------------------------------------------------------- /cola-notify/cola-notify-provider/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-notify 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-notify-provider 13 | 14 | 15 | 16 | org.projectlombok 17 | lombok 18 | 19 | 20 | org.apache.commons 21 | commons-lang3 22 | 23 | 24 | com.honvay 25 | cola-framework-core 26 | 27 | 28 | com.honvay 29 | cola-notify-api 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-web 34 | 35 | 36 | io.swagger 37 | swagger-annotations 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /cola-notify/cola-notify-provider/src/main/java/com/honvay/cola/nc/provider/NotificationController.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.nc.provider; 2 | 3 | import com.honvay.cola.framework.core.protocol.Result; 4 | import com.honvay.cola.nc.api.model.Notification; 5 | import io.swagger.annotations.Api; 6 | import io.swagger.annotations.ApiOperation; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | 10 | /** 11 | * @author LIQIU 12 | * @date 2018-3-27 13 | **/ 14 | @Api(value = "通知中心") 15 | public class NotificationController { 16 | 17 | @Autowired 18 | private NotificationDispatcher dispatcher; 19 | 20 | @ApiOperation("/短信通知") 21 | @RequestMapping("/notify") 22 | public Result notify(Notification notification) { 23 | this.dispatcher.dispatch(notification); 24 | return Result.success(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /cola-notify/cola-notify-provider/src/main/java/com/honvay/cola/nc/provider/NotificationTask.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.nc.provider; 2 | 3 | 4 | import com.honvay.cola.nc.api.model.Notification; 5 | import com.honvay.cola.nc.api.exchanger.NotificationExchanger; 6 | 7 | import java.util.concurrent.Callable; 8 | 9 | /** 10 | * @author LIQIU 11 | * @date 2018-3-31 12 | **/ 13 | public class NotificationTask implements Callable { 14 | 15 | private NotificationExchanger notificationExchanger; 16 | 17 | private T notification; 18 | 19 | public NotificationTask(NotificationExchanger notificationExchanger, T notification) { 20 | this.notificationExchanger = notificationExchanger; 21 | this.notification = notification; 22 | } 23 | 24 | @Override 25 | public Boolean call() { 26 | return notificationExchanger.exchange(notification); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /cola-notify/cola-notify-provider/src/main/java/com/honvay/cola/nc/provider/NotificationThreadFactory.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.nc.provider; 2 | 3 | import java.util.concurrent.ThreadFactory; 4 | import java.util.concurrent.atomic.AtomicInteger; 5 | 6 | /** 7 | * The default thread factory 8 | */ 9 | public class NotificationThreadFactory implements ThreadFactory { 10 | private static final AtomicInteger poolNumber = new AtomicInteger(1); 11 | private final ThreadGroup group; 12 | private final AtomicInteger threadNumber = new AtomicInteger(1); 13 | private final String namePrefix; 14 | 15 | NotificationThreadFactory() { 16 | SecurityManager s = System.getSecurityManager(); 17 | group = (s != null) ? s.getThreadGroup() : 18 | Thread.currentThread().getThreadGroup(); 19 | namePrefix = "notification-" + 20 | poolNumber.getAndIncrement() + 21 | "-thread-"; 22 | } 23 | 24 | @Override 25 | public Thread newThread(Runnable r) { 26 | Thread t = new Thread(group, r, 27 | namePrefix + threadNumber.getAndIncrement(), 28 | 0); 29 | if (t.isDaemon()) { 30 | t.setDaemon(false); 31 | } 32 | if (t.getPriority() != Thread.NORM_PRIORITY) { 33 | t.setPriority(Thread.NORM_PRIORITY); 34 | } 35 | return t; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /cola-notify/cola-notify-sms/cola-notify-sms-aliyun/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-notify-sms 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-notify-sms-aliyun 13 | 14 | 15 | 16 | com.honvay 17 | cola-notify-sms-api 18 | 19 | 20 | com.aliyun 21 | aliyun-java-sdk-dysmsapi 22 | 1.1.0 23 | 24 | 25 | com.aliyun 26 | aliyun-java-sdk-core 27 | 4.2.4 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter 32 | 33 | 34 | org.apache.commons 35 | commons-lang3 36 | 37 | 38 | -------------------------------------------------------------------------------- /cola-notify/cola-notify-sms/cola-notify-sms-aliyun/src/main/java/com/honvay/cola/notify/sms/aliyun/config/AliyunSmsProperties.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.notify.sms.aliyun.config; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | 6 | /** 7 | * @author LIQIU 8 | */ 9 | @Data 10 | @ConfigurationProperties(prefix = "spring.notify.sms.aliyun") 11 | public class AliyunSmsProperties { 12 | 13 | private String accessKeyId; 14 | private String accessKeySecret; 15 | } 16 | -------------------------------------------------------------------------------- /cola-notify/cola-notify-sms/cola-notify-sms-aliyun/src/main/java/com/honvay/cola/notify/sms/aliyun/config/AliyunSmsSenderConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.notify.sms.aliyun.config; 2 | 3 | import com.honvay.cola.notify.sms.aliyun.AliyunSmsSender; 4 | import com.honvay.cola.notify.sms.api.sender.SmsSender; 5 | import org.springframework.beans.BeanUtils; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 8 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 9 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 10 | import org.springframework.context.annotation.Bean; 11 | import org.springframework.context.annotation.Configuration; 12 | 13 | /** 14 | * @author LIQIU 15 | * created on 2019/1/14 16 | **/ 17 | @Configuration 18 | @EnableConfigurationProperties(AliyunSmsProperties.class) 19 | public class AliyunSmsSenderConfiguration { 20 | 21 | @Autowired 22 | private AliyunSmsProperties aliyunSmsProperties; 23 | 24 | 25 | @Bean 26 | @ConditionalOnClass({AliyunSmsSender.class}) 27 | @ConditionalOnProperty(name = "spring.notify.sms.aliyun.accessKeyId") 28 | public SmsSender smsSender() { 29 | AliyunSmsSender sender = new AliyunSmsSender(); 30 | BeanUtils.copyProperties(aliyunSmsProperties, sender); 31 | return sender; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /cola-notify/cola-notify-sms/cola-notify-sms-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-notify-sms 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-notify-sms-api 13 | 14 | 15 | com.honvay 16 | cola-notify-api 17 | 18 | 19 | -------------------------------------------------------------------------------- /cola-notify/cola-notify-sms/cola-notify-sms-api/src/main/java/com/honvay/cola/notify/sms/api/SmsNotification.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.notify.sms.api; 2 | 3 | import com.honvay.cola.nc.api.model.Notification; 4 | import lombok.Data; 5 | import lombok.EqualsAndHashCode; 6 | 7 | /** 8 | * @author LIQIU 9 | * @date 2018-3-27 10 | **/ 11 | @Data 12 | @EqualsAndHashCode(callSuper = true) 13 | public class SmsNotification extends Notification { 14 | 15 | private String templateCode; 16 | 17 | private String signName; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /cola-notify/cola-notify-sms/cola-notify-sms-api/src/main/java/com/honvay/cola/notify/sms/api/sender/SmsParameter.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.notify.sms.api.sender; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * 短信 9 | * 10 | * @author LIQIU 11 | */ 12 | @Data 13 | public class SmsParameter { 14 | 15 | private String templateCode; 16 | private String signName; 17 | private List phoneNumbers; 18 | private String params; 19 | } 20 | -------------------------------------------------------------------------------- /cola-notify/cola-notify-sms/cola-notify-sms-api/src/main/java/com/honvay/cola/notify/sms/api/sender/SmsSendResult.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.notify.sms.api.sender; 2 | 3 | 4 | import lombok.Data; 5 | 6 | /** 7 | * @author LIQIU 8 | */ 9 | @Data 10 | public class SmsSendResult { 11 | 12 | private boolean success; 13 | 14 | private String code; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /cola-notify/cola-notify-sms/cola-notify-sms-api/src/main/java/com/honvay/cola/notify/sms/api/sender/SmsSender.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.notify.sms.api.sender; 2 | 3 | /** 4 | * 短信发送器 5 | * 6 | * @author LIQIU 7 | */ 8 | public interface SmsSender { 9 | 10 | /** 11 | * 发送短信 12 | * 13 | * @param parameter 14 | * @return 15 | */ 16 | SmsSendResult send(SmsParameter parameter); 17 | } 18 | -------------------------------------------------------------------------------- /cola-notify/cola-notify-sms/cola-notify-sms-provider/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-notify-sms 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-notify-sms-provider 13 | 14 | 15 | 16 | com.honvay 17 | cola-notify-sms-api 18 | 19 | 20 | org.projectlombok 21 | lombok 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-data-redis 26 | 27 | 28 | com.fasterxml.jackson.core 29 | jackson-databind 30 | 31 | 32 | org.apache.commons 33 | commons-lang3 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /cola-notify/cola-notify-sms/cola-notify-sms-provider/src/main/java/com/honvay/cola/nc/sms/SmsNotificationAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.nc.sms; 2 | 3 | import com.honvay.cola.nc.sms.exchanger.SmsNotificationExchanger; 4 | import com.honvay.cola.notify.sms.api.sender.SmsSender; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.data.redis.core.StringRedisTemplate; 8 | 9 | /** 10 | * @author LIQIU 11 | * @date 2018-3-27 12 | **/ 13 | @Configuration 14 | public class SmsNotificationAutoConfiguration { 15 | 16 | @Bean 17 | public SmsNotificationExchanger smsNotificationExchanger(SmsSender smsSender, 18 | StringRedisTemplate redisTemplate) { 19 | //每分钟发送短信位20次,写死 20 | return new SmsNotificationExchanger(smsSender, redisTemplate, 20L); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /cola-notify/cola-notify-sms/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-notify 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-notify-sms 13 | pom 14 | 15 | cola-notify-sms-api 16 | cola-notify-sms-aliyun 17 | cola-notify-sms-provider 18 | 19 | 20 | -------------------------------------------------------------------------------- /cola-notify/cola-notify-wechat/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-notify 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-notify-wechat 13 | 14 | 15 | -------------------------------------------------------------------------------- /cola-notify/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-notify 13 | pom 14 | 15 | cola-notify-api 16 | cola-notify-provider 17 | cola-notify-sms 18 | cola-notify-wechat 19 | cola-notify-email 20 | 21 | -------------------------------------------------------------------------------- /cola-samples/cola-sample-jwt/src/main/java/com/honvay/cola/sample/jwt/JwtAuthController.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.sample.jwt; 2 | 3 | import com.honvay.cola.auth.core.model.AuthenticatedUser; 4 | import com.honvay.cola.framework.core.protocol.Result; 5 | import org.springframework.security.core.annotation.AuthenticationPrincipal; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | /** 10 | * @author LIQIU 11 | * created on 2018/12/25 12 | **/ 13 | @RestController 14 | public class JwtAuthController { 15 | 16 | @RequestMapping("/jwt/user/current") 17 | public Result current(@AuthenticationPrincipal AuthenticatedUser authenticatedUser) { 18 | return Result.success(authenticatedUser); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /cola-samples/cola-sample-jwt/src/main/java/com/honvay/cola/sample/jwt/JwtSampleApplication.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.sample.jwt; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.domain.EntityScan; 6 | import org.springframework.context.annotation.ComponentScan; 7 | import org.springframework.data.jpa.repository.config.EnableJpaRepositories; 8 | 9 | /** 10 | * @author LIQIU 11 | */ 12 | @EnableJpaRepositories("com.honvay") 13 | @EntityScan("com.honvay") 14 | @ComponentScan("com.honvay") 15 | @SpringBootApplication 16 | public class JwtSampleApplication { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(JwtSampleApplication.class, args); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /cola-samples/cola-sample-jwt/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | messages: 3 | basename: org/springframework/security/messages 4 | thymeleaf: 5 | cache: false 6 | datasource: 7 | driver-class-name: com.mysql.jdbc.Driver 8 | url: jdbc:mysql://localhost:3306/cola-auth?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC 9 | username: root 10 | password: root 11 | initialization-mode: always 12 | jpa: 13 | hibernate: 14 | ddl-auto: none 15 | social: 16 | qq: 17 | app-id: id 18 | app-secret: secret 19 | wechat: 20 | app-id: id 21 | app-secret: secret 22 | security: 23 | jwt: 24 | signing-key: cola 25 | logging: 26 | level: 27 | org.springframework.web: debug 28 | com.honvay: debug -------------------------------------------------------------------------------- /cola-samples/cola-sample-oauth2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-samples 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-sample-oauth2 13 | 14 | 15 | 16 | com.honvay 17 | cola-auth-base 18 | 19 | 20 | com.honvay 21 | cola-auth-oauth2-base 22 | 23 | 24 | com.alibaba 25 | druid-spring-boot-starter 26 | 1.1.10 27 | 28 | 29 | mysql 30 | mysql-connector-java 31 | 32 | 33 | com.honvay 34 | cola-notify-provider 35 | 36 | 37 | com.honvay 38 | cola-user-provider 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /cola-samples/cola-sample-sso/cola-sample-sso-app/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-sample-sso 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-sample-sso-app 13 | 14 | 15 | 16 | com.honvay 17 | cola-auth-client-app 18 | 19 | 20 | -------------------------------------------------------------------------------- /cola-samples/cola-sample-sso/cola-sample-sso-app/src/main/java/com/honvay/cola/sso/smaple/app/AuthController.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.sso.smaple.app; 2 | 3 | import com.honvay.cola.auth.common.client.app.SsoAuthClient; 4 | import com.honvay.cola.framework.core.protocol.Result; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.security.oauth2.common.OAuth2AccessToken; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.PostMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import java.security.Principal; 12 | 13 | /** 14 | * @author LIQIU 15 | * created on 2018-11-25 16 | **/ 17 | @RestController 18 | public class AuthController { 19 | 20 | @Autowired 21 | private SsoAuthClient ssoAuthClient; 22 | 23 | 24 | @GetMapping("/user") 25 | public Principal principal(Principal principal) { 26 | return principal; 27 | } 28 | 29 | @PostMapping("/login") 30 | public OAuth2AccessToken login(String username, String password) { 31 | return ssoAuthClient.login(username, password); 32 | } 33 | 34 | @GetMapping("/logout") 35 | public Result logout() { 36 | return ssoAuthClient.logout(); 37 | } 38 | 39 | @PostMapping("/loginByOpenId") 40 | public OAuth2AccessToken loginByQQ(String openId, String provider) { 41 | return ssoAuthClient.loginByOpenId(openId, provider); 42 | } 43 | 44 | @PostMapping("/loginBySms") 45 | public OAuth2AccessToken loginBySms(String phoneNumber, String verificationCode) { 46 | return ssoAuthClient.loginBySms(phoneNumber, verificationCode); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /cola-samples/cola-sample-sso/cola-sample-sso-app/src/main/java/com/honvay/cola/sso/smaple/app/ResourceServerConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.sso.smaple.app; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 5 | import org.springframework.security.config.annotation.web.builders.WebSecurity; 6 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 7 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; 8 | import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; 9 | 10 | @Configuration 11 | @EnableResourceServer 12 | public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter { 13 | 14 | @Override 15 | public void configure(HttpSecurity http) throws Exception { 16 | http.authorizeRequests() 17 | .antMatchers("/login","/loginBySms","loginByOpenId").permitAll() 18 | .anyRequest().authenticated(); 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /cola-samples/cola-sample-sso/cola-sample-sso-app/src/main/java/com/honvay/cola/sso/smaple/app/SimpleAppApplication.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.sso.smaple.app; 2 | 3 | /** 4 | * @author LIQIU 5 | * created on 2018-11-26 6 | **/ 7 | 8 | import com.honvay.cola.auth.core.model.AuthenticatedUser; 9 | import org.springframework.boot.SpringApplication; 10 | import org.springframework.boot.autoconfigure.SpringBootApplication; 11 | import org.springframework.context.annotation.ComponentScan; 12 | import org.springframework.security.core.annotation.AuthenticationPrincipal; 13 | import org.springframework.web.bind.annotation.RequestMapping; 14 | import org.springframework.web.bind.annotation.RestController; 15 | 16 | /** 17 | * @author LIQIU 18 | * created on 2018-11-26 19 | **/ 20 | @ComponentScan("com.honvay") 21 | @RestController 22 | @SpringBootApplication 23 | public class SimpleAppApplication { 24 | 25 | public static void main(String[] args) { 26 | SpringApplication.run(SimpleAppApplication.class, args); 27 | } 28 | 29 | @RequestMapping("/user") 30 | public AuthenticatedUser home(@AuthenticationPrincipal AuthenticatedUser authenticatedUser) { 31 | return authenticatedUser; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /cola-samples/cola-sample-sso/cola-sample-sso-app/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8082 3 | 4 | security: 5 | oauth2: 6 | client: 7 | client-id: app 8 | client-secret: user 9 | access-token-uri: https://www.honvay.com/oauth/token 10 | revoke-token-uri: https://www.honvay.com/oauth/revoke 11 | user-authorization-uri: https://www.honvay.com/oauth/authorize 12 | resource: 13 | user-info-uri: https://www.honvay.com/user/me 14 | spring: 15 | thymeleaf: 16 | cache: false -------------------------------------------------------------------------------- /cola-samples/cola-sample-sso/cola-sample-sso-server/src/main/java/com/honvay/cola/sample/sso/SecurityConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.sample.sso; 2 | 3 | import com.honvay.cola.auth.channel.config.ChannelSecurityConfigurer; 4 | import org.springframework.core.annotation.Order; 5 | import org.springframework.security.config.annotation.web.builders.WebSecurity; 6 | import org.springframework.stereotype.Component; 7 | 8 | /** 9 | * @author LIQIU 10 | * created on 2018/12/26 11 | **/ 12 | @Component 13 | @Order(101) 14 | public class SecurityConfiguration implements ChannelSecurityConfigurer { 15 | 16 | @Override 17 | public void configure(WebSecurity web) { 18 | web.ignoring().antMatchers("/webjars/**", "/resources/**", "/favicon.ico"); 19 | } 20 | 21 | @Override 22 | public int getOrder() { 23 | return 2; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /cola-samples/cola-sample-sso/cola-sample-sso-server/src/main/java/com/honvay/cola/sample/sso/SsoServerSampleApplication.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.sample.sso; 2 | 3 | /** 4 | * @author LIQIU 5 | * created on 2018/12/26 6 | **/ 7 | 8 | import org.springframework.boot.SpringApplication; 9 | import org.springframework.boot.autoconfigure.SpringBootApplication; 10 | import org.springframework.boot.autoconfigure.domain.EntityScan; 11 | import org.springframework.context.annotation.ComponentScan; 12 | import org.springframework.data.jpa.repository.config.EnableJpaRepositories; 13 | 14 | /** 15 | * @author LIQIU 16 | */ 17 | @EnableJpaRepositories("com.honvay") 18 | @EntityScan("com.honvay") 19 | @ComponentScan("com.honvay") 20 | @SpringBootApplication 21 | public class SsoServerSampleApplication { 22 | 23 | public static void main(String[] args) { 24 | SpringApplication.run(SsoServerSampleApplication.class, args); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /cola-samples/cola-sample-sso/cola-sample-sso-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | messages: 3 | basename: messages,org/springframework/security/messages 4 | thymeleaf: 5 | cache: false 6 | datasource: 7 | driver-class-name: com.mysql.jdbc.Driver 8 | url: jdbc:mysql://localhost:3306/cola-auth?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC 9 | username: root 10 | password: root 11 | initialization-mode: always 12 | jpa: 13 | hibernate: 14 | ddl-auto: none 15 | social: 16 | login-process-url: /social 17 | signup-process-url: /social/signup 18 | signup-url: https://www.honvay.com/social/signup 19 | qq: 20 | app-id: id 21 | app-secret: secret 22 | wechat: 23 | app-id: id 24 | app-secret: secret 25 | alipay: 26 | app-id: id 27 | app-secret: secret 28 | signType: RSA 29 | private-key: pk 30 | public-key: pk 31 | sms: 32 | login-process-url: /loginBySms 33 | notify: 34 | aliyun: 35 | accessKeyId: 123 36 | accessKeySecret: 1231 37 | security: 38 | oauth2: 39 | resource: 40 | id: auth-controller 41 | logging: 42 | level: 43 | com.honvay: debug 44 | -------------------------------------------------------------------------------- /cola-samples/cola-sample-sso/cola-sample-sso-server/src/main/resources/templates/connect/alipayConnect.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 解绑支付宝 6 | 7 | 8 | 9 |
10 |
11 |
12 |
13 |

解绑支付宝

14 |
15 |

支付宝已解绑,3秒后返回主页

16 | 21 |
22 |
23 |

绑定支付宝发生错误:

24 |

返回主页

25 |
26 |
27 |
28 |
29 |
30 | 31 | 32 | -------------------------------------------------------------------------------- /cola-samples/cola-sample-sso/cola-sample-sso-server/src/main/resources/templates/connect/alipayConnected.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 支付宝绑定成功 6 | 7 | 8 | 9 |
10 |
11 |
12 |
13 |

绑定支付宝成功

14 |
15 |

支付宝已绑定,3秒后跳转到主页

16 |
17 |
18 |
19 |
20 |
21 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /cola-samples/cola-sample-sso/cola-sample-sso-server/src/main/resources/templates/connect/qqConnect.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 解绑QQ 6 | 7 | 8 | 9 |
10 |
11 |
12 |
13 |

解绑QQ

14 |
15 |

QQ已解绑,3秒后返回主页

16 |
17 |
18 |
19 |
20 |
21 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /cola-samples/cola-sample-sso/cola-sample-sso-server/src/main/resources/templates/connect/qqConnected.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | QQ绑定成功 6 | 7 | 8 | 9 |
10 |
11 |
12 |
13 |

绑定QQ成功

14 |
15 |

QQ已绑定,3秒后跳转到主页

16 |
17 |
18 |
19 |
20 |
21 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /cola-samples/cola-sample-sso/cola-sample-sso-server/src/main/resources/templates/connect/wechatConnect.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 绑定微信 6 | 7 | 8 | 9 |
10 |
11 |
12 |
13 |

绑定微信

14 |
15 |

微信已解绑,3秒后返回主页

16 |
17 |
18 |
19 |
20 |
21 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /cola-samples/cola-sample-sso/cola-sample-sso-server/src/main/resources/templates/connect/wechatConnected.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 微信绑定成功 6 | 7 | 8 | 9 |
10 |
11 |
12 |
13 |

绑定微信成功

14 |
15 |

微信已绑定,3秒后跳转到主页

16 |
17 |
18 |
19 |
20 |
21 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /cola-samples/cola-sample-sso/cola-sample-sso-server/src/main/resources/templates/error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 系统错误 6 | 7 | 8 | 9 |
10 |
11 |
12 |
13 |

Error

14 |
15 |

Timestamp:

16 |

Message:

17 |

Error:

18 |

Path:

19 |

Trace:

20 |
21 |
22 |
23 |
24 |
25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /cola-samples/cola-sample-sso/cola-sample-sso-server/src/main/resources/templates/static/css/style.css: -------------------------------------------------------------------------------- 1 | h1 { 2 | color: #78ab46; 3 | } 4 | 5 | footer { 6 | position: fixed; 7 | height: 50px; 8 | bottom: 0; 9 | width: 100%; 10 | background-color: #ccc 11 | } 12 | 13 | footer p { 14 | padding: 15px; 15 | } -------------------------------------------------------------------------------- /cola-samples/cola-sample-sso/cola-sample-sso-web/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-sample-sso 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-sample-sso-web 13 | 14 | 15 | 16 | com.honvay 17 | cola-auth-client-web 18 | 19 | 20 | org.springframework.boot 21 | spring-boot-starter-thymeleaf 22 | 23 | 24 | -------------------------------------------------------------------------------- /cola-samples/cola-sample-sso/cola-sample-sso-web/src/main/java/com/honvay/cola/sso/sample/web/SsoWebSampleApplication.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.sso.sample.web; 2 | 3 | import com.honvay.cola.auth.core.model.AuthenticatedUser; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.context.annotation.ComponentScan; 7 | import org.springframework.security.core.annotation.AuthenticationPrincipal; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | import org.springframework.web.servlet.ModelAndView; 11 | 12 | import java.util.Map; 13 | 14 | /** 15 | * @author LIQIU 16 | * created on 2018-11-26 17 | **/ 18 | @RestController 19 | @SpringBootApplication 20 | @ComponentScan("com.honvay") 21 | public class SsoWebSampleApplication { 22 | 23 | public static void main(String[] args) { 24 | SpringApplication.run(SsoWebSampleApplication.class, args); 25 | } 26 | 27 | @RequestMapping("/") 28 | public ModelAndView home(@AuthenticationPrincipal AuthenticatedUser authenticatedUser, Map map) { 29 | map.put("user", authenticatedUser.getUsername()); 30 | return new ModelAndView("index", map); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /cola-samples/cola-sample-sso/cola-sample-sso-web/src/main/java/com/honvay/cola/sso/sample/web/WebSecurityConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.sso.sample.web; 2 | 3 | import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 6 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 7 | import org.springframework.security.web.util.matcher.AntPathRequestMatcher; 8 | 9 | @Configuration 10 | @EnableOAuth2Sso 11 | public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter { 12 | 13 | @Override 14 | public void configure(HttpSecurity http) throws Exception { 15 | http 16 | .antMatcher("/**") 17 | .authorizeRequests() 18 | .antMatchers("/login**", "/webjars/**", "/error**") 19 | .permitAll() 20 | .anyRequest() 21 | .authenticated().and() 22 | .logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout")).logoutSuccessUrl("https://www.honvay.com/logout").permitAll(); 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /cola-samples/cola-sample-sso/cola-sample-sso-web/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8081 3 | security: 4 | oauth2: 5 | client: 6 | client-id: controller 7 | client-secret: user 8 | access-token-uri: https://www.honvay.com/oauth/token 9 | user-authorization-uri: https://www.honvay.com/oauth/authorize 10 | resource: 11 | user-info-uri: https://www.honvay.com/api/userinfo 12 | spring: 13 | thymeleaf: 14 | cache: false -------------------------------------------------------------------------------- /cola-samples/cola-sample-sso/cola-sample-sso-web/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 用户中心 8 | 9 | 10 | 11 |
12 |

应用

13 |
14 |
15 |    16 | 17 | 用户中心    注销 18 | 19 |
20 |
21 |
22 | 23 | 24 | -------------------------------------------------------------------------------- /cola-samples/cola-sample-sso/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-samples 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-sample-sso 13 | pom 14 | 15 | cola-sample-sso-server 16 | cola-sample-sso-web 17 | cola-sample-sso-app 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /cola-samples/cola-sample-web/src/main/java/com/honvay/cola/sample/web/SecurityConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.sample.web; 2 | 3 | import com.honvay.cola.auth.channel.config.ChannelSecurityConfigurer; 4 | import org.springframework.core.annotation.Order; 5 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 6 | import org.springframework.security.config.annotation.web.builders.WebSecurity; 7 | import org.springframework.stereotype.Component; 8 | 9 | /** 10 | * @author LIQIU 11 | * created on 2018/12/26 12 | **/ 13 | @Component 14 | @Order(101) 15 | public class SecurityConfiguration implements ChannelSecurityConfigurer { 16 | 17 | @Override 18 | public void configure(WebSecurity web) { 19 | web.ignoring().antMatchers("/webjars/**", "/resources/**", "/favicon.ico"); 20 | } 21 | 22 | @Override 23 | public void configure(HttpSecurity httpSecurity) throws Exception { 24 | httpSecurity.authorizeRequests().antMatchers("/signin/**").permitAll(); 25 | } 26 | 27 | @Override 28 | public int getOrder() { 29 | return 2; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /cola-samples/cola-sample-web/src/main/java/com/honvay/cola/sample/web/WebSampleApplication.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.sample.web; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.domain.EntityScan; 6 | import org.springframework.context.annotation.ComponentScan; 7 | import org.springframework.data.jpa.repository.config.EnableJpaRepositories; 8 | 9 | /** 10 | * @author LIQIU 11 | */ 12 | @EnableJpaRepositories("com.honvay") 13 | @EntityScan("com.honvay") 14 | @ComponentScan("com.honvay") 15 | @SpringBootApplication 16 | public class WebSampleApplication { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(WebSampleApplication.class, args); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /cola-samples/cola-sample-web/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | messages: 3 | basename: spring,org/springframework/security/messages 4 | thymeleaf: 5 | cache: false 6 | datasource: 7 | driver-class-name: com.mysql.jdbc.Driver 8 | url: jdbc:mysql://localhost:3306/cola-auth?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC 9 | username: root 10 | password: root 11 | initialization-mode: always 12 | jpa: 13 | hibernate: 14 | ddl-auto: none 15 | sms: 16 | login-process-url: /loginBySms 17 | server: 18 | error: 19 | include-stacktrace: always 20 | cola: 21 | sms: 22 | type: aliyun 23 | aliyun: 24 | accessKeyId: 123 25 | accessKeySecret: 1231 26 | logging: 27 | level: 28 | org.springframework.web: debug 29 | -------------------------------------------------------------------------------- /cola-samples/cola-sample-web/src/main/resources/templates/error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 系统错误 6 | 7 | 8 | 9 |
10 |
11 |
12 |
13 |

Error

14 |
15 |

Timestamp:

16 |

Message:

17 |

Error:

18 |

Path:

19 |

Trace:

20 |
21 |
22 |
23 |
24 |
25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /cola-samples/cola-sample-web/src/main/resources/templates/static/css/style.css: -------------------------------------------------------------------------------- 1 | h1 { 2 | color: #78ab46; 3 | } 4 | 5 | footer { 6 | position: fixed; 7 | height: 50px; 8 | bottom: 0; 9 | width: 100%; 10 | background-color: #ccc 11 | } 12 | 13 | footer p { 14 | padding: 15px; 15 | } -------------------------------------------------------------------------------- /cola-samples/cola-samples-social/src/main/java/com/honvay/cola/sample/social/SecurityConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.sample.social; 2 | 3 | import com.honvay.cola.auth.channel.config.ChannelSecurityConfigurer; 4 | import org.springframework.core.annotation.Order; 5 | import org.springframework.security.config.annotation.web.builders.WebSecurity; 6 | import org.springframework.stereotype.Component; 7 | 8 | /** 9 | * @author LIQIU 10 | * created on 2018/12/26 11 | **/ 12 | @Component 13 | @Order(101) 14 | public class SecurityConfiguration implements ChannelSecurityConfigurer { 15 | 16 | @Override 17 | public void configure(WebSecurity web) { 18 | web.ignoring().antMatchers("/webjars/**", "/resources/**", "/favicon.ico"); 19 | } 20 | 21 | @Override 22 | public int getOrder() { 23 | return 2; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /cola-samples/cola-samples-social/src/main/java/com/honvay/cola/sample/social/SocialSampleApplication.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.sample.social; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.domain.EntityScan; 6 | import org.springframework.context.annotation.ComponentScan; 7 | import org.springframework.data.jpa.repository.config.EnableJpaRepositories; 8 | 9 | /** 10 | * @author LIQIU 11 | */ 12 | @EnableJpaRepositories("com.honvay") 13 | @EntityScan("com.honvay") 14 | @ComponentScan("com.honvay") 15 | @SpringBootApplication 16 | public class SocialSampleApplication { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(SocialSampleApplication.class, args); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /cola-samples/cola-samples-social/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | messages: 3 | basename: spring,org/springframework/security/messages 4 | thymeleaf: 5 | cache: false 6 | datasource: 7 | driver-class-name: com.mysql.jdbc.Driver 8 | url: jdbc:mysql://localhost:3306/cola-auth?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC 9 | username: root 10 | password: root 11 | initialization-mode: always 12 | jpa: 13 | hibernate: 14 | ddl-auto: none 15 | social: 16 | login-process-url: /social 17 | signup-process-url: /social/signup 18 | signup-url: https://www.honvay.com/social/signup #需要指向本地,自行配置 19 | qq: 20 | app-id: id 21 | app-secret: secret 22 | wechat: 23 | app-id: id 24 | app-secret: secret 25 | wechatmp: 26 | app-id: id 27 | app-secret: secret 28 | alipay: 29 | app-id: id 30 | app-secret: secret 31 | signType: RSA 32 | private-key: pk 33 | public-key: pk 34 | sms: 35 | login-process-url: /loginBySms 36 | security: 37 | oauth2: 38 | resource: 39 | id: auth-controller 40 | server: 41 | error: 42 | include-stacktrace: always 43 | port: 8081 44 | cola: 45 | sms: 46 | type: aliyun 47 | aliyun: 48 | accessKeyId: 123 49 | accessKeySecret : 1231 50 | logging: 51 | level: 52 | org.springframework.web: debug 53 | -------------------------------------------------------------------------------- /cola-samples/cola-samples-social/src/main/resources/templates/connect/alipayConnect.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 解绑支付宝 6 | 7 | 8 | 9 |
10 |
11 |
12 |
13 |

解绑支付宝

14 |
15 |

支付宝已解绑,3秒后返回主页

16 | 21 |
22 |
23 |

绑定支付宝发生错误:

24 |

返回主页

25 |
26 |
27 |
28 |
29 |
30 | 31 | 32 | -------------------------------------------------------------------------------- /cola-samples/cola-samples-social/src/main/resources/templates/connect/alipayConnected.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 支付宝绑定成功 6 | 7 | 8 | 9 |
10 |
11 |
12 |
13 |

绑定支付宝成功

14 |
15 |

支付宝已绑定,3秒后跳转到主页

16 |
17 |
18 |
19 |
20 |
21 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /cola-samples/cola-samples-social/src/main/resources/templates/connect/qqConnect.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 解绑QQ 6 | 7 | 8 | 9 |
10 |
11 |
12 |
13 |

解绑QQ

14 |
15 |

QQ已解绑,3秒后返回主页

16 |
17 |
18 |
19 |
20 |
21 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /cola-samples/cola-samples-social/src/main/resources/templates/connect/qqConnected.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | QQ绑定成功 6 | 7 | 8 | 9 |
10 |
11 |
12 |
13 |

绑定QQ成功

14 |
15 |

QQ已绑定,3秒后跳转到主页

16 |
17 |
18 |
19 |
20 |
21 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /cola-samples/cola-samples-social/src/main/resources/templates/connect/wechatConnect.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 绑定微信 6 | 7 | 8 | 9 |
10 |
11 |
12 |
13 |

绑定微信

14 |
15 |

微信已解绑,3秒后返回主页

16 |
17 |
18 |
19 |
20 |
21 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /cola-samples/cola-samples-social/src/main/resources/templates/connect/wechatConnected.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 微信绑定成功 6 | 7 | 8 | 9 |
10 |
11 |
12 |
13 |

绑定微信成功

14 |
15 |

微信已绑定,3秒后跳转到主页

16 |
17 |
18 |
19 |
20 |
21 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /cola-samples/cola-samples-social/src/main/resources/templates/error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 系统错误 6 | 7 | 8 | 9 |
10 |
11 |
12 |
13 |

Error

14 |
15 |

Timestamp:

16 |

Message:

17 |

Error:

18 |

Path:

19 |

Trace:

20 |
21 |
22 |
23 |
24 |
25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /cola-samples/cola-samples-social/src/main/resources/templates/static/css/style.css: -------------------------------------------------------------------------------- 1 | h1 { 2 | color: #78ab46; 3 | } 4 | 5 | footer { 6 | position: fixed; 7 | height: 50px; 8 | bottom: 0; 9 | width: 100%; 10 | background-color: #ccc 11 | } 12 | 13 | footer p { 14 | padding: 15px; 15 | } -------------------------------------------------------------------------------- /cola-samples/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-samples 13 | pom 14 | 15 | cola-sample-oauth2 16 | cola-sample-web 17 | cola-sample-sso 18 | cola-sample-jwt 19 | cola-samples-social 20 | 21 | -------------------------------------------------------------------------------- /cola-security/cola-security-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-security 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-security-api 13 | 14 | 15 | 16 | org.projectlombok 17 | lombok 18 | 19 | 20 | com.honvay 21 | cola-framework-core 22 | 23 | 24 | com.honvay 25 | cola-notify-api 26 | 27 | 28 | javax.validation 29 | validation-api 30 | 31 | 32 | -------------------------------------------------------------------------------- /cola-security/cola-security-api/src/main/java/com/honvay/cola/sc/api/CredentialService.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.sc.api; 2 | 3 | import com.honvay.cola.sc.api.model.CredentialConfig; 4 | import com.honvay.cola.sc.api.model.CredentialNotify; 5 | import com.honvay.cola.sc.api.model.CredentialValidation; 6 | 7 | import javax.validation.Valid; 8 | 9 | /** 10 | * @author LIQIU 11 | * created on 2018/12/25 12 | **/ 13 | @Valid 14 | public interface CredentialService { 15 | 16 | /** 17 | * 生成凭证 18 | * 19 | * @param request 请求 20 | * @return 凭证Token 21 | */ 22 | String generate(@Valid CredentialConfig request); 23 | 24 | /** 25 | * 验证凭证 26 | * 27 | * @param request 请求 28 | * @return 是否匹配 29 | */ 30 | boolean validate(@Valid CredentialValidation request); 31 | 32 | /** 33 | * 将凭证通知到用户 34 | * 35 | * @param request 通知请求 36 | */ 37 | void notify(CredentialNotify request); 38 | 39 | /** 40 | * 获取凭证内容 41 | * 42 | * @param application 应用 43 | * @param principal 主体 44 | * @param token 凭证令牌 45 | * @return 凭证 46 | */ 47 | String getCredential(@Valid String application, String principal, String token); 48 | } 49 | -------------------------------------------------------------------------------- /cola-security/cola-security-api/src/main/java/com/honvay/cola/sc/api/PasswordStrategy.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.sc.api; 2 | 3 | 4 | /** 5 | * @author LIQIU 6 | * created on 2018/12/29 7 | **/ 8 | public interface PasswordStrategy { 9 | 10 | 11 | /** 12 | * 检查密码强度 13 | * 14 | * @param password 密码 15 | */ 16 | void check(String password); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /cola-security/cola-security-api/src/main/java/com/honvay/cola/sc/api/enums/SecurityErrorEnum.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.sc.api.enums; 2 | 3 | import com.honvay.cola.framework.core.ErrorMessage; 4 | 5 | /** 6 | * @author LIQIU 7 | * created on 2018/12/25 8 | **/ 9 | public enum SecurityErrorEnum implements ErrorMessage { 10 | ; 11 | private String code; 12 | private String message; 13 | 14 | SecurityErrorEnum(String code, String message) { 15 | this.code = code; 16 | this.message = message; 17 | } 18 | 19 | @Override 20 | public String getCode() { 21 | return code; 22 | } 23 | 24 | @Override 25 | public String getMessage() { 26 | return message; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /cola-security/cola-security-api/src/main/java/com/honvay/cola/sc/api/exception/PasswordInvalidException.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.sc.api.exception; 2 | 3 | /** 4 | * @author LIQIU 5 | * created on 2018/12/29 6 | **/ 7 | public class PasswordInvalidException extends RuntimeException { 8 | } 9 | -------------------------------------------------------------------------------- /cola-security/cola-security-api/src/main/java/com/honvay/cola/sc/api/model/CredentialConfig.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.sc.api.model; 2 | 3 | import com.honvay.cola.nc.api.model.Notification; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import javax.validation.constraints.Max; 10 | import javax.validation.constraints.Min; 11 | import javax.validation.constraints.NotEmpty; 12 | import javax.validation.constraints.NotNull; 13 | import java.io.Serializable; 14 | 15 | /** 16 | * @author LIQIU 17 | * @date 2018-7-10 18 | **/ 19 | @Data 20 | @Builder 21 | @NoArgsConstructor 22 | @AllArgsConstructor 23 | public class CredentialConfig implements Serializable { 24 | 25 | /** 26 | * 凭证大小 27 | */ 28 | @Min(value = 4, message = "凭证长度最小长度不能小于4位") 29 | @Min(value = 50, message = "凭证长度最大长度不能大于50位") 30 | @NotNull(message = "凭证长度不能为空") 31 | private Integer size; 32 | 33 | /** 34 | * 应用 35 | */ 36 | @NotEmpty(message = "主体不能为空") 37 | private String application; 38 | 39 | /** 40 | * 凭证类型 41 | */ 42 | @NotNull(message = "凭证类型不能为空") 43 | private CredentialType type; 44 | 45 | /** 46 | * 主体 47 | */ 48 | @NotEmpty(message = "主体不能为空") 49 | private String principal; 50 | 51 | /** 52 | * 过期时间 53 | */ 54 | @Min(value = 1000 * 15, message = "凭证最少失效时间为15秒") 55 | @Max(value = 1000 * 60 * 60, message = "凭证最大时间薇1小时") 56 | private Long expire; 57 | 58 | /** 59 | * 通知 60 | */ 61 | private Notification notification; 62 | 63 | } 64 | -------------------------------------------------------------------------------- /cola-security/cola-security-api/src/main/java/com/honvay/cola/sc/api/model/CredentialNotify.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.sc.api.model; 2 | 3 | import com.honvay.cola.nc.api.model.Notification; 4 | import lombok.Data; 5 | 6 | /** 7 | * @author LIQIU 8 | * created on 2018/12/25 9 | **/ 10 | @Data 11 | public class CredentialNotify { 12 | 13 | /** 14 | * 凭证令牌 15 | */ 16 | private String token; 17 | 18 | /** 19 | * 应用 20 | */ 21 | private String application; 22 | 23 | /** 24 | * 主体 25 | */ 26 | private String principal; 27 | 28 | /** 29 | * 通知 30 | */ 31 | private Notification notification; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /cola-security/cola-security-api/src/main/java/com/honvay/cola/sc/api/model/CredentialType.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.sc.api.model; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * @author LIQIU 7 | * @date 2018-7-10 8 | **/ 9 | public enum CredentialType implements Serializable { 10 | 11 | /** 12 | * 全数字验证码 13 | */ 14 | NUMBER, 15 | 16 | /** 17 | * 数字英文随机验证码 18 | */ 19 | NORMAL; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /cola-security/cola-security-api/src/main/java/com/honvay/cola/sc/api/model/CredentialValidation.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.sc.api.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import javax.validation.constraints.Max; 9 | import javax.validation.constraints.Min; 10 | import javax.validation.constraints.NotEmpty; 11 | import java.io.Serializable; 12 | 13 | /** 14 | * @author LIQIU 15 | * @date 2018-7-10 16 | **/ 17 | @Data 18 | @Builder 19 | @NoArgsConstructor 20 | @AllArgsConstructor 21 | public class CredentialValidation implements Serializable { 22 | 23 | /** 24 | * 凭证主体 25 | */ 26 | @NotEmpty(message = "主体不能为空") 27 | private String principal; 28 | 29 | /** 30 | * 应用 31 | */ 32 | @NotEmpty(message = "应用不能为空") 33 | private String application; 34 | 35 | /** 36 | * 凭证令牌 37 | */ 38 | @NotEmpty(message = "令牌不能为空") 39 | private String token; 40 | 41 | /** 42 | * 凭证 43 | */ 44 | @NotEmpty(message = "凭证不能为空") 45 | private String credential; 46 | 47 | /** 48 | * 是否忽略大小写 49 | */ 50 | private Boolean ignoreCase; 51 | 52 | } 53 | -------------------------------------------------------------------------------- /cola-security/cola-security-provider/src/main/java/com/honvay/cola/sc/provider/SecurityCenterAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.sc.provider; 2 | 3 | import com.honvay.cola.sc.api.PasswordStrategy; 4 | import com.honvay.cola.sc.provider.credential.CredentialProperties; 5 | import com.honvay.cola.sc.provider.password.DefaultPasswordStrategy; 6 | import com.honvay.cola.sc.provider.password.PasswordProperties; 7 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; 8 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 9 | import org.springframework.context.annotation.Configuration; 10 | 11 | /** 12 | * @author LIQIU 13 | * created on 2018/12/26 14 | **/ 15 | @Configuration 16 | @EnableConfigurationProperties({CredentialProperties.class, PasswordProperties.class}) 17 | public class SecurityCenterAutoConfiguration { 18 | 19 | @ConditionalOnBean(PasswordStrategy.class) 20 | public PasswordStrategy passwordStrategy(PasswordProperties properties){ 21 | return new DefaultPasswordStrategy(properties); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /cola-security/cola-security-provider/src/main/java/com/honvay/cola/sc/provider/credential/CredentialProperties.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.sc.provider.credential; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | 6 | import java.time.Duration; 7 | 8 | /** 9 | * @author LIQIU 10 | * created on 2018/12/25 11 | **/ 12 | @Data 13 | @ConfigurationProperties(prefix = "cola.security.credential") 14 | public class CredentialProperties { 15 | 16 | private Duration notifyInterval = Duration.ofMinutes(1L); 17 | 18 | private String credentialPlaceholder = "credential"; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /cola-security/cola-security-provider/src/main/java/com/honvay/cola/sc/provider/password/InvalidPasswordException.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.sc.provider.password; 2 | 3 | /** 4 | * @author LIQIU 5 | * created on 2019/1/24 6 | **/ 7 | public class InvalidPasswordException extends RuntimeException { 8 | 9 | public InvalidPasswordException(String message) { 10 | super(message); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /cola-security/cola-security-provider/src/main/java/com/honvay/cola/sc/provider/password/PasswordProperties.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.sc.provider.password; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | 6 | /** 7 | * @author LIQIU 8 | * created on 2018/12/29 9 | **/ 10 | @Data 11 | @ConfigurationProperties(prefix = "cola.security.password") 12 | public class PasswordProperties { 13 | 14 | /** 15 | * 最长长度 16 | */ 17 | private Integer maxLength = 100; 18 | 19 | /** 20 | * 最小长度 21 | */ 22 | private Integer minLength = 6; 23 | 24 | /** 25 | * 强度 26 | */ 27 | private PasswordStrength strength = PasswordStrength.NORMAL; 28 | } 29 | -------------------------------------------------------------------------------- /cola-security/cola-security-provider/src/main/java/com/honvay/cola/sc/provider/password/PasswordStrength.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.sc.provider.password; 2 | 3 | /** 4 | * @author LIQIU 5 | * created on 2018/12/29 6 | **/ 7 | public enum PasswordStrength { 8 | 9 | /** 10 | * 任意密码 11 | */ 12 | WEAK, 13 | /** 14 | * 数字加字母 15 | */ 16 | LOW, 17 | /** 18 | * 数字加大小写字母 19 | */ 20 | NORMAL, 21 | /** 22 | * 数字加大小写字母加特殊字符 23 | */ 24 | HIGH; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /cola-security/cola-security-provider/src/main/resources/messages-zh_CN.properties: -------------------------------------------------------------------------------- 1 | PasswordIsNull=密码为空 2 | PasswordIsTooShort=密码长度不足 3 | PasswordIsTooLong=密码长度太长 4 | PasswordStrenghtTooLow=密码强度不足 -------------------------------------------------------------------------------- /cola-security/cola-security-provider/src/test/java/com/honvay/cola/sc/provider/CredentialServiceImplTest.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.sc.provider; 2 | 3 | import com.honvay.cola.sc.api.CredentialService; 4 | import com.honvay.cola.sc.api.model.CredentialConfig; 5 | import com.honvay.cola.sc.api.model.CredentialType; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.junit.Assert; 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | import org.springframework.test.context.junit4.SpringRunner; 13 | 14 | import java.time.Duration; 15 | 16 | /** 17 | * @author LIQIU 18 | * created on 2018/12/28 19 | **/ 20 | @Slf4j 21 | @RunWith(SpringRunner.class) 22 | @SpringBootTest(classes = TestContext.class) 23 | public class CredentialServiceImplTest { 24 | 25 | 26 | @Autowired 27 | private CredentialService credentialService; 28 | 29 | @Test 30 | public void generate() { 31 | CredentialConfig config = CredentialConfig.builder() 32 | .principal("123") 33 | .size(6) 34 | .type(CredentialType.NUMBER) 35 | .expire(Duration.ofMinutes(5L).toMillis()) 36 | .application("sign_up").build(); 37 | String token = credentialService.generate(config); 38 | log.info("Generated token : " + token); 39 | 40 | String token2 = credentialService.generate(config); 41 | Assert.assertEquals(token, token2); 42 | } 43 | } -------------------------------------------------------------------------------- /cola-security/cola-security-provider/src/test/java/com/honvay/cola/sc/provider/TestContext.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.sc.provider; 2 | 3 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 4 | import org.springframework.context.annotation.ComponentScan; 5 | 6 | /** 7 | * @author LIQIU 8 | * created on 2018/12/28 9 | **/ 10 | @EnableAutoConfiguration 11 | @ComponentScan("com.honvay") 12 | public class TestContext { 13 | } 14 | -------------------------------------------------------------------------------- /cola-security/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-security 13 | pom 14 | 15 | cola-security-api 16 | cola-security-provider 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /cola-user/cola-user-admin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-user 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-user-admin 13 | 14 | 15 | 16 | com.honvay 17 | cola-user-provider 18 | 19 | 20 | org.springframework.boot 21 | spring-boot-starter-web 22 | 23 | 24 | -------------------------------------------------------------------------------- /cola-user/cola-user-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-user 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-user-api 13 | 14 | 15 | 16 | com.honvay 17 | cola-framework-core 18 | 19 | 20 | javax.validation 21 | validation-api 22 | 23 | 24 | io.swagger 25 | swagger-annotations 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /cola-user/cola-user-api/src/main/java/com/honvay/cola/uc/api/enums/UserErrorMessage.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.uc.api.enums; 2 | 3 | 4 | import com.honvay.cola.framework.core.ErrorMessage; 5 | 6 | /** 7 | * @author LIQIU 8 | * created on 2018/12/25 9 | **/ 10 | public enum UserErrorMessage implements ErrorMessage { 11 | 12 | /** 13 | * 用户不能存在 14 | */ 15 | USER_NOT_EXISTS("UC000001", "用户不存在"), 16 | /** 17 | * 邮箱已存在 18 | */ 19 | USER_EMAIL_EXISTS("UC000002", "邮箱已注册"), 20 | 21 | /** 22 | * 用户名已注册 23 | */ 24 | USER_NAME_EXISTS("UC000003", "用户名已注册"), 25 | 26 | /** 27 | * 手机号已存在 28 | */ 29 | USER_PHONE_NUMBER_EXISTS("UC000004", "手机号已存在"), 30 | /** 31 | * 用户状态错误 32 | */ 33 | USER_STATUS_ILLEGAL("UC000005", "用户状态错误"), 34 | /** 35 | * 原始密码错误 36 | */ 37 | ORIGIN_PASSWORD_NOT_MATCHED("UC000006", "原始密码错误"), 38 | 39 | /** 40 | * 确认密码不匹配 41 | */ 42 | CONFIRM_PASSWORD_NOT_MATCHED("UC000007", "确认密码不匹配"), 43 | 44 | PHONE_NUMBER_ILLEGAL("UC000008", "手机号码格式错误"), 45 | 46 | SMS_CREDENTIAL_NOT_MATCHED("UC000009", "短信验证码错误"), 47 | 48 | /** 49 | * 无效密码 50 | */ 51 | PASSWORD_INVALID("UC000010", "无效密码"); 52 | 53 | private String code; 54 | private String message; 55 | 56 | UserErrorMessage(String code, String message) { 57 | this.code = code; 58 | this.message = message; 59 | } 60 | 61 | @Override 62 | public String getCode() { 63 | return code; 64 | } 65 | 66 | @Override 67 | public String getMessage() { 68 | return message; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /cola-user/cola-user-api/src/main/java/com/honvay/cola/uc/api/enums/UserStatus.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.uc.api.enums; 2 | 3 | /** 4 | * 用户状态枚举 5 | * 6 | * @author LIQIU 7 | * created on 2018-11-16 8 | **/ 9 | public enum UserStatus { 10 | 11 | /** 12 | * 正常状态 13 | */ 14 | ACTIVE("正常", 1), 15 | /** 16 | * 锁定状态 17 | */ 18 | LOCKED("锁定", 2), 19 | /** 20 | * 失效状态 21 | */ 22 | DISABLED("失效", 3); 23 | 24 | UserStatus(String name, Integer value) { 25 | this.name = name; 26 | this.value = value; 27 | } 28 | 29 | /** 30 | * 状态名称 31 | */ 32 | private String name; 33 | 34 | /** 35 | * 状态值 36 | */ 37 | private Integer value; 38 | 39 | public String getName() { 40 | return name; 41 | } 42 | 43 | public void setName(String name) { 44 | this.name = name; 45 | } 46 | 47 | public Integer getValue() { 48 | return value; 49 | } 50 | 51 | public void setValue(Integer value) { 52 | this.value = value; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /cola-user/cola-user-api/src/main/java/com/honvay/cola/uc/api/model/UpdatePasswordDto.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.uc.api.model; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.Data; 6 | 7 | import javax.validation.constraints.NotEmpty; 8 | import javax.validation.constraints.Size; 9 | 10 | /** 11 | * @author LIQIU 12 | * created on 2018/12/25 13 | **/ 14 | @Data 15 | @ApiModel(description = "修改密码参数") 16 | public class UpdatePasswordDto { 17 | 18 | @ApiModelProperty(name = "用户ID", required = true) 19 | private Integer id; 20 | 21 | @NotEmpty(message = "原密码不能为空") 22 | @ApiModelProperty(name = "原密码", required = true) 23 | private String oldPassword; 24 | 25 | @NotEmpty(message = "新密码不能为空") 26 | @Size(min = 6, max = 50, message = "密码长度最少6位,最多50位") 27 | @ApiModelProperty(name = "新密码", required = true) 28 | private String newPassword; 29 | 30 | @NotEmpty(message = "确认密码能为空") 31 | @ApiModelProperty(name = "确认新密码", required = true) 32 | private String confirmNewPassword; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /cola-user/cola-user-api/src/main/java/com/honvay/cola/uc/api/model/UserAddDto.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.uc.api.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import javax.validation.constraints.NotNull; 9 | 10 | /** 11 | * @author LIQIU 12 | * created on 2019/1/14 13 | **/ 14 | @Data 15 | @Builder 16 | @AllArgsConstructor 17 | @NoArgsConstructor 18 | public class UserAddDto { 19 | 20 | /** 21 | * 用户名 22 | */ 23 | @NotNull 24 | private String username; 25 | 26 | /** 27 | * 密码 28 | */ 29 | @NotNull 30 | private String password; 31 | 32 | /** 33 | * 名称 34 | */ 35 | @NotNull 36 | private String name; 37 | 38 | /** 39 | * 邮箱 40 | */ 41 | private String email; 42 | 43 | /** 44 | * 手机号码 45 | */ 46 | private String phoneNumber; 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /cola-user/cola-user-api/src/main/java/com/honvay/cola/uc/api/model/UserDto.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.uc.api.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import javax.validation.constraints.NotNull; 9 | import javax.validation.constraints.Pattern; 10 | import java.util.Date; 11 | 12 | /** 13 | * @author LIQIU 14 | * created on 2018/12/24 15 | **/ 16 | @Data 17 | @Builder 18 | @AllArgsConstructor 19 | @NoArgsConstructor 20 | public class UserDto { 21 | 22 | /** 23 | * ID 24 | */ 25 | private Integer id; 26 | 27 | /** 28 | * 用户名 29 | */ 30 | @NotNull 31 | private String username; 32 | 33 | /** 34 | * 密码 35 | */ 36 | @NotNull 37 | private String password; 38 | 39 | /** 40 | * 名称 41 | */ 42 | @NotNull 43 | private String name; 44 | 45 | /** 46 | * 邮箱 47 | */ 48 | private String email; 49 | 50 | /** 51 | * 手机号码 52 | */ 53 | private String phoneNumber; 54 | 55 | /** 56 | * 头像 57 | */ 58 | private String avatar; 59 | 60 | /** 61 | * 最后登录时间 62 | */ 63 | private Date lastLoginDate; 64 | 65 | /** 66 | * 最后登录IP 67 | */ 68 | private String lastLoginIp; 69 | 70 | /** 71 | * 最后登录位置 72 | */ 73 | private String lastLoginLocation; 74 | 75 | /** 76 | * 登录失败次数 77 | */ 78 | private Integer loginFailTimes; 79 | 80 | /** 81 | * 状态: 1、正常 2、锁定 3、失效 82 | */ 83 | private Integer status; 84 | 85 | } 86 | -------------------------------------------------------------------------------- /cola-user/cola-user-api/src/main/java/com/honvay/cola/uc/api/model/UserUpdateDto.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.uc.api.model; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.Data; 6 | 7 | /** 8 | * @author LIQIU 9 | * created on 2018/12/25 10 | **/ 11 | @Data 12 | @ApiModel(description = "修改用户信息") 13 | public class UserUpdateDto { 14 | 15 | @ApiModelProperty(name = "姓名",required = true) 16 | private String name; 17 | 18 | @ApiModelProperty(name = "性别",required = true) 19 | private String gender; 20 | } 21 | -------------------------------------------------------------------------------- /cola-user/cola-user-provider/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola-user 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-user-provider 13 | 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-starter-data-jpa 18 | 19 | 20 | org.springframework.boot 21 | spring-boot-starter-validation 22 | 23 | 27 | 28 | com.honvay 29 | cola-user-api 30 | 31 | 32 | org.springframework.security 33 | spring-security-core 34 | 35 | 36 | com.honvay 37 | cola-security-api 38 | 39 | 40 | -------------------------------------------------------------------------------- /cola-user/cola-user-provider/src/main/java/com/honvay/cola/uc/provider/event/PasswordChangedEvent.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.uc.provider.event; 2 | 3 | import org.springframework.context.ApplicationEvent; 4 | 5 | /** 6 | * @author LIQIU 7 | * created on 2018/12/25 8 | **/ 9 | public class PasswordChangedEvent extends ApplicationEvent { 10 | /** 11 | * Create a new ApplicationEvent. 12 | * 13 | * @param source the object on which the event initially occurred (never {@code null}) 14 | */ 15 | public PasswordChangedEvent(Object source) { 16 | super(source); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /cola-user/cola-user-provider/src/main/java/com/honvay/cola/uc/provider/repository/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.uc.provider.repository; 2 | 3 | import com.honvay.cola.uc.provider.domain.User; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | import java.util.Optional; 7 | 8 | /** 9 | * @author LIQIU 10 | * created on 2018-11-16 11 | **/ 12 | public interface UserRepository extends JpaRepository { 13 | 14 | /** 15 | * 通过用户名查找用户 16 | * 17 | * @param username 用户名 18 | * @return 用户 19 | */ 20 | Optional findByUsername(String username); 21 | 22 | /** 23 | * 通过手机号查找用户 24 | * 25 | * @param phoneNumber 手机号码 26 | * @return 用户 27 | */ 28 | Optional findByPhoneNumber(String phoneNumber); 29 | 30 | /** 31 | * 通过邮箱地址查找用户 32 | * 33 | * @param email 邮箱地址 34 | * @return 用户 35 | */ 36 | Optional findByEmail(String email); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /cola-user/cola-user-web/src/main/java/com/honvay/cola/uc/web/model/PhoneNumberBindDto.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.uc.web.model; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.Data; 6 | 7 | import javax.validation.constraints.NotEmpty; 8 | 9 | /** 10 | * @author LIQIU 11 | * created on 2018/12/29 12 | **/ 13 | @Data 14 | @ApiModel("短信注册参数") 15 | public class PhoneNumberBindDto { 16 | 17 | /** 18 | * 手机号码 19 | */ 20 | @NotEmpty 21 | @ApiModelProperty(value = "手机号码", required = true) 22 | private String phoneNumber; 23 | 24 | /** 25 | * 短信令牌 26 | */ 27 | @NotEmpty 28 | @ApiModelProperty(value = "短信令牌", required = true) 29 | private String token; 30 | 31 | /** 32 | * 短信凭证 33 | */ 34 | @NotEmpty 35 | @ApiModelProperty(value = "短信凭证", required = true) 36 | private String credential; 37 | 38 | } 39 | -------------------------------------------------------------------------------- /cola-user/cola-user-web/src/main/java/com/honvay/cola/uc/web/model/SmsSignUpDto.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.uc.web.model; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.Data; 6 | 7 | import javax.validation.constraints.NotEmpty; 8 | 9 | /** 10 | * @author LIQIU 11 | * created on 2018/12/25 12 | **/ 13 | @Data 14 | @ApiModel("短信注册参数") 15 | public class SmsSignUpDto { 16 | 17 | /** 18 | * 手机号码 19 | */ 20 | @NotEmpty 21 | @ApiModelProperty(value = "手机号码", required = true) 22 | private String phoneNumber; 23 | 24 | /** 25 | * 短信令牌 26 | */ 27 | @NotEmpty 28 | @ApiModelProperty(value = "短信令牌", required = true) 29 | private String token; 30 | 31 | /** 32 | * 短信凭证 33 | */ 34 | @NotEmpty 35 | @ApiModelProperty(value = "短信凭证", required = true) 36 | private String credential; 37 | 38 | } 39 | -------------------------------------------------------------------------------- /cola-user/cola-user-web/src/main/java/com/honvay/cola/uc/web/model/UsernamePasswordSignUpDto.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.uc.web.model; 2 | 3 | import lombok.Data; 4 | 5 | import javax.validation.constraints.NotEmpty; 6 | import javax.validation.constraints.Pattern; 7 | import javax.validation.constraints.Size; 8 | 9 | /** 10 | * @author LIQIU 11 | * created on 2018/12/29 12 | **/ 13 | @Data 14 | public class UsernamePasswordSignUpDto { 15 | 16 | @NotEmpty(message = "确认密码不能为空") 17 | @Pattern(regexp = "^[A-Za-z0-9]+$", message = "用户名只允许为数字或英文字母") 18 | private String username; 19 | 20 | @NotEmpty 21 | @Size(max = 100, message = "名称最多包含50个字符") 22 | private String name; 23 | 24 | @NotEmpty(message = "密码不能为空") 25 | private String password; 26 | 27 | @NotEmpty(message = "确认密码不能为空") 28 | private String confirmPassword; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /cola-user/cola-user-web/src/test/java/com/honvay/cola/uc/web/controller/WebConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.honvay.cola.uc.web.controller; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.context.annotation.ComponentScan; 5 | 6 | /** 7 | * @author LIQIU 8 | * created on 2018/12/28 9 | **/ 10 | @SpringBootApplication 11 | @ComponentScan("com.honvay") 12 | public class WebConfiguration { 13 | } 14 | -------------------------------------------------------------------------------- /cola-user/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cola 7 | com.honvay 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cola-user 13 | pom 14 | 15 | cola-user-api 16 | cola-user-provider 17 | cola-user-web 18 | cola-user-admin 19 | 20 | 21 | 22 | 23 | org.projectlombok 24 | lombok 25 | 26 | 27 | -------------------------------------------------------------------------------- /sql/cola.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leecho/cola/c44e90ec989b7ddfe92714759c891c05e5541a69/sql/cola.sql --------------------------------------------------------------------------------