我正在使用Spring Security与SpringMVC创建一个Web应用程序(为了清楚起见,我将其称为WebApp),它与现有应用程序相对应(我将其称为BackendApp).
我想将身份验证职责委托给BackendApp(这样我就不需要同步这两个应用程序).
为了实现这一点,我希望WebApp(运行spring security)通过REST与用户在表单中提供的用户名和密码进行BackendApp通信,并根据BackendApp的响应是200 OK还是401 Unauthorized进行身份验证.
我知道我需要编写一个自定义的身份验证管理器来执行此操作,但我是一个很新的春天,无法找到有关如何实现它的任何信息.
我相信我需要做这样的事情:
public class CustomAuthenticationManager implements AuthenticationManager{
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
String username = authentication.getName();
String pw = authentication.getCredentials().toString();
// Code to make rest call here and check for OK or Unauthorised.
// What do I return?
}
}
Run Code Online (Sandbox Code Playgroud)
如果成功,我是否设置authentication.setAuthenticated(true),否则设置为false,那就是它?
编写完成后,如何配置spring security以使用java配置文件来使用此身份验证管理器?
在此先感谢您的任何帮助.
使用sails.js作为我正在构建的node.js应用程序的框架.
我正在尝试从后端检索用户先前设置的信息(即我的应用程序的设置),然后在我的客户端javascript中使用这些设置.
我目前有一个控制器,它从数据库中检索信息并将其传递到需要它的视图.
return res.view('dashboard', { configs: configurations });
Run Code Online (Sandbox Code Playgroud)
我知道在渲染html时可以访问它,但不知道如何将它传递给在浏览器上运行的javascript环境.
任何提示都会很棒!
为了澄清,我不是试图在html页面中呈现这些信息(即使用的方法<%= variable %>,我想在页面上运行的javascript中使用它.
我试图了解如何使用 rxcpp,我的印象是,当可观察者发出一个值时,所有订阅的观察者都会通过调用其 on_next() 方法来获得通知,并向他们传递发出的值。
以下示例的情况并非如此:
auto eventloop = rxcpp::observe_on_event_loop();
printf("Start task\n");
auto values = rxcpp::observable<>::interval(std::chrono::seconds(2)).map(
[](int i){
printf("Observable sending: %d\n", i);
return i;
}
);
values.
subscribe_on(eventloop).
take(2).
as_blocking().
subscribe(
[](int v){printf("#1 onNext: %d\n", v);},
[](){printf("#1 onCompleted\n");});
values.
subscribe_on(eventloop).
take(2).
as_blocking().
subscribe(
[](int v){printf("#2 onNext: %d\n", v);},
[](){printf("#2 onCompleted\n");});
printf("Finish task\n");
Run Code Online (Sandbox Code Playgroud)
我期望输出是这样的:
Start task
Observable sending: 1
#1 onNext: 1
#2 onNext: 1
Observable sending: 2
#1 onNext: 2
#1 onCompleted
#2 onNext: 2
#2 onCompleted
Finish task
Run Code Online (Sandbox Code Playgroud)
即当新值到来时,所有订阅的观察者都会调用 on_next …
c++ ×1
java ×1
javascript ×1
node.js ×1
reactivex ×1
rxcpp ×1
sails.js ×1
spring ×1
spring-mvc ×1