【SpringBoot】1 Gitee

本项目 Gitee 地址:https://gitee.com/Lin_DH/system
idea中可能装个gitee的插件,这样操作起来比较方便。
1)登录 Gitee 官网(https://gitee.com/),新建仓库。
在这里插入图片描述
2)复制新建的 Gitee 仓库地址:https://gitee.com/Lin_DH/system.git,在本地下载 Git 工具情况下,新建一个新的目录用于存放新项目,使用【git clone 仓库地址】命令拉取 Gitee 仓库上的项目,拉下来的项目只有一个 system 目录,目录中只有一个 .git 目录。
在这里插入图片描述
3)使用编译器 IDEA 打开 system 项目。
4)配置本地 Git 用户名和邮件地址。
在这里插入图片描述

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要在Spring Boot应用程序中实现Gitee登录,你需要执行以下步骤: 1. 创建一个Gitee应用程序并获取客户端ID和客户端密钥。可以在Gitee的开发者中心创建应用程序。 2. 添加Spring Security依赖项。 3. 在Security Configuration中配置OAuth2客户端。 下面是一个简单的配置示例: ```java @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/login/**") .permitAll() .anyRequest() .authenticated() .and() .oauth2Login() .loginPage("/login") .defaultSuccessURL("/") .failureUrl("/login?error=true") .and() .csrf() .disable(); } @Bean public ClientRegistrationRepository clientRegistrationRepository() { return new InMemoryClientRegistrationRepository(giteeClientRegistration()); } private ClientRegistration giteeClientRegistration() { return ClientRegistration.withRegistrationId("gitee") .clientId("your-client-id") .clientSecret("your-client-secret") .clientAuthenticationMethod(ClientAuthenticationMethod.POST) .authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE) .redirectUriTemplate("{baseUrl}/login/oauth2/code/{registrationId}") .scope("user_info") .authorizationUri("https://gitee.com/oauth/authorize") .tokenUri("https://gitee.com/oauth/token") .userInfoUri("https://gitee.com/api/v5/user") .userNameAttributeName(IdTokenClaimNames.SUB) .jwkSetUri("https://gitee.com/oauth/keys") .clientName("Gitee") .build(); } } ``` 在上面的代码中,我们使用Spring Security OAuth2客户端支持来配置Gitee登录。 在configure()方法中,我们通过.antMatchers()方法指定/login/**路径可公开访问,任何人都可以访问它。 我们还用.anyRequest().authenticated()确保所有其他请求都需要一个已经认证的用户。 在oauth2Login()方法中,我们设置了登录页面,成功的默认URL和错误URL。 最后,我们通过clientRegistrationRepository()方法将客户端注册添加到Spring Security中。 在giteeClientRegistration()方法中,我们使用ClientRegistration.withRegistrationId()方法创建一个新的客户端注册。我们设置客户端ID和密钥,并指定客户端认证方法。 我们还设置了授权类型,重定向URI模板,作用域,授权URI,令牌URI,用户信息URI,用户名属性名称,JWK集合URI和客户端名称。 为了使此配置生效,你需要在Spring Boot应用程序中提供以下属性: ``` spring.security.oauth2.client.registration.gitee.client-id=your-client-id spring.security.oauth2.client.registration.gitee.client-secret=your-client-secret ``` 这样,你就可以使用Gitee登录来保护你的Spring Boot应用程序了。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值