Java 类play.mvc.Http.Session 实例源码

项目:play-samlsso    文件:SSOSessionStorageHelper.java   
/**
 * Create a new SSO session.
 * @param session Play session object.
 * @return new SSO sessions's id.
 */
public static String createSession(final Session session){
    String sessionId = session.get(Constants.SSO_SESSION_ID);

    if(sessionId == null){
        sessionId = UUID.randomUUID().toString();
        session.put(Constants.SSO_SESSION_ID, sessionId);

        if(log.isDebugEnabled()){
            log.debug(String.format("No session was found. Created new session with ID %s ", sessionId));
        }
    } else {
        if(log.isDebugEnabled()){
            log.debug(String.format("Session with ID %s found", sessionId));
        }
    }

    return sessionId;
}
项目:play-samlsso    文件:SAMLSSOAuthenticationAction.java   
@Override
@SuppressWarnings("unchecked")
public Promise<SimpleResult> call(Http.Context ctx) throws Throwable {
    Session session = ctx.session();
    String sessionId = null;
    String tagrgetUrl = ctx.request().uri();
    String absoluteTargetUrl = getAbsoluteUrl(tagrgetUrl, ctx);

    if(!SSOSessionStorageHelper.isSSOSessionExists(session)){
        sessionId = SSOSessionStorageHelper.createSession(session);
    } else {
        sessionId = SSOSessionStorageHelper.getSessionId(session);
    }

    // Check whether user profile information there and initiate SSO process
    UserProfile userProfile = SSOSessionStorageHelper.getUserProfile(sessionId);

    if(userProfile == null){
        return SAMLSSOManager.INSTANCE.buildAuthenticationRequest(ctx, absoluteTargetUrl);
    }

    return delegate.call(ctx);
}
项目:play2-prototypen    文件:GameController.java   
/**
 * Controller Action for initiating the web socket.
 */
