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


Java Context类代码示例

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


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

示例1: getUsername

import play.mvc.Http.Context; //导入依赖的package包/类
@Override
 public String getUsername(Context ctx) {
 	String[] authTokenHeaderValues = ctx.request().headers().get(AuthUtils.AUTH_HEADER_KEY);
 	if ((authTokenHeaderValues != null) && (authTokenHeaderValues.length == 1) && (authTokenHeaderValues[0] != null)) {
 		String authHeader = authTokenHeaderValues[0];

try {
	JWTClaimsSet claimSet = (JWTClaimsSet) authenticator.decodeToken(authHeader);
	if (new DateTime(claimSet.getExpirationTime()).isAfter(DateTime.now())) {
		return claimSet.getSubject();
	} 
} catch (ParseException | JOSEException e) {
	Logger.error("Erro na validação do token: " + e.getMessage());
}
 	}

     return null;
 }
 
开发者ID:nazareno,项目名称:diferentonas-server,代码行数:19,代码来源:AcessoCidadao.java

示例2: getVerifyEmailMailingBody

import play.mvc.Http.Context; //导入依赖的package包/类
@Override
protected Body getVerifyEmailMailingBody(final String token,
		final MyUsernamePasswordAuthUser user, final Context ctx) {

	final boolean isSecure = getConfiguration().getBoolean(
			SETTING_KEY_VERIFICATION_LINK_SECURE);
	final String url = routes.Signup.verify(token).absoluteURL(
			ctx.request(), isSecure);

	final Lang lang = Lang.preferred(ctx.request().acceptLanguages());
	final String langCode = lang.code();

	final String html = getEmailTemplate(
			"views.html.account.signup.email.verify_email", langCode, url,
			token, user.getName(), user.getEmail());
	final String text = getEmailTemplate(
			"views.txt.account.signup.email.verify_email", langCode, url,
			token, user.getName(), user.getEmail());

	return new Body(text, html);
}
 
开发者ID:Vadus,项目名称:songs_play,代码行数:22,代码来源:MyUsernamePasswordAuthProvider.java

示例3: getPasswordResetMailingBody

import play.mvc.Http.Context; //导入依赖的package包/类
protected Body getPasswordResetMailingBody(final String token,
		final User user, final Context ctx) {

	final boolean isSecure = getConfiguration().getBoolean(
			SETTING_KEY_PASSWORD_RESET_LINK_SECURE);
	final String url = routes.Signup.resetPassword(token).absoluteURL(
			ctx.request(), isSecure);

	final Lang lang = Lang.preferred(ctx.request().acceptLanguages());
	final String langCode = lang.code();

	final String html = getEmailTemplate(
			"views.html.account.email.password_reset", langCode, url,
			token, user.name, user.email);
	final String text = getEmailTemplate(
			"views.txt.account.email.password_reset", langCode, url, token,
			user.name, user.email);

	return new Body(text, html);
}
 
开发者ID:Vadus,项目名称:songs_play,代码行数:21,代码来源:MyUsernamePasswordAuthProvider.java

示例4: getVerifyEmailMailingBodyAfterSignup

import play.mvc.Http.Context; //导入依赖的package包/类
protected Body getVerifyEmailMailingBodyAfterSignup(final String token,
		final User user, final Context ctx) {

	final boolean isSecure = getConfiguration().getBoolean(
			SETTING_KEY_VERIFICATION_LINK_SECURE);
	final String url = routes.Signup.verify(token).absoluteURL(
			ctx.request(), isSecure);

	final Lang lang = Lang.preferred(ctx.request().acceptLanguages());
	final String langCode = lang.code();

	final String html = getEmailTemplate(
			"views.html.account.email.verify_email", langCode, url, token,
			user.name, user.email);
	final String text = getEmailTemplate(
			"views.txt.account.email.verify_email", langCode, url, token,
			user.name, user.email);

	return new Body(text, html);
}
 
开发者ID:Vadus,项目名称:songs_play,代码行数:21,代码来源:MyUsernamePasswordAuthProvider.java

示例5: getUsername

import play.mvc.Http.Context; //导入依赖的package包/类
@Override
public String getUsername(Context ctx) {
    // see if user is logged in
    if (session("username") == null)
        return null;

    // see if the session is expired
    String previousTick = session("userTime");
    if (previousTick != null && !previousTick.equals("")) {
        long previousT = Long.valueOf(previousTick);
        long currentT = new Date().getTime();
        long timeout = Long.valueOf(Play.application().configuration().getString("sessionTimeout")) * 1000 * 60;
        if ((currentT - previousT) > timeout) {
            // session expired
            session().clear();
            return null;
        }
    }

    // update time in session
    String tickString = Long.toString(new Date().getTime());
    session("userTime", tickString);

    return session("username");
}
 
开发者ID:kurator-org,项目名称:kurator-web,代码行数:26,代码来源:Secured.java

示例6: createAction

