当前位置: 首页>>代码示例>>Java>>正文


Java OAuthRequestException类代码示例

本文整理汇总了Java中com.google.appengine.api.oauth.OAuthRequestException的典型用法代码示例。如果您正苦于以下问题:Java OAuthRequestException类的具体用法?Java OAuthRequestException怎么用?Java OAuthRequestException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


OAuthRequestException类属于com.google.appengine.api.oauth包,在下文中一共展示了OAuthRequestException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getEmail

import com.google.appengine.api.oauth.OAuthRequestException; //导入依赖的package包/类
@Override
public String getEmail() {
  
  try {
    OAuthService authService = OAuthServiceFactory.getOAuthService();
    
    User user = authService.getCurrentUser();
    
    if ( user != null ) {
      String email = user.getEmail();
      if ( email != null && email.length() != 0 ) {
        return "mailto:" + email;
      }
    }
  } catch ( OAuthRequestException e) {
    // ignore this -- just means it isn't an OAuth-mediated request.
  }
  return null;
}
 
开发者ID:opendatakit,项目名称:aggregate,代码行数:20,代码来源:GaeOutOfBandUserFetcher.java

示例2: getFriends

import com.google.appengine.api.oauth.OAuthRequestException; //导入依赖的package包/类
/**
 * Get user's Friends
 *
 * @param user The Google Authenticated User
 */
@ApiMethod(
        name = "friends.all",
        path = "friends",
        httpMethod = ApiMethod.HttpMethod.GET
)
public CollectionResponse<FriendResponse> getFriends(User user) throws OAuthRequestException {
    UserRecord currentUser = userDAO.getUserRecord(user);
    if (currentUser == null) {
        throw new OAuthRequestException(Messages.ERROR_AUTH);
    }

    List<FriendResponse> responseList = new ArrayList<>();

    List<Long> friends = friendDAO.getUsersFriends(currentUser);
    for (Long friendId : friends) {
        UserRecord friendUserRecord = userDAO.getUserRecord(friendId);
        responseList.add(new FriendResponse().setUserRecord(friendUserRecord));
    }

    return CollectionResponse.<FriendResponse>builder().setItems(responseList).build();
}
 
开发者ID:AndrewJack,项目名称:moment-for-android-wear,代码行数:27,代码来源:FriendEndpoint.java

示例3: getFriendRequests

import com.google.appengine.api.oauth.OAuthRequestException; //导入依赖的package包/类
/**
 * Get User's friend requests
 * users that have added the current user
 *
 * @param user The Google Authenticated User
 */
@ApiMethod(
        name = "friends.requests",
        path = "friends/requests",
        httpMethod = ApiMethod.HttpMethod.GET
)
public CollectionResponse<FriendResponse> getFriendRequests(User user) throws OAuthRequestException {
    UserRecord currentUser = userDAO.getUserRecord(user);
    if (currentUser == null) {
        throw new OAuthRequestException(Messages.ERROR_AUTH);
    }

    List<Long> requestedAdds = friendDAO.getAddRequests(currentUser);
    List<FriendResponse> responseList = new ArrayList<>(requestedAdds.size());
    for (Long requestedAdd : requestedAdds) {
        UserRecord requestingUser = userDAO.getUserRecord(requestedAdd);
        responseList.add(new FriendResponse().setUserRecord(requestingUser));
    }

    return CollectionResponse.<FriendResponse>builder().setItems(responseList).build();
}
 
开发者ID:AndrewJack,项目名称:moment-for-android-wear,代码行数:27,代码来源:FriendEndpoint.java

示例4: removeFriend

import com.google.appengine.api.oauth.OAuthRequestException; //导入依赖的package包/类
/**
 * Remove user's friend
 *
 * @param friendId The user id of the friend to remove
 * @param user The Google Authenticated User
 */
