Search in sources :

Example 1 with JapConfig

use of com.fujieid.jap.core.config.JapConfig in project OneBlog by zhangyd-c.

the class OAuthController method renderAuth.

@RequestMapping("/social/{source}")
public ModelAndView renderAuth(@PathVariable("source") String source, HttpServletResponse response, HttpServletRequest request) {
    SocialConfig socialConfig = sysSocialConfigService.getByPlatform(source);
    if (null == socialConfig) {
        throw new ZhydException(source + " 平台的配置尚未完成,暂时不支持登录!");
    }
    SocialStrategy socialStrategy = new SocialStrategy(japUserService, new JapConfig());
    JapResponse japResponse = socialStrategy.authenticate(JapUtil.blogSocialConfig2JapSocialConfig(socialConfig, source), request, response);
    if (!japResponse.isSuccess()) {
        throw new ZhydException(japResponse.getMessage());
    }
    if (japResponse.isRedirectUrl()) {
        return ResultUtil.redirect((String) japResponse.getData());
    } else {
        JapUser japUser = (JapUser) japResponse.getData();
        User user = (User) japUser.getAdditional();
        SessionUtil.setUser(user);
        return ResultUtil.redirect("/");
    }
}
Also used : ZhydException(com.zyd.blog.framework.exception.ZhydException) JapUser(com.fujieid.jap.core.JapUser) JapConfig(com.fujieid.jap.core.config.JapConfig) User(com.zyd.blog.business.entity.User) JapUser(com.fujieid.jap.core.JapUser) SocialStrategy(com.fujieid.jap.social.SocialStrategy) JapResponse(com.fujieid.jap.core.result.JapResponse) SocialConfig(com.zyd.blog.business.entity.SocialConfig) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with JapConfig

use of com.fujieid.jap.core.config.JapConfig in project ddd by EricFoxz.

the class Oauth2Controller method renderAuth.

@RequestMapping("/login/jai")
@SneakyThrows
public ModelAndView renderAuth(HttpServletRequest request, HttpServletResponse response) {
    Oauth2Strategy oauth2Strategy = new Oauth2Strategy(applicationOauth2Service, new JapConfig());
    OAuthConfig config = new OAuthConfig();
    config.setPlatform("jai").setState(IdUtil.fastSimpleUUID()).setClientId("xx").setClientSecret("xx").setCallbackUrl("http://sso.jap.com:8443/oauth2/login/jai").setAuthorizationUrl("xx").setTokenUrl("xx").setUserinfoUrl("xx").setScopes(new String[] { "read", "write" }).setResponseType(Oauth2ResponseType.CODE).setGrantType(Oauth2GrantType.AUTHORIZATION_CODE);
    JapResponse japResponse = oauth2Strategy.authenticate(config, new JakartaRequestAdapter(request), new JakartaResponseAdapter(response));
    if (!japResponse.isSuccess()) {
        return new ModelAndView(new RedirectView("/?error=" + URLUtil.encode(japResponse.getMessage())));
    }
    if (japResponse.isRedirectUrl()) {
        return new ModelAndView(new RedirectView((String) japResponse.getData()));
    } else {
        // 登录成功,需要对用户数据进行处理
        // ...
        System.out.println(japResponse.getData());
        return new ModelAndView(new RedirectView("/"));
    }
}
Also used : JapConfig(com.fujieid.jap.core.config.JapConfig) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) JakartaRequestAdapter(com.fujieid.jap.http.adapter.jakarta.JakartaRequestAdapter) Oauth2Strategy(com.fujieid.jap.oauth2.Oauth2Strategy) JapResponse(com.fujieid.jap.core.result.JapResponse) OAuthConfig(com.fujieid.jap.oauth2.OAuthConfig) JakartaResponseAdapter(com.fujieid.jap.http.adapter.jakarta.JakartaResponseAdapter) SneakyThrows(lombok.SneakyThrows) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

JapConfig (com.fujieid.jap.core.config.JapConfig)2 JapResponse (com.fujieid.jap.core.result.JapResponse)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 JapUser (com.fujieid.jap.core.JapUser)1 JakartaRequestAdapter (com.fujieid.jap.http.adapter.jakarta.JakartaRequestAdapter)1 JakartaResponseAdapter (com.fujieid.jap.http.adapter.jakarta.JakartaResponseAdapter)1 OAuthConfig (com.fujieid.jap.oauth2.OAuthConfig)1 Oauth2Strategy (com.fujieid.jap.oauth2.Oauth2Strategy)1 SocialStrategy (com.fujieid.jap.social.SocialStrategy)1 SocialConfig (com.zyd.blog.business.entity.SocialConfig)1 User (com.zyd.blog.business.entity.User)1 ZhydException (com.zyd.blog.framework.exception.ZhydException)1 SneakyThrows (lombok.SneakyThrows)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1 RedirectView (org.springframework.web.servlet.view.RedirectView)1