import play.mvc.Http.Context; //导入依赖的package包/类
@Override
public Action<Void> createAction(Request request, Method actionMethod) {

    return new Action.Simple() {
        @Override
        public Promise<Result> call(Context ctx) throws Throwable {
            // Inject the required services into the context
            injectCommonServicesIncontext(ctx);
            final Language language = new Language(request.getQueryString("lang"));

            if (messagesPlugin.isLanguageValid(language.getCode())) {
                Logger.debug("change language to: " + language.getCode());
                ctx.changeLang(language.getCode());
                // Update the CAS language cookie which is relying on Spring
                // framework (not really solid yet works)
                Utilities.setSsoLanguage(ctx, language.getCode());
            }

            return delegate.call(ctx);

        }
    };

}
 
开发者ID:theAgileFactory,项目名称:maf-desktop-app,代码行数:25,代码来源:MafHttpRequestHandler.java

示例7: getUsername

import play.mvc.Http.Context; //导入依赖的package包/类
public String getUsername(final Context ctx, String role) {
       String username = getUsernameOrIP(ctx, true);
       User u = User.findByEmail(username);

       if (u == null) {
           // Allow access by IP address to ROLE_VIEW_JC things. username
           // may be null if not from a valid IP, which will deny access.
           if (role.equals(UserRole.ROLE_VIEW_JC)) {
               return username;
           }
       } else if (u.hasRole(role) &&
                  (u.organization == null || u.organization.equals(OrgConfig.get().org))) {
           // Allow access if this user belongs to this organization or is a
           // multi-domain admin (null organization). Also, the user must
           // have the required role.
           return username;
       }

       return null;
}
 
开发者ID:schmave,项目名称:demschooltools,代码行数:21,代码来源:Secured.java

示例8: getUsernameOrIP

import play.mvc.Http.Context; //导入依赖的package包/类
public String getUsernameOrIP(final Context ctx, boolean allow_ip) {
     Logger.debug("Authenticator::getUsername " + ctx + ", " + allow_ip);
     final AuthUser u = mAuth.getUser(ctx.session());

     if (u != null) {
         User the_user = User.findByAuthUserIdentity(u);
         if (the_user != null) {
	// If a user is logged in already, check the session timeout.
	// If there is no timeout, or we can't parse it, or it's too old,
	// don't count the user as being logged in.
	Session sess = ctx.session();
	if (sess.get("timeout") != null) {
		try
		{
			long timeout = Long.parseLong(sess.get("timeout"));
			if (System.currentTimeMillis() - timeout < 1000 * 60 * 30) {
				sess.put("timeout", "" + System.currentTimeMillis());
				return the_user.email;
			}
		}
		catch (NumberFormatException e) {
		}
	}
}
     }

     // If we don't have a logged-in user, try going by IP address.
     if (allow_ip && Organization.getByHost() != null) {
         String sql = "select ip from allowed_ips where ip like :ip and organization_id=:org_id";
         SqlQuery sqlQuery = Ebean.createSqlQuery(sql);
         String address = Application.getRemoteIp();
         sqlQuery.setParameter("ip", address);
         sqlQuery.setParameter("org_id", Organization.getByHost().id);

         // execute the query returning a List of MapBean objects
         SqlRow result = sqlQuery.findUnique();

         if (result != null) {
             return address;
         }
     }

     return null;
 }
 
开发者ID:schmave,项目名称:demschooltools,代码行数:45,代码来源:Secured.java

示例9: restrict

import play.mvc.Http.Context; //导入依赖的package包/类
@Override
public boolean restrict(List<String[]> deadBoltRoles) {
    try {
        if (log.isDebugEnabled()) {
            log.debug("RESTRICT with handler [" + get() + "] timeout [" + DEFAULT_TIMEOUT + "] for roles " + Utilities.toString(deadBoltRoles));
        }
        Optional<Subject> subjectOption = getSubject(Http.Context.current(), get()).get(DEFAULT_TIMEOUT);
        if (!subjectOption.isPresent()) {
            if (log.isDebugEnabled()) {
                log.debug("RESTRICT FALSE since no subject found");
            }
            return false;
        }
        Subject subject = subjectOption.get();
        if (log.isDebugEnabled()) {
            log.debug("RESTRICT Subject = " + subject);
        }
        return restrict(deadBoltRoles, subject);
    } catch (Exception e) {
        log.error("Error while checking restriction for " + Utilities.toString(deadBoltRoles), e);
        return false;
    }
}
 
开发者ID:theAgileFactory,项目名称:app-framework,代码行数:24,代码来源:AbstractSecurityServiceImpl.java

示例10: beforeAuthCheck

