• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java User类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: testAuthenticateSuccess

import com.google.api.server.spi.auth.common.User; //导入依赖的package包/类
@Test
public void testAuthenticateSuccess() {
  String email = "[email protected]";
  String id = "user-id";
  UserInfo userInfo = new UserInfo(ImmutableList.<String>of(), email, id, "issuer");
  when(this.authenticator.authenticate(request, AUTH_INFO, SERVICE_NAME))
      .thenReturn(userInfo);
  this.attribute.set(ATTRIBUTE_PREFIX + ".method_info", INFO);
  this.attribute.set(ATTRIBUTE_PREFIX + ".service", SERVICE);

  User user = this.espAuthenticator.authenticate(request);
  assertEquals(email, user.getEmail());
  assertEquals(id, user.getId());

  verify(this.authenticator, only()).authenticate(request, AUTH_INFO, SERVICE_NAME);
}
 
开发者ID:cloudendpoints,项目名称:endpoints-management-java,代码行数:17,代码来源:EspAuthenticatorTest.java


示例2: authenticateAppEngineUser

import com.google.api.server.spi.auth.common.User; //导入依赖的package包/类
/**
 * Authenticate the request and retrieve an {@code com.google.appengine.api.users.User}. Should
 * only run once per request.
 */
com.google.appengine.api.users.User authenticateAppEngineUser() throws ServiceException {
  if (!EnvUtil.isRunningOnAppEngine()) {
    return null;
  }
  attr.set(Attribute.REQUIRE_APPENGINE_USER, true);
  User user = authenticate();
  attr.set(Attribute.REQUIRE_APPENGINE_USER, false);
  if (user == null) {
    return null;
  }
  com.google.appengine.api.users.User appEngineUser =
      (com.google.appengine.api.users.User) attr.get(Attribute.AUTHENTICATED_APPENGINE_USER);
  if (appEngineUser != null) {
    return appEngineUser;
  } else {
    return user.getEmail() == null
        ? null : new com.google.appengine.api.users.User(user.getEmail(), "", user.getId());
  }
}
 
开发者ID:cloudendpoints,项目名称:endpoints-java,代码行数:24,代码来源:Auth.java


示例3: testUserInjectionThrowsExceptionIfRequired

import com.google.api.server.spi.auth.common.User; //导入依赖的package包/类
@Test
public void testUserInjectionThrowsExceptionIfRequired() throws Exception {
  @SuppressWarnings("unused")
  class TestUser {
    @SuppressWarnings("unused")
    public void getUser(User user) { }
  }
  ApiMethodConfig methodConfig = Mockito.mock(ApiMethodConfig.class);
  when(methodConfig.getAuthLevel()).thenReturn(AuthLevel.REQUIRED);
  methodConfig.setAuthLevel(AuthLevel.REQUIRED);
  try {
    Method method = TestUser.class.getDeclaredMethod("getUser", User.class);
    readParameters(
        "{}", EndpointMethod.create(method.getDeclaringClass(), method),
        methodConfig,
        null,
        null);
    fail("expected unauthorized method exception");
  } catch (UnauthorizedException ex) {
    // expected
  }
}
 
开发者ID:cloudendpoints,项目名称:endpoints-java,代码行数:23,代码来源:ServletRequestParamReaderTest.java


示例4: testAppEngineUserInjectionThrowsExceptionIfRequired

import com.google.api.server.spi.auth.common.User; //导入依赖的package包/类
@Test
public void testAppEngineUserInjectionThrowsExceptionIfRequired() throws Exception {
  @SuppressWarnings("unused")
  class TestUser {
    @SuppressWarnings("unused")
    public void getUser(com.google.appengine.api.users.User user) { }
  }
  ApiMethodConfig methodConfig = Mockito.mock(ApiMethodConfig.class);
  when(methodConfig.getAuthLevel()).thenReturn(AuthLevel.REQUIRED);
  methodConfig.setAuthLevel(AuthLevel.REQUIRED);
  try {
    Method method = TestUser.class
        .getDeclaredMethod("getUser", com.google.appengine.api.users.User.class);
    readParameters(
        "{}",
        EndpointMethod.create(method.getDeclaringClass(), method),
        methodConfig,
        null,
        null);
    fail("expected unauthorized method exception");
  } catch (UnauthorizedException ex) {
    // expected
  }
}
 
