Tag: angularjs

Angularjs Post没有向Spring JWT发送头文件

我有一个由AngularJs构建的Web应用程序和一个由Spring构建的后端应用程序,我正在使用JWT来保护我的应用程序。 使用Get方法一切正常,在后端级别我获得了我期待的持有者令牌,因此我可以返回私人信息。 但是使用POST方法,不会发送承载令牌。 我不知道这是来自后端或前端层的问题。 在这里你有我的代码: AngularJS $http({ method: ‘POST’, url: SessionService.apiUrl + ‘/category/create’, headers: { ‘Accept’: ‘application/json’,’Content-Type’: ‘application/json; charset=UTF-8;’, ‘Authorization’: ‘Bearer ‘ + SessionService.getToken() }, data: params }) 对于GET方法,我有完全相同(没有参数和方法GET),它正在工作。 在后端: @RequestMapping(value = “/category/create”, method = RequestMethod.POST) public @ResponseBody Response add(@RequestBody CategoryBO request) { … } 要获取Authorization标头,我将以下列方式使用io.jsonwebtoken库: protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws […]

Access-Control-Allow-Origin是否足以防止XSRF攻击?

我们正在构建一个带有在JBoss中运行的Java Spring / Hibernate后端的应用程序。 前端是AngularJS。 我们还没有做任何事情来在服务器端设置XSRF令牌。 我们也不(无论如何)要求允许其他域访问我们的Web资源。 我想我会试着看看我们的网站是否容易受到XSRF攻击,所以我建立了一个恶意网络应用程序,使用Angular的$ http.post()发布到我们真正的应用程序url之一。 我登录到真正的应用程序,然后我尝试从恶意应用程序发布。 在浏览器中,我收到了401响应并看到了错误: XMLHttpRequest cannot load http://localhost:8080/user/delete. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:6543’ is therefore not allowed access. The response had HTTP status code 401. 服务器端未设置为在响应上设置Access-Control-Allow-Origin,因此出现上述错误。 所以我的问题是,只是从响应头中省略了Access-Control-Allow-Origin,足以防止XSRF攻击? 有没有办法我仍然可以在我的网站上进行XSRF攻击,即使没有设置Access-Control-Allow-Origin? 如果是这样的话? 我想演示这次攻击。 谢谢。

使用Selenium测试Angularjs应用程序

我正在测试角度js应用程序 链接Angular js App 当我点击Web应用程序上的UI工具包链接时,我收到以下错误 – at demoaj.Ajapp.main(Ajapp.java:16)引起:org.openqa.selenium.NoSuchElementException:无法找到元素:{“method”:“xpath”,“selector”:“html / body / div 1 / div 1 / aside / div / div / ul / li [2] / a“}命令持续时间或超时:51毫秒有关此错误的文档,请访问: http : //seleniumhq.org/exceptions/no_such_element.html 我是新手,我对这个AngularJS进行了一些研究 java代码 package demoaj; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; public class Ajapp { public static void main(String[] args) […]

如何将Cross Origin资源共享与Spring MVC 4.0.0 RESTful Webservice集成

