我已经尝试过使用microsoft azure AD为spring提供的演示,但这不起作用 thaht总是说这个错误: org.springframework.security.oauth2.client.resource.UserRedirectRequiredException:需要重定向才能获得用户批准或此批准 java.lang.IllegalArgumentException:[不是URI,因为没有客户端]不是有效的HTTP URL
你可以在这里看到代码:
@EnableOAuth2Sso
@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private AADAuthenticationFilter aadAuthFilter;
@Autowired
private OAuth2ClientContextFilter oauth2ClientContext;
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().permitAll().and().csrf().disable()
.addFilterBefore(aadAuthFilter, UsernamePasswordAuthenticationFilter.class)
.addFilterAfter(oauth2ClientContext, SecurityContextPersistenceFilter.class);
}
}
classe控制器:
@Controller
public class hellocontroler {
@PreAuthorize("hasRole('Employees')")
@RequestMapping("/")
public String hello() {
return "Hello World!";
}
课程演示:
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
poperty file:
# Specifies your Active Directory Application ID:
azure.activedirectory.clientId=xxxxxxxxxxxxxxxxxxxxx
# Specifies your secret key:
azure.activedirectory.clientSecret= xxxxxxxxxxxxxxxxxxxxxxx
# Specifies the list of Active Directory groups to use for authentication:
azure.activedirectory.activeDirectoryGroups=Employees