use of com.fujieid.jap.core.exception.JapException in project solon by noear.
the class FixedSocialStrategy method authenticate.
@Override
public JapResponse authenticate(AuthenticateConfig config, JapHttpRequest request, JapHttpResponse response) {
SocialConfig socialConfig = null;
try {
this.checkAuthenticateConfig(config, SocialConfig.class);
socialConfig = (SocialConfig) config;
} catch (JapException e) {
return JapResponse.error(e.getErrorCode(), e.getErrorMessage());
}
if (socialConfig.isBindUser()) {
return this.bind(config, request, response);
}
// !!! 取消 Session 校验 !!!
// JapUser sessionUser = this.checkSession(request, response);
// if (null != sessionUser) {
// return JapResponse.success(sessionUser);
// }
AuthRequest authRequest = null;
try {
authRequest = Reflect.on(this).call("getAuthRequest", config).get();
} catch (JapException e) {
return JapResponse.error(e.getErrorCode(), e.getErrorMessage());
}
String source = socialConfig.getPlatform();
AuthCallback authCallback = Reflect.on(this).call("parseRequest", request).get();
if (Reflect.on(this).call("isCallback", source, authCallback).get()) {
try {
return Reflect.on(this).call("login", request, response, source, authRequest, authCallback, (SocialFunc) this::loginSuccess).get();
} catch (JapUserException e) {
return JapResponse.error(e.getErrorCode(), e.getErrorMessage());
}
}
// If it is not a callback request, it must be a request to jump to the authorization link
String url = authRequest.authorize(socialConfig.getState());
return JapResponse.success(url);
}
Aggregations