Java 如何使用Office 365身份验证配置spring安全性?
我是新来的春天安全。我了解了有关身份验证管理器和其他内容的spring安全性的基础知识Java 如何使用Office 365身份验证配置spring安全性?,java,spring-mvc,spring-security,spring-security-oauth2,Java,Spring Mvc,Spring Security,Spring Security Oauth2,我是新来的春天安全。我了解了有关身份验证管理器和其他内容的spring安全性的基础知识 我使用angularjs作为前端,使用spring3.0.5作为后端 我想将基于角色授权的spring安全性添加到现有项目中 我还想使用office 365对用户进行身份验证。所以,我在中创建了应用程序,并将重定向URI作为本地主机操作 使用我的代码,我能够使用office 365进行身份验证,并能够在重定向操作中获取用户名 @RequestMapping(value="/getCodeAndProcess"
我使用
angularjs
作为前端,使用spring3.0.5
作为后端
我想将基于角色授权的spring安全性添加到现有项目中
我还想使用office 365对用户进行身份验证。所以,我在中创建了应用程序,并将重定向URI作为本地主机操作
使用我的代码,我能够使用office 365进行身份验证,并能够在重定向操作中获取用户名
@RequestMapping(value="/getCodeAndProcess", method=RequestMethod.POST)
private ModelAndView getCodeAndProcess(@RequestParam("code") String code, HttpServletRequest request) throws Exception {
HttpSession session = null;
try {
session = request.getSession(false);
session.setMaxInactiveInterval(45*60);
String username = helper.processCodeAndGetUsername(code); //this is I'm getting using office 365.
String userRole = helper.getUserRoleBasedOnUsername(username);
System.out.println("================userRole================="+userRole);
if(username != "") {
session.setAttribute("username", username);
session.setAttribute("userRole", userRole);
}else {
session.invalidate();
throw new Exception("username not found");
}
return new ModelAndView("redirect:/adminDashboard/showDashboard");
}catch(Exception e) {
log.error("Error while processing on users authentication.",e );
session.invalidate();
return new ModelAndView("redirect:/login/loginPage");
}
}
现在,我不知道如何在security context.xml
中配置用户名和角色,这样我就可以使用@PreAuthorize(“hasRole('ROLE\u USER')”)
,进行身份验证()