use of com.fujieid.jap.core.result.JapResponse in project solon by noear.
the class SocialController method redirect.
/**
* 第三方跳转方法
*/
@Get
@Mapping("/social/{platform}")
public Object redirect(Context ctx, HttpServletRequest request, HttpServletResponse response, String platform, String next, String code, String state) throws IllegalAccessException {
// 验证 二次回调地址 是否合法
if (next == null) {
// 如果没指定回调地址,可能是第三方回调的结果
next = (String) this.cacheService.get(this.getKey(state));
// 如果 Callback 所属的 State 已过期
if (next == null) {
throw new IllegalStateException();
} else {
// 填入缺失的 next 参数
ctx.paramSet("next", next);
}
} else {
if (!this.validNext(next)) {
throw new IllegalAccessException();
}
}
// 构建 社会化登录 Payload
SocialConfig socialConfig = new SocialConfig().setPlatform(platform).setState(UuidUtils.getUUID()).setJustAuthConfig(this.japProperties.getCredentials().get(platform));
// 将 State -> Callback 存入缓存
this.cacheService.store(this.getKey(socialConfig.getState()), next, 300);
// 请求登录
JapResponse japResponse = this.socialStrategy.authenticate(socialConfig, new JakartaRequestAdapter(new HttpServletRequestWrapperImpl(ctx, request)), new JakartaResponseAdapter(response));
return this.simpleResponse(ctx, japResponse);
}
use of com.fujieid.jap.core.result.JapResponse 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("/");
}
}
use of com.fujieid.jap.core.result.JapResponse in project solon by noear.
the class SimpleController method login.
@Post
@Mapping("/login")
public Object login(Context ctx, HttpServletRequest request, HttpServletResponse response) {
request = new HttpServletRequestWrapperImpl(ctx, request);
JapResponse japResponse = this.simpleStrategy.authenticate(this.japProperties.getSimpleConfig(), new JakartaRequestAdapter(request), new JakartaResponseAdapter(response));
return this.simpleResponse(ctx, japResponse);
}
use of com.fujieid.jap.core.result.JapResponse 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("/"));
}
}
Aggregations