コード例 #1
0
 @RequestMapping(value = "/manual", method = RequestMethod.GET)
 public Subject manualCallback(
     @RequestParam Long userId,
     @RequestParam String appKey,
     @RequestParam String accessToken,
     @RequestParam String refreshToken)
     throws TaobaoOauthException {
   Subject currentSubject = SecurityUtils.getSubject();
   if (!currentSubject.isAuthenticated()) {
     ShiroTaobaoAuthenticationToken token = new ShiroTaobaoAuthenticationToken();
     token.setUserId(userId);
     token.setAppKey(appKey);
     token.setAccessToken(accessToken);
     token.setRefreshToken(refreshToken);
     token.setAppKey(taobaoApiService.getAppKey());
     try {
       currentSubject.login(token);
     } catch (UnknownAccountException uae) {
       throw new AuthenticationException("UnknownAccountException occurred.", uae);
     } catch (IncorrectCredentialsException ice) {
       throw new AuthenticationException("IncorrectCredentialsException occurred.", ice);
     } catch (LockedAccountException lae) {
       throw new AuthenticationException("LockedAccountException occurred.", lae);
     }
   }
   return SecurityUtils.getSubject();
 }
コード例 #2
0
  /**
   * cas 登录
   *
   * @param redirect
   * @param userId
   * @param appKey
   * @param accessToken
   * @param refreshToken
   * @return
   * @throws TaobaoSessionExpiredException
   * @throws TaobaoEnhancedApiException
   * @throws TaobaoOauthException
   * @throws TaobaoAccessControlException
   */
  @RequestMapping(value = "/signIn", method = RequestMethod.POST)
  public String signIn(
      @RequestParam String redirect,
      @RequestParam String nick,
      @RequestParam Long userId,
      @RequestParam String appKey,
      @RequestParam String accessToken,
      @RequestParam String refreshToken)
      throws TaobaoSessionExpiredException, TaobaoEnhancedApiException, TaobaoOauthException,
          TaobaoAccessControlException {

    Subject subject = SecurityUtils.getSubject();
    if (!subject.isAuthenticated()) {
      ShiroTaobaoAuthenticationToken token = new ShiroTaobaoAuthenticationToken();
      token.setNick(nick);
      token.setUserId(userId);
      token.setAppKey(appKey);
      token.setAccessToken(accessToken);
      token.setRefreshToken(refreshToken);
      subject.login(token);
    }
    return "redirect:" + redirect;
  }