我正在为Spring Security实现一个自定义的AngularJS登录页面,而且我遇到了身份验证问题.
我正在关注本教程/示例,他们的示例在本地工作正常:https://github.com/dsyer/spring-security-angular/tree/master/single
但是,当我尝试自己实现这个时,我无法进行身份验证,而且我不确定我的错误在哪里.
使用凭证进行/登录POST(curl与示例相同),我收到302 Found,重定向到GET/login /,返回404 Not Found.
当我尝试POST到/ login时,Spring不生成任何调试日志,因此我不确定它是如何为302服务的.
我的代码可以在这里找到:https://github.com/AndrewBell/spring-angular-starter/tree/master
值得注意的变化(很可能是我的问题的根源):
文件结构更改
严格使用Angular(无jQuery) - 这导致发出POST请求所需的不同功能
使用凉亭而不是wro4j
角度代码样式/范围
许多相关的Spring Security问题表明POST请求的格式不正确,但我的示例与示例相同(至少当我在chrome dev控制台中复制到curl时).其他人建议实现自定义授权提供程序,但在示例中不需要它,因此我对我和示例之间的区别感到困惑.帮我堆栈交换,你是我唯一的希望.
开发工具:imgurDOTcom/a/B2KmV
相关代码:
login.js
'use strict';
angular
.module('webApp')
.controller('LoginCtrl', ['$root`enter code here`Scope', '$scope', '$http', '$location', '$route', function($rootScope, $scope, $http, $location, $route) {
console.log("LoginCtrl created.");
var vm = this;
vm.credentials = {
username: "",
password: ""
};
//vm.login = login;
$scope.tab = function(route) {
return $route.current && route === $route.current.controller;
};
var authenticate = …Run Code Online (Sandbox Code Playgroud)我正在资源上实现自定义响应标头,在阅读了类似的问题后,我在 CORS 标头中添加了一个“Access-Control-Expose-Headers”,但我不能正确配置某些内容。
以下是我在资源的 GET 请求中收到的标头:我收到“Steve”的“Response-Header”,“Access-Control-Expose-Headers”应该允许
Access-Control-Allow-Headers:x-requested-with, Request-Header, Response-Header
Access-Control-Allow-Methods:POST, GET, OPTIONS, DELETE
Access-Control-Allow-Origin:*
Access-Control-Expose-Headers:Response-Header
Response-Header:Steve
Run Code Online (Sandbox Code Playgroud)
但是,Angular 仍然无法访问该自定义标头。我找回了我的自定义请求头,但不是我的自定义响应头:
{
"data": {
"id": 2,
"content": "Hello, frank!"
},
"status": 200,
"config": {
"method": "GET",
"transformRequest": [
null
],
"transformResponse": [
null
],
"url": "http:\/\/localhost:8080\/greeting",
"headers": {
"Accept": "application\/json, text\/plain, *\/*",
"Request-Header": "frank"
}
},
"statusText": "OK"
}
Run Code Online (Sandbox Code Playgroud)
Angular 1.3 $httpProvider.interceptor:
'use strict';
angular
.module('headerDemoUiApp')
.factory('AuthInterceptor', function AuthInterceptor(nameService) {
return {
request: handleRequest,
response: handleResponse
};
function handleRequest(config) {
if …Run Code Online (Sandbox Code Playgroud) 我正在使用spring-boot-starter-data-mongodb构建一个简单的REST api,并且E11000 duplicate key error在尝试插入第二行时总是得到一个.
Spring的入门指南有一个非常简单的配置,我遵循,但我必须遗漏一些东西.
我已经删除了集合,并开始新鲜,第一个文档保存正常,但第二个文件也尝试保存为id = 0.如何让Spring/Mongo正确增加?
这是我得到的错误:
org.springframework.dao.DuplicateKeyException: { "serverUsed" : "localhost:27017" , "ok" : 1 , "n" : 0 , "err" : "E11000 duplicate key error index: test.game.$_id_ dup key: { : 0 }" , "code" : 11000}; nested exception is com.mongodb.MongoException$DuplicateKey: { "serverUsed" : "localhost:27017" , "ok" : 1 , "n" : 0 , "err" : "E11000 duplicate key error index: test.game.$_id_ dup key: { : 0 }" , "code" …Run Code Online (Sandbox Code Playgroud) 如果您在请求中使用camelCase参数,则使用Spring MVC将URL请求参数映射到对象是相当简单的,但是当使用连字符分隔值时,如何将这些参数映射到对象?
参考示例:
控制器:
@RestController
public class MyController {
@RequestMapping(value = "/search", method = RequestMethod.GET)
public ResponseEntity<String> search(RequestParams requestParams) {
return new ResponseEntity<>("my-val-1: " + requestParams.getMyVal1() + " my-val-2: " + requestParams.getMyVal2(), HttpStatus.OK);
}
}
Run Code Online (Sandbox Code Playgroud)
保持参数的对象:
public class RequestParams {
private String myVal1;
private String myVal2;
public RequestParams() {}
public String getMyVal1() {
return myVal1;
}
public void setMyVal1(String myVal1) {
this.myVal1 = myVal1;
}
public String getMyVal2() {
return myVal2;
}
public void setMyVal2(String myVal2) {
this.myVal2 = myVal2; …Run Code Online (Sandbox Code Playgroud) spring ×4
java ×3
angularjs ×2
cors ×1
mongodb ×1
spring-boot ×1
spring-mongo ×1
spring-mvc ×1