登录页面
<form class="form-signin" action="./login" method="post">
<h2 class="form-signin-heading">请 登 录</h2>
<input type="text" class="form-control" placeholder="账号" name="username"/>
<input type="password" class="form-control" placeholder="密码" name="password"/>
<button class="btn btn-lg btn-primary btn-block" type="submit">登录</button>
</form>
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Bean
public UserDetailsService userDetailsService() {
return new UserDetailServiceImpl();
}
@Bean
public BCryptPasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService());
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/oauth/**").permitAll() //此处不太对
.and()
.formLogin()
.loginPage("/login") ;
http .csrf().disable();
}
}
public class ClientDetailsConfig implements ClientDetailsService {
private Map<String, ClientDetails> clientDetailsStore = new HashMap<String, ClientDetails>();
/**
* @method
* @description 项目管理service
* @date: 2019-10-13 19:37
* @author: zhangzhenhua
* @Param: null
* @return
*/
@Autowired
private SysProjectService sysProjectService;
@Override
public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
QueryWrapper<SysProjectPO> queryWrapper = new QueryWrapper<SysProjectPO>();
queryWrapper.eq("code", clientId);
SysProjectPO projectModel = sysProjectService.getOne(queryWrapper);
if (projectModel == null) {
throw new ClientRegistrationException("该客户端不存在");
}
BaseClientDetails baseClientDetails = new BaseClientDetails(projectModel.getCode(),
projectModel.getCode(),
"all",
projectModel.getAuthorizedType(),
projectModel.getSecret(),
projectModel.getReturnUrl()
);
baseClientDetails.setAccessTokenValiditySeconds(20);
baseClientDetails.setRefreshTokenValiditySeconds(20);
return baseClientDetails;
}
}
我在详细说下:
第一步:http://localhost:9000/authorization/oauth/authorize?client_id=back&response_type=token 9000这个是网关服务,
routes:
- id: authorization
uri: lb://authorization-server
predicates:
- Path=/authorization/**
filters:
- StripPrefix=1
第二步:跳转到授权服务/login,正常登录成功之后应该调回 http://localhost:8300/oauth/authorize,点击授权然后跳转到项目returnurl,但是跳转不回去了。