Search in sources :

Example 1 with JapUserException

use of com.fujieid.jap.core.exception.JapUserException 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);
}
Also used : AuthRequest(me.zhyd.oauth.request.AuthRequest) JapException(com.fujieid.jap.core.exception.JapException) AuthCallback(me.zhyd.oauth.model.AuthCallback) SocialConfig(com.fujieid.jap.social.SocialConfig) JapUserException(com.fujieid.jap.core.exception.JapUserException)

Aggregations

JapException (com.fujieid.jap.core.exception.JapException)1 JapUserException (com.fujieid.jap.core.exception.JapUserException)1 SocialConfig (com.fujieid.jap.social.SocialConfig)1 AuthCallback (me.zhyd.oauth.model.AuthCallback)1 AuthRequest (me.zhyd.oauth.request.AuthRequest)1