public static WebSocket<JsonNode> initializeSinglePlayerGame(final Long game) {

    final Session session = session();

    return new WebSocket<JsonNode>() {

        public void onReady(WebSocket.In<JsonNode> in,
                WebSocket.Out<JsonNode> out) {
            try {
                SinglePlayerGameHall.join(game,
                        UserService.getAuthUserName(session), in, out);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    };
}
项目:play2-prototypen    文件:UserService.java   
/**
 * Returns the language configured with the given {@link Session}. If there
 * is no language configured, the first language matching an application
 * supported and browser accepted language is returned. If there is no match
 * found, the first application supported language is returned.
 * 
 * @param session
 *            The session the language is registered with.
 * @param request
 *            The current HTTP request need for accing browser accepted
 *            langugages.
 * @return The {@link Lang}.
 */
public static Lang getSessionLanguage(Session session, Request request) {

    // session language
    String sLang = session.get("lang");
    if (sLang != null)
        return play.i18n.Lang.forCode(sLang).underlyingLang;

    // matching application supported and browser accepted language
    if (sLang == null) {
        String sSupportedLangs = play.Play.application().configuration()
                .getString("application.langs");
        List<play.i18n.Lang> acceptedLangs = request.acceptLanguages();
        for (play.i18n.Lang acceptedLang : acceptedLangs) {
            for (String sSupportedLang : sSupportedLangs.split(",")) {
                if (acceptedLang.code().compareTo(sSupportedLang) == 0)
                    return acceptedLang.underlyingLang;
            }
        }
    }

    // no matching between supported and accepted languages found: return
    // the first configured language
    return Lang.defaultLang();
}
项目:play2-prototypen    文件:UserService.java   
/**
 * Authenticates and returns an instance of {@link User} for the case the
 * user is already registered.
 * 
 * If the user isn't registered yet this operation will dynamically create
 * an anonymous user identified by parameter username.
 * 
 * @param session
 *            The {@link Session} the user has to be authenticated with.
 * @param username
 *            The user name to be authenticated.
 * @return The {@link User}.
 */
public static User authenticate(Session session, String username) {

    User authUser = findUser(username);

    // if the user is not regisitered
    if (authUser == null)
        // dynamically create an anonymous user
        authUser = UserService.createAnonymousUser(username);

    // register user id with session
    session.put("username", authUser.name);

    return authUser;
}
项目:play2-prototypen    文件:UserManagementImpl.java   
@Override
public Lang getSessionLanguage(Session session) {
    String lang = getLoggedUser(session).language;
    if(lang!=null)
        return Lang.apply(lang);
    else
        return getConfiguredLanguages().get(0);
}
项目:songs_play    文件:UserProvider.java   
@Nullable
public User getUser(Session session) {
    final AuthUser currentAuthUser = this.auth.getUser(session);
    final User localUser = User.findByAuthUserIdentity(currentAuthUser);
    return localUser;
}
项目:demschooltools    文件:Secured.java   
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;
 }
项目:gsn    文件:LocalAuthController.java   
public static User getLocalUser(final Session session) {
    final AuthUser currentAuthUser = PlayAuthenticate.getUser(session);
    final User localUser = User.findByAuthUserIdentity(currentAuthUser);
    return localUser;
}
项目:play2-prototypen    文件:UserService.java   
/**
 * Returns the authenticated users name.
 * 
 * @param session
 *            The Session the user is authenticated with.
 * @return The authenticated {@link User}'s name or null if the {@link User}
 *         could not be found.
 */
public static String getAuthUserName(Session session) {
    User authUser = getAuthUser(session);
    if (authUser != null)
        return authUser.name;
    else
        return null;
}
项目:play2-prototypen    文件:UserManagementImpl.java   
/**
 * Return the currently authenticated {@link User}, whose UUID is stored
 * inside the {@link Session}.
 * 
 * @param session
 * @return
 */
@Override
public User getLoggedUser(Session session) {
    final AuthUser currentAuthUser = PlayAuthenticate.getUser(session);
    final User localUser = User.findByAuthUserIdentity(currentAuthUser);
    return localUser;
}
项目:play-samlsso    文件:SSOSessionStorageHelper.java   
/**
 * Check for existing session.
 * @param session Play session object.
 * @return true if SSO session exists or false otherwise.
 */
public static boolean isSSOSessionExists(final Session session){
    return session.containsKey(Constants.SSO_SESSION_ID) && session.get(Constants.SSO_SESSION_ID) != null;
}
项目:play-samlsso    文件:SSOSessionStorageHelper.java   
/**
 * Get the current session id.
 * @param session Play session object.
 * @return ID of the current SSO session.
 */
public static String getSessionId(final Session session){
    return session.get(Constants.SSO_SESSION_ID);
}
项目:play2-prototypen    文件:UserService.java   
/**
 * Sets the session specific language.
 * 
 * @param session
 *            The {@link Session}.
 * @param id
 *            The language code ID.
 */
public static void setSessionLang(Session session, String id) {
    session.put("lang", id);
}
项目:play2-prototypen    文件:UserService.java   
/**
 * This Operation returns the currently authenticated {@link User}.
 * 
 * @param session
 *            The Session the user is authenticated with.
 * @return The {@link User}.
 */
public static User getAuthUser(Session session) {
    return findUser(session.get("username"));
}
项目:play2-prototypen    文件:UserManagementService.java   
/**
 * Gib den aktuell eingeloggten Nutzer zurück oder <code>null</code> wenn
 * kein Nutzer eingeloggt.
 * 
 * @return
 */
public models.common.User getLoggedUser(Session session);
项目:play2-prototypen    文件:UserManagementService.java   
/**
 * Gib die aktuell gewählte Sprache zurück.
 * 
 * @param session
 * @return
 */
public Lang getSessionLanguage(Session session);
项目:play2-prototypen    文件:Application.java   
/**
 * Return the currently authenticated {@link User}, whose UUID is stored
 * inside the {@link Session}.
 * 
 * @param session
 * @return
 */
public static User getLocalUser(final Session session) {
    final AuthUser currentAuthUser = PlayAuthenticate.getUser(session);
    final User localUser = User.findByAuthUserIdentity(currentAuthUser);
    return localUser;
}