优化权限

This commit is contained in:
zhou-hao
2019-10-17 17:33:14 +08:00
parent 1e2ec16e6f
commit 9d206c0580
67 changed files with 1361 additions and 348 deletions

View File

@@ -0,0 +1,56 @@
package org.hswebframework.web.authorization.basic.web;
import org.hswebframework.web.authorization.*;
import org.hswebframework.web.authorization.simple.CompositeReactiveAuthenticationManager;
import org.hswebframework.web.authorization.simple.PlainTextUsernamePasswordAuthenticationRequest;
import org.hswebframework.web.authorization.simple.SimpleAuthentication;
import org.hswebframework.web.authorization.simple.SimpleUser;
import org.junit.Test;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import java.util.Arrays;
public class CompositeReactiveAuthenticationManagerTest {
@Test
public void test() {
CompositeReactiveAuthenticationManager manager = new CompositeReactiveAuthenticationManager(
Arrays.asList(
new ReactiveAuthenticationManagerProvider() {
@Override
public Mono<Authentication> authenticate(Mono<AuthenticationRequest> request) {
return Mono.error(new IllegalArgumentException("密码错误"));
}
@Override
public Mono<Authentication> getByUserId(String userId) {
return Mono.empty();
}
},
new ReactiveAuthenticationManagerProvider() {
@Override
public Mono<Authentication> authenticate(Mono<AuthenticationRequest> request) {
SimpleAuthentication authentication = new SimpleAuthentication();
authentication.setUser(SimpleUser.builder().id("test").build());
return Mono.just(authentication);
}
@Override
public Mono<Authentication> getByUserId(String userId) {
return Mono.empty();
}
}
)
);
manager.authenticate(Mono.just(new PlainTextUsernamePasswordAuthenticationRequest()))
.map(Authentication::getUser)
.map(User::getId)
.as(StepVerifier::create)
.expectNext("test")
.verifyComplete();
}
}