开发者ID:cloudendpoints,项目名称:endpoints-java,代码行数:25,代码来源:ServletRequestParamReaderTest.java


示例5: readParameters

import com.google.api.server.spi.auth.common.User; //导入依赖的package包/类
private Object[] readParameters(final String input, EndpointMethod method,
    ApiMethodConfig methodConfig, final User user,
    final com.google.appengine.api.users.User appEngineUser)
    throws Exception {
  ParamReader reader = new ServletRequestParamReader(
      method, request, context, null, methodConfig) {
    @Override
    User getUser() {
      return user;
    }
    @Override
    com.google.appengine.api.users.User getAppEngineUser() {
      return appEngineUser;
    }
  };
  return readParameters(input, reader);
}
 
开发者ID:cloudendpoints,项目名称:endpoints-java,代码行数:18,代码来源:ServletRequestParamReaderTest.java


示例6: testAuthenticateOAuth2Fail

import com.google.api.server.spi.auth.common.User; //导入依赖的package包/类
@Test
public void testAuthenticateOAuth2Fail() {
  authenticator = new GoogleAppEngineAuthenticator(oauthService, userService) {
    @Override
    com.google.appengine.api.users.User getOAuth2User(HttpServletRequest request,
        ApiMethodConfig config) {
      return null;
    }

    @Override
    boolean shouldTryCookieAuth(ApiMethodConfig config) {
      return false;
    }
  };
  assertNull(authenticator.authenticate(request));
}
 
开发者ID:cloudendpoints,项目名称:endpoints-java,代码行数:17,代码来源:GoogleAppEngineAuthenticatorTest.java


示例7: testAuthenticateOAuth2CookieAuthBothFail

import com.google.api.server.spi.auth.common.User; //导入依赖的package包/类
@Test
public void testAuthenticateOAuth2CookieAuthBothFail() {
  authenticator = new GoogleAppEngineAuthenticator(oauthService, userService) {
    @Override
    com.google.appengine.api.users.User getOAuth2User(HttpServletRequest request,
        ApiMethodConfig config) {
      return null;
    }

    @Override
    boolean shouldTryCookieAuth(ApiMethodConfig config) {
      return true;
    }
  };
  when(userService.getCurrentUser()).thenReturn(null);
  assertNull(authenticator.authenticate(request));
}
 
开发者ID:cloudendpoints,项目名称:endpoints-java,代码行数:18,代码来源:GoogleAppEngineAuthenticatorTest.java


示例8: testAuthenticateOAuth2FailCookieAuth

import com.google.api.server.spi.auth.common.User; //导入依赖的package包/类
@Test
public void testAuthenticateOAuth2FailCookieAuth() {
  authenticator = new GoogleAppEngineAuthenticator(oauthService, userService) {
    @Override
    com.google.appengine.api.users.User getOAuth2User(HttpServletRequest request,
        ApiMethodConfig config) {
      return null;
    }

    @Override
    boolean shouldTryCookieAuth(ApiMethodConfig config) {
      return true;
    }
  };
  when(userService.getCurrentUser()).thenReturn(APP_ENGINE_USER);
  assertEquals(USER, authenticator.authenticate(request));
  assertEquals(APP_ENGINE_USER, attr.get(Attribute.AUTHENTICATED_APPENGINE_USER));
}
 
开发者ID:cloudendpoints,项目名称:endpoints-java,代码行数:19,代码来源:GoogleAppEngineAuthenticatorTest.java


示例9: getUserEmail

import com.google.api.server.spi.auth.common.User; //导入依赖的package包/类
/**
 * Gets the authenticated user's email. If the user is not authenticated, this will return an HTTP
 * 401.
 * <p>
 * Note that name is not specified. This will default to "{class name}.{method name}". For
 * example, the default is "echo.getUserEmail".
 * <p>
 * Note that httpMethod is not required here. Without httpMethod, this will default to GET due
 * to the API method name. httpMethod is added here for example purposes.
 */