@ApiMethod(
        name = "friends.remove",
        path = "friends/{friendId}",
        httpMethod = ApiMethod.HttpMethod.DELETE
)
public void removeFriend(@Named("friendId") long friendId, User user)
        throws OAuthRequestException, BadRequestException, NotFoundException, IOException {

    UserRecord currentUser = userDAO.getUserRecord(user);
    if (currentUser == null) {
        throw new OAuthRequestException(Messages.ERROR_AUTH);
    }

    if (friendId == 0) {
        throw new BadRequestException(Messages.ERROR_INVALID_PARAMETERS);
    }

    FriendRecord friendRecord = friendDAO.getFriendRecord(currentUser);
    if (friendRecord != null && friendRecord.removeFriend(friendId)) {
        // if friend was found and removed then update friend record
        friendDAO.save(friendRecord);
    } else {
        throw new NotFoundException(Messages.ERROR_FRIEND_NOT_FOUND);
    }
}
 
开发者ID:AndrewJack,项目名称:moment-for-android-wear,代码行数:32,代码来源:FriendEndpoint.java

示例5: unregister

import com.google.appengine.api.oauth.OAuthRequestException; //导入依赖的package包/类
/**
 * Unregister a device
 * This will not remove a user
 *
 * @param deviceId The Google Cloud Messaging registration Id to remove
 * @param user     The Google Authenticated User
 */
@ApiMethod(
        name = "users.unregister",
        path = "users/unregister",
        httpMethod = HttpMethod.POST
)
public void unregister(@Named("deviceId") String deviceId, User user) throws OAuthRequestException, BadRequestException {
    UserRecord currentUser = userDAO.getUserRecord(user);
    if (currentUser == null) {
        throw new OAuthRequestException(Messages.ERROR_AUTH);
    }

    if (deviceId == null) {
        throw new BadRequestException(Messages.ERROR_INVALID_PARAMETERS);
    }

    for (String id : currentUser.getDevices()) {
        if (id.equals(deviceId)) {
            // found device - unregister it
            currentUser.removeDevice(id);
            userDAO.save(currentUser);
            return;
        }
    }
}
 
开发者ID:AndrewJack,项目名称:moment-for-android-wear,代码行数:32,代码来源:UserEndpoint.java

示例6: remove

import com.google.appengine.api.oauth.OAuthRequestException; //导入依赖的package包/类
/**
 * Remove a user
 *
 * @param user The Google Authenticated User
 */
@ApiMethod(
        name = "users.remove",
        path = "users",
        httpMethod = HttpMethod.DELETE
)
public void remove(User user) throws OAuthRequestException {
    UserRecord currentUser = userDAO.getUserRecord(user);
    if (currentUser == null) {
        throw new OAuthRequestException(Messages.ERROR_AUTH);
    }

    // delete friends record
    friendDAO.delete(currentUser);
    // delete user record
    userDAO.delete(currentUser);

    // TODO: start task to remove user from other people's friends
}
 
开发者ID:AndrewJack,项目名称:moment-for-android-wear,代码行数:24,代码来源:UserEndpoint.java

示例7: getCommentsByTech

import com.google.appengine.api.oauth.OAuthRequestException; //导入依赖的package包/类
@Override
public Response getCommentsByTech(String techId, User user) throws InternalServerErrorException,
    BadRequestException, NotFoundException, OAuthRequestException {

  final Technology technology = techService.getTechnologyById(techId, user);

  validateUser(user);
  validateTechnology(technology);

  final List<TechnologyComment> commentsByTech =
      technologyCommentDao.findAllActivesByTechnology(technology);
  final TechnologyCommentsTO response = new TechnologyCommentsTO();
  response.setComments(commentsByTech);
  /*
   * for (TechnologyComment comment : response.getComments()) { setCommentRecommendation(comment);
   * }
   */
  return response;
}
 
开发者ID:ciandt-dev,项目名称:tech-gallery,代码行数:20,代码来源:TechnologyCommentServiceImpl.java

示例8: getEndorsementsByTech

import com.google.appengine.api.oauth.OAuthRequestException; //导入依赖的package包/类
/**
 * GET for getting one endorsement.
 *
 * @throws InternalServerErrorException in case something goes wrong
 * @throws OAuthRequestException in case of authentication problem
 * @throws NotFoundException in case the information are not founded
 * @throws BadRequestException in case a request with problem were made.
 */
