本文整理汇总了Java中com.google.api.server.spi.auth.common.User类的典型用法代码示例。如果您正苦于以下问题:Java User类的具体用法?Java User怎么用?Java User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
User类属于com.google.api.server.spi.auth.common包,在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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());
}
}
示例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
}
}
示例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
}
}
示例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);
}
示例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));
}
示例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));
}
示例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));
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}