import play.mvc.Http.Context; //导入依赖的package包/类
@Override
public Promise<Optional<Result>> beforeAuthCheck(final Http.Context ctx) {
    String uid = getUserSessionManagerPlugin().getUserSessionId(ctx);
    if (log.isDebugEnabled()) {
        log.debug("Calling beforeAuthCheck, user in session is " + uid);
    }
    if (uid == null) {
        return Promise.promise(new Function0<Optional<Result>>() {
            public Optional<Result> apply() throws Throwable {
                return Optional.of(redirectToLoginPage(ctx.request().uri()));
            }

        });

    }
    Optional<Result> emptyResult = Optional.empty();
    return Promise.promise(() -> emptyResult);
}
 
开发者ID:theAgileFactory,项目名称:app-framework,代码行数:19,代码来源:AbstractSecurityServiceImpl.java

示例11: checkPermission

import play.mvc.Http.Context; //导入依赖的package包/类
@Override
public Promise<Boolean> checkPermission(String permissionValue, DeadboltHandler deadboltHandler, Context ctx) {
    boolean permissionOk = false;

    try {
        IUserAccount userAccount = getSecurityService().getCurrentUser();
        if (userAccount != null) {
            List<? extends Permission> permissions = userAccount.getPermissions();
            for (Iterator<? extends Permission> iterator = permissions.iterator(); !permissionOk && iterator.hasNext();) {
                Permission permission = iterator.next();
                permissionOk = permission.getValue().contains(permissionValue);
            }
        }
    } catch (Exception e) {
        log.error("impossible to get the user", e);
    }

    final boolean permissionOkFinal = permissionOk;
    return Promise.promise(() -> permissionOkFinal);
}
 
开发者ID:theAgileFactory,项目名称:app-framework,代码行数:21,代码来源:AbstractSecurityServiceImpl.java

示例12: notify

import play.mvc.Http.Context; //导入依赖的package包/类
@Override
public Promise<Result> notify(Context ctx) {
    if (log.isDebugEnabled()) {
        log.debug("Notification for request " + ctx.request().path());
    }
    for (String pathPrefix : getRegisteredListeners().keySet()) {
        if (ctx.request().path().startsWith(pathPrefix)) {
            if (log.isDebugEnabled()) {
                log.debug("Notification for request " + ctx.request().path() + " found matching listener " + pathPrefix);
            }
            return getRegisteredListeners().get(pathPrefix).notifyRequest(ctx);
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("No matching listener for " + ctx.request().path());
    }
    return null;
}
 
开发者ID:theAgileFactory,项目名称:app-framework,代码行数:19,代码来源:CustomRouterServiceImpl.java

示例13: execute

import play.mvc.Http.Context; //导入依赖的package包/类
@Override
public Promise<Result> execute(String path, Context ctx) {
    for (WebCommand webCommand : webCommands) {
        if (webCommand.isCompatible(path, ctx)) {
            try {
                return webCommand.call(path, ctx);
            } catch (Exception e) {
                log.error("Error while calling the web command", e);
                return Promise.promise(() -> Controller.badRequest());
            }
        }
    }
    log.info("No compatible command found for path " + path);
    if (log.isDebugEnabled()) {
        log.debug("No compatible command found for path " + path);
    }
    return Promise.promise(() -> Controller.badRequest());
}
 
开发者ID:theAgileFactory,项目名称:app-framework,代码行数:19,代码来源:ExtensionManagerServiceImpl.java

示例14: getUsername

import play.mvc.Http.Context; //导入依赖的package包/类
@Override
public String getUsername(Context ctx) {
  String[] authTokenHeaderValues = ctx
      .request()
      .headers()
      .get(SecurityController.AUTH_TOKEN_HEADER.toLowerCase());
  if ((authTokenHeaderValues != null) && (authTokenHeaderValues.length == 1)
      && (authTokenHeaderValues[0] != null)) {
    User user = userService.getUserByAuthToken(authTokenHeaderValues[0]);
    if (isAuthenticatedUser(user)) {
      ctx.args.put("user", user);
      return user.getEmail();
    }
  }
  return null;
}
 
开发者ID:Coderaio,项目名称:sample-play-angular-app,代码行数:17,代码来源:Secured.java

示例15: renderTemplate

import play.mvc.Http.Context; //导入依赖的package包/类
@Test
public void renderTemplate() throws InstantiationException, IllegalAccessException {
    Request requestMock = mock(Request.class);

    Context.current.set(new Context(1l, mock(RequestHeader.class), requestMock, //
            Collections.<String, String>emptyMap(), // sessionData
            Collections.<String, String>emptyMap(), // flashData
            Collections.<String, Object>emptyMap()));

    when(requestMock.username()).thenReturn("nom_de_test");

    Html html = views.html.index.render("Your new application is ready.");
    assertThat(contentType(html)).isEqualTo("text/html");
    assertThat(contentAsString(html)).contains("Your new application is ready.");
    assertThat(contentAsString(html)).contains("Bonjour nom_de_test!");
}
 
开发者ID:fmaturel,项目名称:PlayTraining,代码行数:17,代码来源:ApplicationTest.java


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