小编Lwa*_*ent的帖子

如何在windows azure上部署java应用程序

嗨,我是一名计算机科学专业的三年级学生,我已经在netbeans上创建了我的第三年java项目,现在我想将它部署到一个带有windows azure的虚拟机上.这样做的一点是,我希望能够为连接到互联网的任何计算机上使用该应用程序只需通过访问云和不用每次都(比如你可以怎么玩任何游戏蒸东西不必安装程序在任何电脑上).现在的问题是,是否有可能,如果是这样,我该如何做到这一点,提前谢谢

java cloud azure web-deployment azure-web-sites

3
推荐指数
1
解决办法
8952
查看次数

主体作为 UsernamePasswordAuthenticationToken 返回

我遇到了我认为可能是错误的情况。

我正在使用 Spring Boot 和 Spring Security。通常情况下,一切都运行良好,但是当我尝试通过控制器或直接从控制器获取主体时,由于某种奇怪的原因HttpServletRequest,它会被强制转换UsernamePasswordAuthenticationToken。当我使用SecurityContextHolder.getContext().getAuthentication().getPrincipal()它时,它返回正确的对象。

请参阅下面的代码,请参阅最后 6 行左右的注释以了解实际返回的内容。

@RequestMapping(method = RequestMethod.POST)
public ElementDto postElement(@RequestBody @Valid ElementDto element, BindingResult bindingResult, HttpServletRequest httpServletRequest, Principal principal) {
    logger.info("postElement - {}", element);
    if (bindingResult.hasErrors()) {
        throw new SpringBootCommonError(bindingResult.getAllErrors().get(0).getDefaultMessage(), SpringBootCommonErrorEnum.VALIDATION);
    }
    UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = (UsernamePasswordAuthenticationToken)principal; /*is of type UsernamePasswordAuthenticationToken*/
    Principal requestPrincipal = httpServletRequest.getUserPrincipal();/*is of type UsernamePasswordAuthenticationToken*/
    Principal principalFromCast = (Principal)usernamePasswordAuthenticationToken.getPrincipal();/*is of type User (what I want)*/
    Object securityPrincipal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();/*is of type (what I want)*/
    element.setUploadedBy(((User) httpServletRequest.getUserPrincipal()).getEntityNo()); …
Run Code Online (Sandbox Code Playgroud)

spring-security spring-boot

3
推荐指数
1
解决办法
8495
查看次数