@Override
public Response getEndorsementsByTech(String techId, User user)
    throws InternalServerErrorException, BadRequestException, NotFoundException,
    OAuthRequestException {
  final List<Endorsement> endorsementsByTech = endorsementDao.findAllActivesByTechnology(techId);
  final List<EndorsementsGroupedByEndorsedTransient> grouped =
      groupEndorsementByEndorsed(endorsementsByTech, techId);
  final Technology technology = techService.getTechnologyById(techId, user);

  techService.updateEdorsedsCounter(technology, grouped.size());

  groupUsersWithSkill(grouped, technology);

  Collections.sort(grouped, new EndorsementsGroupedByEndorsedTransient());
  final ShowEndorsementsResponse response = new ShowEndorsementsResponse();
  response.setEndorsements(grouped);
  return response;
}
 
开发者ID:ciandt-dev,项目名称:tech-gallery,代码行数:27,代码来源:EndorsementServiceImpl.java

示例9: transformGroupedUserMapIntoList

import com.google.appengine.api.oauth.OAuthRequestException; //导入依赖的package包/类
private List<EndorsementsGroupedByEndorsedTransient> transformGroupedUserMapIntoList(
    Map<TechGalleryUser, List<TechGalleryUser>> mapUsersGrouped, String techId)
        throws BadRequestException, NotFoundException, InternalServerErrorException,
        OAuthRequestException {
  final List<EndorsementsGroupedByEndorsedTransient> groupedList =
      new ArrayList<EndorsementsGroupedByEndorsedTransient>();

  for (final Map.Entry<TechGalleryUser, List<TechGalleryUser>> entry : mapUsersGrouped
      .entrySet()) {
    final EndorsementsGroupedByEndorsedTransient grouped =
        new EndorsementsGroupedByEndorsedTransient();
    grouped.setEndorsed(entry.getKey());
    final Skill response = skillService.getUserSkill(techId, entry.getKey());
    if (response != null) {
      grouped.setEndorsedSkill(response.getValue());
    } else {
      grouped.setEndorsedSkill(0);
    }
    grouped.setEndorsers(entry.getValue());
    groupedList.add(grouped);
  }
  return groupedList;
}
 
开发者ID:ciandt-dev,项目名称:tech-gallery,代码行数:24,代码来源:EndorsementServiceImpl.java

示例10: getLinksByTech

import com.google.appengine.api.oauth.OAuthRequestException; //导入依赖的package包/类
@Override
public Response getLinksByTech(String techId, User user) throws InternalServerErrorException,
    BadRequestException, NotFoundException, OAuthRequestException {

  final Technology technology = techService.getTechnologyById(techId, user);

  validateUser(user);
  validateTechnology(technology);

  final List<TechnologyLink> linksByTech =
      technologyLinkDao.findAllByTechnology(technology);
  final TechnologyLinksTO response = new TechnologyLinksTO();
  response.setLinks(linksByTech);

  return response;
}
 
开发者ID:ciandt-dev,项目名称:tech-gallery,代码行数:17,代码来源:TechnologyLinkServiceImpl.java

示例11: getUserSkill

import com.google.appengine.api.oauth.OAuthRequestException; //导入依赖的package包/类
@Override
public Skill getUserSkill(String techId, TechGalleryUser user) throws BadRequestException,
    OAuthRequestException, NotFoundException, InternalServerErrorException {
  // User can't be null
  if (user == null) {
    throw new OAuthRequestException(i18n.t("Null user reference!"));
  }

  // Technology can't be null
  final Technology technology = techService.getTechnologyById(techId, null);
  if (technology == null) {
    throw new NotFoundException(i18n.t("Technology do not exists!"));
  }
  final Skill userSkill = skillDao.findByUserAndTechnology(user, technology);
  if (userSkill == null) {
    return null;
  } else {
    return userSkill;
  }
}
 
开发者ID:ciandt-dev,项目名称:tech-gallery,代码行数:21,代码来源:SkillServiceImpl.java

