Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用Office 365身份验证配置spring安全性?_Java_Spring Mvc_Spring Security_Spring Security Oauth2 - Fatal编程技术网

Java 如何使用Office 365身份验证配置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"

我是新来的春天安全。我了解了有关身份验证管理器和其他内容的spring安全性的基础知识
我使用
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')”)
进行身份验证()