Search in sources :

Example 1 with Get

use of org.noear.solon.annotation.Get 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);
}
Also used : HttpServletRequestWrapperImpl(com.fujieid.jap.solon.HttpServletRequestWrapperImpl) JakartaRequestAdapter(com.fujieid.jap.http.adapter.jakarta.JakartaRequestAdapter) JapResponse(com.fujieid.jap.core.result.JapResponse) SocialConfig(com.fujieid.jap.social.SocialConfig) JakartaResponseAdapter(com.fujieid.jap.http.adapter.jakarta.JakartaResponseAdapter) Get(org.noear.solon.annotation.Get) Mapping(org.noear.solon.annotation.Mapping)

Example 2 with Get

use of org.noear.solon.annotation.Get in project solon by noear.

the class LogoutController method logout.

@Get
@Mapping("logout")
public void logout(Context ctx, HttpServletRequest request, HttpServletResponse response) {
    IdsResponse<String, String> idsResponse = this.logoutEndpoint.logout(new JakartaRequestAdapter(request), new JakartaResponseAdapter(response));
    ctx.redirect(idsResponse.getData());
}
Also used : JakartaRequestAdapter(com.fujieid.jap.http.adapter.jakarta.JakartaRequestAdapter) JakartaResponseAdapter(com.fujieid.jap.http.adapter.jakarta.JakartaResponseAdapter) Get(org.noear.solon.annotation.Get) Mapping(org.noear.solon.annotation.Mapping)

Example 3 with Get

use of org.noear.solon.annotation.Get in project solon-examples by noear.

the class LoginController method getValidationImg.

/*
     * 获取验证码图片
     */
@Get
@Mapping(value = "/login/validation/img", method = MethodType.GET, produces = "image/jpeg")
public void getValidationImg(Context ctx) throws IOException {
    // 生成验证码存入session
    String validation = RandomUtils.code(4);
    Session.current().setValidation(validation);
    ctx.sessionState().sessionPublish();
    // 获取图片
    BufferedImage bufferedImage = ImageUtils.getValidationImage(validation);
    // 禁止图像缓存
    ctx.headerSet("Pragma", "no-cache");
    ctx.headerSet("Cache-Control", "no-cache");
    ctx.headerSet("Expires", "0");
    // 图像输出
    ImageIO.setUseCache(false);
    ImageIO.write(bufferedImage, "jpeg", ctx.outputStream());
}
Also used : BufferedImage(java.awt.image.BufferedImage) Get(org.noear.solon.annotation.Get) Mapping(org.noear.solon.annotation.Mapping)

Example 4 with Get

use of org.noear.solon.annotation.Get in project Water by noear.

the class LoginController method getValidationImg.

/*
     * 获取验证码图片
     */
@Get
@Produces("image/jpeg")
@Mapping("/login/validation/img")
public void getValidationImg(Context ctx) throws IOException {
    // 生成验证码存入session
    String validation = RandomUtils.code(4);
    Session.current().setValidation(validation);
    ctx.sessionState().sessionPublish();
    // 获取图片
    BufferedImage bufferedImage = ImageUtils.getValidationImage(validation);
    // 禁止图像缓存
    ctx.headerSet("Pragma", "no-cache");
    ctx.headerSet("Cache-Control", "no-cache");
    ctx.headerSet("Expires", "0");
    // 图像输出
    ImageIO.setUseCache(false);
    ImageIO.write(bufferedImage, "jpeg", ctx.outputStream());
}
Also used : BufferedImage(java.awt.image.BufferedImage) Produces(org.noear.solon.annotation.Produces) Get(org.noear.solon.annotation.Get) Mapping(org.noear.solon.annotation.Mapping)

Example 5 with Get

use of org.noear.solon.annotation.Get in project solon by noear.

the class AuthorizationController method authorizeGet.

@Get
@Mapping("authorize")
public void authorizeGet(Context ctx, HttpServletRequest request) throws IOException {
    // authorize
    IdsResponse<String, String> idsResponse = this.authorizationEndpoint.authorize(new JakartaRequestAdapter(request));
    ctx.redirect(idsResponse.getData());
}
Also used : JakartaRequestAdapter(com.fujieid.jap.http.adapter.jakarta.JakartaRequestAdapter) Get(org.noear.solon.annotation.Get) Mapping(org.noear.solon.annotation.Mapping)

Aggregations

Get (org.noear.solon.annotation.Get)5 Mapping (org.noear.solon.annotation.Mapping)5 JakartaRequestAdapter (com.fujieid.jap.http.adapter.jakarta.JakartaRequestAdapter)3 JakartaResponseAdapter (com.fujieid.jap.http.adapter.jakarta.JakartaResponseAdapter)2 BufferedImage (java.awt.image.BufferedImage)2 JapResponse (com.fujieid.jap.core.result.JapResponse)1 SocialConfig (com.fujieid.jap.social.SocialConfig)1 HttpServletRequestWrapperImpl (com.fujieid.jap.solon.HttpServletRequestWrapperImpl)1 Produces (org.noear.solon.annotation.Produces)1