// [START google_id_token_auth]
@ApiMethod(
        httpMethod = ApiMethod.HttpMethod.GET,
        authenticators = {EspAuthenticator.class},
        audiences = {"YOUR_OAUTH_CLIENT_ID"},
        clientIds = {"YOUR_OAUTH_CLIENT_ID"}
)
public Email getUserEmail(User user) throws UnauthorizedException {
    if (user == null) {
        throw new UnauthorizedException("Invalid credentials");
    }

    Email response = new Email();
    response.setEmail(user.getEmail());
    return response;
}
 
开发者ID:Cryptonomica,项目名称:cryptonomica,代码行数:27,代码来源:TestAPI.java


示例10: getUserEmailFirebase

import com.google.api.server.spi.auth.common.User; //导入依赖的package包/类
/**
     * Gets the authenticated user's email. If the user is not authenticated, this will return an HTTP
     * 401.
     * <p>
     * Note that name is not specified. This will default to "{class name}.{method name}". For
     * example, the default is "echo.getUserEmail".
     * <p>
     * Note that httpMethod is not required here. Without httpMethod, this will default to GET due
     * to the API method name. httpMethod is added here for example purposes.
     */
    // [START firebase_auth]
    @ApiMethod(
            path = "firebase_user",
            httpMethod = ApiMethod.HttpMethod.GET,
            authenticators = {EspAuthenticator.class},
            issuerAudiences = {
                    @ApiIssuerAudience(
                            name = "firebase",
//                            audiences = {"YOUR-PROJECT-ID"}
                            audiences = {"cryptonomica-server"}
                    )
            }
    )


    public Email getUserEmailFirebase(User user) throws UnauthorizedException {
        if (user == null) {
            throw new UnauthorizedException("Invalid credentials");
        }

        Email response = new Email();
        response.setEmail(user.getEmail());
        return response;
    }
 
开发者ID:Cryptonomica,项目名称:cryptonomica,代码行数:35,代码来源:TestAPI.java


示例11: authenticate

import com.google.api.server.spi.auth.common.User; //导入依赖的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


示例12: getUserEmail

import com.google.api.server.spi.auth.common.User; //导入依赖的package包/类
/**
 * Gets the authenticated user's email. If the user is not authenticated, this will return an HTTP
 * 401.
 *
 * <p>Note that name is not specified. This will default to "{class name}.{method name}". For
 * example, the default is "echo.getUserEmail".
 *
 * <p>Note that httpMethod is not required here. Without httpMethod, this will default to GET due
 * to the API method name. httpMethod is added here for example purposes.
 */
// [START google_id_token_auth]
@ApiMethod(
    httpMethod = ApiMethod.HttpMethod.GET,
    authenticators = {EspAuthenticator.class},
    audiences = {"YOUR_OAUTH_CLIENT_ID"},
    clientIds = {"YOUR_OAUTH_CLIENT_ID"}
    )
