Example #1
0
  /*
   * 모바일 회원 가입
   */
  @Override
  public String registerMobileAccount(RequestRegisterMobileAccount mobileAccount) {
    MobileVerification verification =
        mobileVerificationRepository.findByIdAndDeviceId(
            mobileAccount.getId(), mobileAccount.getDeviceId());
    if (verification == null) {
      throw new EdiyaAPIException(APIError.REGISTRAION_ERROR_NOT_FOUND_REQUEST);
    }

    String[] userInfo =
        CryptoUtils.decryptRSA(
                verification.getPrivateKeyModulus(),
                verification.getPrivateKeyExponent(),
                mobileAccount.getCrypto())
            .split(":");
    if (userInfo.length != 3) {
      throw new EdiyaAPIException(APIError.REGISTRAION_ERROR_SYNTAX_ACCOUNT_INFO);
    }

    // TODO userName, userId, deviceId 중복 체크

    // 사용자 정보 생성
    String userId = CryptoUtils.generateUserId();
    String secret = CryptoUtils.generateSecureRandom();
    String name = userInfo[0];
    String nick = userInfo[1];
    String password = userInfo[2];

    // 계정정보 저장
    User user = new User(userId, name, nick, password);
    userRepository.save(user);

    // 단말기 정보 저장
    DeviceSession session = new DeviceSession(userId, secret, verification);
    deviceSessionRepository.save(session);

    // 가입 요청 정보 삭제
    mobileVerificationRepository.delete(verification);

    logger.info(
        "registerMobileAccount {} {} {} {}",
        user.getId(),
        user.getName(),
        user.getNick(),
        session.getDeviceId());

    return Base64Utils.encodeToString(verification.getDeviceId().getBytes())
        + ":"
        + Base64Utils.encodeToString(secret.getBytes());
  }
Example #2
0
  /*
   * 모바일 회원가입 요청
   */
  @Override
  public ResponseStartMobileVerification startMobileVerification(MobileVerification verification) {
    // 비밀키 설정
    KeyPair keyPair = CryptoUtils.generateRSAKeyPair();
    verification.setPrivateKey(keyPair.getPrivate());

    // 가입 요청 정보 저장
    mobileVerificationRepository.save(verification);

    logger.info("startMobileVerification {}", verification.getDeviceId());

    // 공개키는 응답결과로 전달
    return new ResponseStartMobileVerification(verification.getId(), keyPair.getPublic());
  }