我有一个简单的Web服务返回JSON数据。 用户类 ( com.bargadss.SpringService.Domain )是包含的POJO类 user_ID,firstName,lastName,eMail UserService类 ( com.bargadss.SpringService.DAO )有两个主要操作 getAllUser() – >查询数据库以从用户表中选择所有用户并返回列表{用户} getUserById(int user_ID) – >查询数据库以根据ID 选择特定用户 SpringServiceController ( com.bargadss.SpringService.Controller )如下: package com.bargadss.SpringService.Controller; import java.util.List; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import com.bargadss.SpringService.DAO.UserService; import com.bargadss.SpringService.Domain.User; @RestController @RequestMapping(“/service/user/”) public class SpringServiceController { UserService userService=new UserService(); @RequestMapping(value = “/{id}”, method = RequestMethod.GET,headers=”Accept=application/json”) public User […]

如何设置Grails和AngularJS部分模板

我正在实现一个项目,使用AngularJS作为前端 ,Grails作为后端。 Angular JS =>单页面应用程序 Grails => REST API将在WebApp本身和第三方应用程序中使用。 这就是我设置项目的方式: web-app | |_____ js ( angular controllers, modules, partial templates.) | |_____ images | |_____ css grails-app | |_____ views ( in here I have my main view, the one I use at the first user request ) 我不喜欢使用Resources Plugin,而是使用Grunt构建自己的前端,然后我只链接布局本身的最终文件。 我在web-app中构建了js文件夹,以包含一个partials文件夹,其中包含要在AngularJS中调用的所有部分模板 这是加载视图的非常标准的角度代码: angular.module(‘myapp’, []). config([‘$routeProvider’, […]

通过Javascript缓存与在Server中设置HTTPResponse头之间有什么区别?

在前端,我使用AngularJS“$ resource”作为GET请求,在后端我使用SpringMVC公开我的方法Restful方式。 现在我想只缓存一些我的GET请求。 我注意到有一些方法可以像使用$ cacheFactory一样。 或类似的东西: return { Things: $resource(‘url/to/:thing’, {}, { list : { method : ‘GET’, cache : true } }; 请注意,这也可能是一个带有一些缓存参数的简单ajax调用,而不是必须使用angularJS。 所以不是在客户端上使用这种方法,我不知道它可以在服务器上完成,只需通过Java在Response头中设置缓存,有些事情如下: response.setHeader(“Cache-Control: max-age=2592000”); 这两种方法有什么区别? 应该采用哪种方法? PS这个问题不是服务器端缓存与客户端缓存问题,我只需在服务器中设置HTTPResponse头即可。

带有spring MVC的JasperReport:在客户端打印报告而不显示它

我正在开发一个Spring MVC – Angularjs应用程序。 我需要打印报告,我选择了JasperReport来做到这一点。 在我继续之前,我想知道我是否可以生成报告,然后将其直接打印在客户端计算机上设置的默认打印机(可根据用户更改的打印机) 上 , 而不在屏幕上显示。 我一直在寻找这个特定需求的答案,但找不到任何答案。 如果有人知道它…. 生成报告并打印它的来源: HashMap params = new HashMap(); params.put(“Title”, “My Report”); InputStream reportStream = this.getClass().getResourceAsStream(TEMPLATE); JasperDesign jd = JRXmlLoader.load(reportStream); JasperReport jr = JasperCompileManager.compileReport(jd); JasperPrint jp = JasperFillManager.fillReport(jr, params, datasource.getDataSource()); JasperPrintManager.printReport(jp, false);

AngularJS与Apache Tiles

我在项目中使用Spring MVC和AngularJS。 可以使用AngularJs $ routing和ngView代替Apache Tiles框架或与Apache Tiles框架一起使用吗? 据我所知,使用$ routing和ngView,我们创建模板并在单页应用程序中重用它们。

在预检响应中,Access-Control-Allow-Methods不允许使用方法DELETE

我正在使用泽西作为我的restful api实现。 在前端,我使用angularjs $ http服务来发出http请求。 当我请求删除方法时,我总是得到以下错误。 “Method DELETE is not allowed by Access-Control-Allow-Methods in preflight response.” 我读了一些文章,他们说我需要允许删除“Access-Control-Allow-Methods”。 我已经设置了如下的响应filter,但它仍然存在这样的问题。 我还该怎么办? @Provider public class CORSResponseFilter implements ContainerResponseFilter { @Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { MultivaluedMap headers = responseContext.getHeaders(); headers.add(“Access-Control-Allow-Origin”, “*”); headers.add(“Access-Control-Allow-Methods”, “*”); } } 下面是我提出请求的角度代码: $http({ method: ‘DELETE’, url: remoteUrl, headers : {‘Content-Type’: […]

AngularJS和Webpack集成

我正在寻找一些帮助使用webpack的大型AngularJS应用程序。 我们正在使用基于function的文件夹结构(每个function/页面都有一个模块,它们有控制器,指令)。 我已成功配置webpack以使其与Grunt一起工作,Grunt生成一个单独的捆绑包。 我想创建一个块,因为它将成为一个大型应用程序,我们想异步加载模块(页面/function)工件。 我正在浏览一些webpack示例,使用require([deps],fn )语法来使用’code splitting’ 。 但是我无法让懒人装满块。 首先,我不知道究竟在哪里,我需要在AngularJS将用户路由到下一页之前导入这些块。 我正在努力寻找明确的责任分离。 是否有人向我指出一个示例AngularJS应用程序,其中webpack用于在每个路由后异步加载控制器/指令/filter? 我关注的链接很少: 我应该使用Browserify或Webpack来延迟加载1.x https://github.com/petehunt/webpack-howto#9-async-loading http://dontkry.com中 的依赖项 /posts/code/single-page-modules-with-webpack.html