public Email getUserEmail(User user) throws UnauthorizedException {
  if (user == null) {
    throw new UnauthorizedException("Invalid credentials");
  }

  Email response = new Email();
  response.setEmail(user.getEmail());
  return response;
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:27,代码来源:Echo.java


示例13: getUserEmailFirebase

import com.google.api.server.spi.auth.common.User; //导入依赖的package包/类
/**
 * Gets the authenticated user's email. If the user is not authenticated, this will return an HTTP
 * 401.
 *
 * <p>Note that name is not specified. This will default to "{class name}.{method name}". For
 * example, the default is "echo.getUserEmail".
 *
 * <p>Note that httpMethod is not required here. Without httpMethod, this will default to GET due
 * to the API method name. httpMethod is added here for example purposes.
 */
// [START firebase_auth]
@ApiMethod(
    path = "firebase_user",
    httpMethod = ApiMethod.HttpMethod.GET,
    authenticators = {EspAuthenticator.class},
    issuerAudiences = {@ApiIssuerAudience(name = "firebase", audiences = {"YOUR-PROJECT-ID"})}
    )
public Email getUserEmailFirebase(User user) throws UnauthorizedException {
  if (user == null) {
    throw new UnauthorizedException("Invalid credentials");
  }

  Email response = new Email();
  response.setEmail(user.getEmail());
  return response;
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:27,代码来源:Echo.java


示例14: getUserEmail

import com.google.api.server.spi.auth.common.User; //导入依赖的package包/类
/**
 * Gets the authenticated user's email. If the user is not authenticated, this will return an HTTP
 * 401.
 *
 * Note that name is not specified. This will default to "{class name}.{method name}". For
 * example, the default is "echo.getUserEmail".
 *
 * Note that httpMethod is not required here. Without httpMethod, this will default to GET due
 * to the API method name. httpMethod is added here for example purposes.
 */
// [START google_id_token_auth]
@ApiMethod(
    httpMethod = ApiMethod.HttpMethod.GET,
    authenticators = {EspAuthenticator.class},
    audiences = {"YOUR_OAUTH_CLIENT_ID"},
    clientIds = {"YOUR_OAUTH_CLIENT_ID"}
    )
public Email getUserEmail(User user) throws UnauthorizedException {
  if (user == null) {
    throw new UnauthorizedException("Invalid credentials");
  }

  Email response = new Email();
  response.setEmail(user.getEmail());
  return response;
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:27,代码来源:Echo.java


示例15: getUserEmailFirebase

import com.google.api.server.spi.auth.common.User; //导入依赖的package包/类
/**
 * Gets the authenticated user's email. If the user is not authenticated, this will return an HTTP
 * 401.
 *
 * Note that name is not specified. This will default to "{class name}.{method name}". For
 * example, the default is "echo.getUserEmail".
 *
 * Note that httpMethod is not required here. Without httpMethod, this will default to GET due
 * to the API method name. httpMethod is added here for example purposes.
 */
// [START firebase_auth]
@ApiMethod(
    path = "firebase_user",
    httpMethod = ApiMethod.HttpMethod.GET,
    authenticators = {EspAuthenticator.class},
    issuerAudiences = {@ApiIssuerAudience(name = "firebase", audiences = {"YOUR-PROJECT-ID"})}
    )
public Email getUserEmailFirebase(User user) throws UnauthorizedException {
  if (user == null) {
    throw new UnauthorizedException("Invalid credentials");
  }

  Email response = new Email();
  response.setEmail(user.getEmail());
  return response;
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:27,代码来源:Echo.java


示例16: getUserEmail

import com.google.api.server.spi.auth.common.User; //导入依赖的package包/类
/**
 * Gets the authenticated user's email. If the user is not authenticated, this will return an HTTP
 * 401.
 *
 * <p>Note that name is not specified. This will default to "{class name}.{method name}". For
 * example, the default is "echo.getUserEmail".
 *
 * <p>Note that httpMethod is not required here. Without httpMethod, this will default to GET due
 * to the API method name. httpMethod is added here for example purposes.
 */
// [START google_id_token_auth]
@ApiMethod(
    httpMethod = ApiMethod.HttpMethod.GET,
    authenticators = {EspAuthenticator.class},
    audiences = {"YOUR_OAUTH_CLIENT_ID"},
    clientIds = {"YOUR_OAUTH_CLIENT_ID"}
)
public Email getUserEmail(User user) throws UnauthorizedException {
  if (user == null) {
    throw new UnauthorizedException("Invalid credentials");
  }

  Email response = new Email();
  response.setEmail(user.getEmail());
  return response;
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:27,代码来源:Echo.java


示例17: getUserEmailFirebase

import com.google.api.server.spi.auth.common.User; //导入依赖的package包/类
/**
 * Gets the authenticated user's email. If the user is not authenticated, this will return an HTTP
 * 401.
 *
 * <p>Note that name is not specified. This will default to "{class name}.{method name}". For
 * example, the default is "echo.getUserEmail".
 *
 * <p>Note that httpMethod is not required here. Without httpMethod, this will default to GET due
 * to the API method name. httpMethod is added here for example purposes.
 */
// [START firebase_auth]
@ApiMethod(
    path = "firebase_user",
    httpMethod = ApiMethod.HttpMethod.GET,
    authenticators = {EspAuthenticator.class},
    issuerAudiences = {
        @ApiIssuerAudience(
            name = "firebase",
            audiences = {"YOUR-PROJECT-ID"}
        )
    }
)
public Email getUserEmailFirebase(User user) throws UnauthorizedException {
  if (user == null) {
    throw new UnauthorizedException("Invalid credentials");
  }

  Email response = new Email();
  response.setEmail(user.getEmail());
  return response;
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:32,代码来源:Echo.java


示例18: reset

import com.google.api.server.spi.auth.common.User; //导入依赖的package包/类
/**
 * Reset reservations in datastore to match those in RTDB. Reservations in RTDB are used
 * as the source of truth, corresponding reservations in datastore are updated to match
 * those in RTDB. Reservations in RTDB that do not exist in datastore are added to datastore.
 * Reservations that exist in datastore and do not exist in RTDB are updated in datastore
 * with status DELETED.
 *
 * Use of this endpoint should be followed by a user data sync.
 *
 * @param user User making request (injected by Endpoints)
 */
@ApiMethod(name = "reset", path = "reset")
public void reset(User user)
    throws UnauthorizedException {
  if (user == null) {
    throw new UnauthorizedException("Invalid credentials");
  }

  // Add Sync Reservations worker to queue.
  Queue queue = QueueFactory.getQueue("SyncReservationsQueue");

  TaskOptions taskOptions = TaskOptions.Builder
      .withUrl("/queue/syncres")
      .method(Method.GET);
  queue.add(taskOptions);
}
 
开发者ID:google,项目名称:iosched,代码行数:27,代码来源:ReservationsEndpoint.java


示例19: updateUser

import com.google.api.server.spi.auth.common.User; //导入依赖的package包/类
/**
 * Batch update user data
 *
 * @param user Current user (injected by Endpoints)
 * @param userData UserData object with new values to save
 * @return Updated UserData object
 */
@SuppressWarnings("ResourceParameter")  // http://b.android.com/201031
@ApiMethod(name = "updateUser", path = "all", httpMethod = ApiMethod.HttpMethod.PUT)
public UserData updateUser(User user,  UserData userData) throws UnauthorizedException {
    UserData savedData = getUser(user);

    // Bookmarked sessions can be overwritten
    savedData.bookmarkedSessions = userData.bookmarkedSessions;
    // Reviewed sessions should be merged with old values
    for (String session : userData.reviewedSessions) {
        savedData.reviewedSessions.add(session);
    }
    // We don't allow clients to update reserved sessions, preserve old values

    save(savedData);
    return savedData;
}
 
开发者ID:google,项目名称:iosched,代码行数:24,代码来源:UserdataEndpoint.java


示例20: addWaitlistedSession

import com.google.api.server.spi.auth.common.User; //导入依赖的package包/类
/**
 * Add a waitlisted session for the specified user. If the session is already in the user's feed,
 * it will be annotated with status=WAITLISTED.
 *
 * @param user         Service account making the request (injected by Endpoints)
 * @param userId       User ID of user that reserved a session.
 * @param sessionId    Session ID to mark as reserved.
 * @param timestampUTC The time (in millis, UTC) when the user performed this action. May be
 *                     different than the time this method is called if offline sync is
 *                     implemented. MUST BE ACCURATE - COMPENSATE FOR CLOCK DRIFT!
 * @return The list of reserved sessions for the user
 */
@ApiMethod(name = "addWaitlistedSession", path = "reservations/waitlist",
    httpMethod = ApiMethod.HttpMethod.PUT, clientIds = {Ids.SERVICE_ACCOUNT_CLIENT_ID})
public Map<String, ReservedSession> addWaitlistedSession (
    User user,
    @Named("userId") String userId,
    @Named("sessionId") String sessionId,
    @Named("timestampUTC") long timestampUTC)
    throws UnauthorizedException {
    UserData data = getUser(user, userId);
    ReservedSession s = new ReservedSession(sessionId, Status.WAITLISTED, timestampUTC);
    data.reservedSessions.put(sessionId, s);
    save(data);
    // notify user's clients of reservation change change
    new GCMPing().notifyUserSync(data.userId);
    return data.reservedSessions;
}
 
开发者ID:google,项目名称:iosched,代码行数:29,代码来源:UserdataEndpoint.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ConfigBasedEJBClientContextSelector类代码示例发布时间:2022-05-23
下一篇:
Java JcaX509v3CertificateBuilder类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap