0
可以說,我配置了兩個API資源使用不同的網址:如何在Spring Oauth2中爲不同的URL配置不同的超時時間?
- /API /安全/ **
- /API /管理/ **
@Override
public void configure(HttpSecurity http) throws Exception {
http.exceptionHandling()
.authenticationEntryPoint(customAuthenticationEntryPoint)
.and()
.logout()
.logoutUrl("/oauth/logout")
.logoutSuccessHandler(customLogoutSuccessHandler)
.and()
.csrf()
.requireCsrfProtectionMatcher(new AntPathRequestMatcher("/oauth/authorize"))
.disable()
.headers()
.frameOptions()
.disable()
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers("/api/secure/**").hasAnyAuthority(Authorities.ROLE_USER.name(), Authorities.ROLE_ADMIN.name())
.antMatchers("/admin/**").hasAnyAuthority(Authorities.ROLE_ADMIN.name());
}
和我配置的超時:
- 的刷新令牌:每日1次;
- 用於訪問令牌:30分鐘;
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("client01")
.secret("pass")
.refreshTokenValiditySeconds(24 * 60 * 60)
.accessTokenValiditySeconds(30 * 60)
.scopes("read", "write")
.authorities(Authorities.ROLE_USER.name(), Authorities.ROLE_ADMIN.name(), Authorities.ROLE_SUPERADMIN.name())
.authorizedGrantTypes("password", "refresh_token");
}
我怎麼能做出/ API不同的超時/安全/ **(如上)和/ API /管理/ **(refreshToken:20分鐘,的accessToken:10秒)?