示例12: authenticate

import com.google.appengine.api.oauth.OAuthRequestException; //导入依赖的package包/类
@Override
public User authenticate(HttpServletRequest req) {
    OAuthService authService = OAuthServiceFactory.getOAuthService();
    com.google.appengine.api.users.User currentUser;

    try {
      currentUser = authService.getCurrentUser(Constants.EMAIL_SCOPE);
      // Check current user..
      if(currentUser != null) {
        String email = currentUser.getEmail();
        // Check domain..
        if(isValidDomain(email) || isWhiteList(email)) {
          return new User(currentUser.getUserId(), currentUser.getEmail());
        }
      }
      throw new RestrictedDomainException(i18n.t("Authorization error"));
    }
    catch(OAuthRequestException  e) {
      log.log(Level.WARNING, "Error when trying to authenticate. Message: " + e.getMessage(), e);
      return null;
    }
}
 
开发者ID:ciandt-dev,项目名称:tech-gallery,代码行数:23,代码来源:TechGalleryAuthenticator.java

示例13: registerDevice

import com.google.appengine.api.oauth.OAuthRequestException; //导入依赖的package包/类
/**
 * Register a device to the backend
 *
 * @param regId The Google Cloud Messaging registration Id to add
 */
@ApiMethod(name = "register")
public void registerDevice(@Named("regId") String regId, User user) throws OAuthRequestException {
    if(user == null){
        throw new OAuthRequestException("Not authorized");
    }
    final String userId = PresenterRecord.getUserId(user.getEmail());
    log.info("Registration for userId: " + userId);
    PresenterRecord record = ofy().load().
            key(Key.create(PresenterRecord.class, userId)).now();
    if(record == null){
        log.info("Record not found for userId '" + userId + "'. Adding new record");
        record = new PresenterRecord();
        record.setUserId(userId);
    }
    if (record.getRegIds().contains(regId)) {
        log.info("Device " + regId + " already registered, skipping register");
    }
    else {
        record.addRegistrationId(regId);
    }
    record.updateTime();
    ofy().save().entity(record).now();
}
 
开发者ID:google,项目名称:watchpresenter,代码行数:29,代码来源:RegistrationEndpoint.java

示例14: getMessageForVersion

import com.google.appengine.api.oauth.OAuthRequestException; //导入依赖的package包/类
/**
 *
 * @param versionNumber Version number for which message should be retrieved
 */
@ApiMethod(name = "getMessageForVersion")
public VersionMessage getMessageForVersion(@Named("versionNumber")int versionNumber, User user)
        throws IOException, OAuthRequestException {
    if(user == null){
        throw new OAuthRequestException("Not authorized");
    }
    final String userId = PresenterRecord.getUserId(user.getEmail());
    if(log.isLoggable(Level.FINE)) {
        log.fine("Get message version for userId " +
                userId + ". Version number: " + versionNumber);
    }
    VersionMessage message = new VersionMessage(
            VersionMessage.ACTION_NOTHING, "", "");
    return message;
}
 
开发者ID:google,项目名称:watchpresenter,代码行数:20,代码来源:MessagingEndpoint.java

示例15: checkRegistration

import com.google.appengine.api.oauth.OAuthRequestException; //导入依赖的package包/类
/**
 * Check if the user Id has, at least, one registered device
 *
 */
@ApiMethod(name = "checkRegistration")
public RegisteredResponse checkRegistration(User user) throws OAuthRequestException {
    if(user == null){
        throw new OAuthRequestException("Not authorized");
    }
    RegisteredResponse result = new RegisteredResponse();
    final String userId = PresenterRecord.getUserId(user.getEmail());
    log.info("Checking for registration. userId: " + userId);
    PresenterRecord record = ofy().load().
            key(Key.create(PresenterRecord.class, userId)).now();
    if(record != null){
        result.setRegistered(true);
    }
    return result;
}
 
开发者ID:google,项目名称:watchpresenter,代码行数:20,代码来源:MessagingEndpoint.java


注:本文中的com.google.appengine.api.oauth.OAuthRequestException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。