Dependencies have been added according to the instructions on REST Protocol on the official website.
public class CustomAuthentionHandler extends AbstractPreAndPostProcessingAuthenticationHandler {
@Autowired
private UserServiceImpl userService;
public CustomAuthentionHandler(String name, ServicesManager servicesManager, PrincipalFactory principalFactory, Integer order){
super(name,servicesManager,principalFactory,order);
}
@Override
protected HandlerResult doAuthentication(Credential credential) throws GeneralSecurityException, PreventedException {
System.out.println("\nCredential==="+credential.getClass().getName()+"\n");
UsernamePasswordCredential usernamePasswordCredential = (UsernamePasswordCredential) credential;
String username = usernamePasswordCredential.getUsername();
String password = usernamePasswordCredential.getPassword();
//
UserVo userVo = userService.getUserWithMultiAttrs(username, password);
System.out.println("userVo: "+userVo.toString());
if(userVo==null){
throw new AccountNotFoundException("");
}
//
Map<String, Object> map = new HashMap<>();
map.put("external\_userinfo", JSON.toJSONString(userVo));
return createHandlerResult(usernamePasswordCredential, principalFactory.createPrincipal(username, map), null);
}
@Override
public boolean supports(Credential credential) {
return credential instanceof UsernamePasswordCredential;
}
}