我试图将Spring安全性与自定义角度2登录集成,这是我的应用程序的特定端点受弹簧安全保护,尝试访问它将重定向到/登录,在角度2处理.现在的情况我没有了解如何执行登录并在登录后授予对后端API的访问权限.
我正在配置弹簧安全性如下:
@Override
protected void configure(final HttpSecurity http) throws Exception {
http
.csrf().disable()
.cors().and()
.authorizeRequests()
.antMatchers("/api/someEndpoint/**")
.hasRole(ADMIN_ROLE).and().formLogin()
.loginPage("/login").and().logout();
}
@Override
protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder);
}
Run Code Online (Sandbox Code Playgroud)
因为我有默认登录一切正常,但我发现自己无法创建一个有效的角度2登录集成.我在角度2中尝试了以下代码无效:
login(loginDetails:Object) {
console.log(loginDetails)
const headers = new Headers({ 'Content-Type': 'application/json' });
const options = new RequestOptions({ headers: headers });
const body = JSON.stringify(loginDetails);
console.log(headers);
console.log(body);
return this.http.post(this.loginUrl, body, options)
}
Run Code Online (Sandbox Code Playgroud)
据我所知,用户名和密码变量名称的弹簧安全默认值是"用户名"和"密码",我肯定会在请求体中传递,所以当传递一些无效的用户数据时,{"username":"admin", "password" : "pass"}我应该重定向到/ login?错误或其他什么,并且成功通过身份验证后,我应该重定向到/ welcome并保持身份验证
我有我的数据库中定义的用户和传递,我的自定义userDetailsService检查它是否欢迎任何答案,评论或问题
rest restful-authentication spring-mvc spring-security angular
我想制作一个休息api控制器(弹簧启动),当用get获取请允许我下载excel文件.目前我有这个端点:
@RequestMapping(value = "/download.xls", method = RequestMethod.GET)
public ResponseEntity Survey_Reports(@RequestParam(value = "evaluated") String evaluated){
return surveyService.getSurveysFile(evaluated);
}
Run Code Online (Sandbox Code Playgroud)
最终要求这种方法:
public static ResponseEntity getDownloadResponse() {
File file2Upload = new File("Survey_Reports.xls");
Path path = Paths.get(file2Upload.getAbsolutePath());
ByteArrayResource resource = null;
try {
resource = new ByteArrayResource(Files.readAllBytes(path));
} catch (IOException e) {
logger.error("there was an error getting the file bytes ", e);
}
return ResponseEntity.ok()
.contentLength(file2Upload.length())
//this line doesnt seem to work as i set the file format in the controller request mapping
.contentType(MediaType.parseMediaType("application/vnd.ms-excel"))
.body(resource); …Run Code Online (Sandbox Code Playgroud) 如何为sysdate不同的东西设置日期列的默认值?像01/07/1998,我目前正在使用
ALTER TABLE XILIADO
ADD (FECHA_AFIL DATE DEFAULT sysdate NOT NULL);
Run Code Online (Sandbox Code Playgroud)