Search in sources :

Example 6 with Session

use of com.willshex.blogwt.shared.api.datatype.Session in project blogwt by billy1380.

the class Response method fromJson.

@Override
public void fromJson(JsonObject jsonObject) {
    super.fromJson(jsonObject);
    if (jsonObject.has("status")) {
        JsonElement jsonStatus = jsonObject.get("status");
        if (jsonStatus != null) {
            status = StatusType.fromString(jsonStatus.getAsString());
        }
    }
    if (jsonObject.has("error")) {
        JsonElement jsonError = jsonObject.get("error");
        if (jsonError != null) {
            error = new Error();
            error.fromJson(jsonError.getAsJsonObject());
        }
    }
    if (jsonObject.has("session")) {
        JsonElement jsonSession = jsonObject.get("session");
        if (jsonSession != null) {
            session = new Session();
            session.fromJson(jsonSession.getAsJsonObject());
        }
    }
}
Also used : JsonElement(com.google.gson.JsonElement) Error(com.willshex.gson.web.service.shared.Error) Session(com.willshex.blogwt.shared.api.datatype.Session)

Example 7 with Session

use of com.willshex.blogwt.shared.api.datatype.Session in project blogwt by billy1380.

the class HeaderPart method onAttach.

/* (non-Javadoc)
	 * 
	 * @see com.google.gwt.user.client.ui.Composite#onAttach() */
@Override
protected void onAttach() {
    super.onAttach();
    register(DefaultEventBus.get().addHandlerToSource(LoginEventHandler.TYPE, SessionController.get(), this));
    register(DefaultEventBus.get().addHandlerToSource(LogoutEventHandler.TYPE, SessionController.get(), this));
    register(DefaultEventBus.get().addHandlerToSource(NavigationChangedEventHandler.TYPE, NavigationController.get(), (p, c) -> {
        if (p != null) {
            activateItem(p.getPage(), false, this::getItem);
        }
        activateItem(c.getPage(), true, this::getItem);
        btnNavExpand.hide();
        GoogleAnalyticsHelper.sendPageView("#" + c.toString());
    }));
    register(RootPanel.get().addDomHandler(this, ClickEvent.getType()));
    register(DefaultEventBus.get().addHandlerToSource(ChangeUserDetailsEventHandler.TYPE, UserController.get(), this));
    Session session = SessionController.get().session();
    if (session != null && session.user != null) {
        setLoggedInUser(session.user);
    } else {
        configureNavBar(false);
    }
}
Also used : Anchor(com.google.gwt.user.client.ui.Anchor) Page(com.willshex.blogwt.shared.api.datatype.Page) Image(com.google.gwt.user.client.ui.Image) Event(com.google.gwt.user.client.Event) PageType(com.willshex.blogwt.shared.page.PageType) UiBinder(com.google.gwt.uibinder.client.UiBinder) SessionController(com.willshex.blogwt.client.controller.SessionController) InlineHyperlink(com.google.gwt.user.client.ui.InlineHyperlink) Map(java.util.Map) UserController(com.willshex.blogwt.client.controller.UserController) LogoutRequest(com.willshex.blogwt.shared.api.user.call.LogoutRequest) Permission(com.willshex.blogwt.shared.api.datatype.Permission) ChangeUserDetailsRequest(com.willshex.blogwt.shared.api.user.call.ChangeUserDetailsRequest) PageController(com.willshex.blogwt.client.controller.PageController) UserHelper(com.willshex.blogwt.shared.helper.UserHelper) PropertyController(com.willshex.blogwt.client.controller.PropertyController) RootPanel(com.google.gwt.user.client.ui.RootPanel) PropertyHelper(com.willshex.blogwt.shared.helper.PropertyHelper) UiHelper.activateItem(com.willshex.blogwt.client.helper.UiHelper.activateItem) List(java.util.List) Widget(com.google.gwt.user.client.ui.Widget) ChangeUserDetailsEventHandler(com.willshex.blogwt.client.api.user.event.ChangeUserDetailsEventHandler) GoogleAnalyticsHelper(com.willshex.blogwt.client.helper.GoogleAnalyticsHelper) UiField(com.google.gwt.uibinder.client.UiField) Element(com.google.gwt.dom.client.Element) PageTypeHelper(com.willshex.blogwt.client.helper.PageTypeHelper) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) EventListener(com.google.gwt.user.client.EventListener) User(com.willshex.blogwt.shared.api.datatype.User) Session(com.willshex.blogwt.shared.api.datatype.Session) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) NavigationChangedEventHandler(com.willshex.blogwt.client.event.NavigationChangedEventHandler) RegisteringComposite(com.willshex.blogwt.client.gwt.RegisteringComposite) HashMap(java.util.HashMap) Resources(com.willshex.blogwt.client.Resources) GWT(com.google.gwt.core.client.GWT) AnchorElement(com.google.gwt.dom.client.AnchorElement) LoginEventHandler(com.willshex.blogwt.client.api.user.event.LoginEventHandler) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) LogoutEventHandler(com.willshex.blogwt.client.api.user.event.LogoutEventHandler) DataTypeHelper(com.willshex.blogwt.shared.helper.DataTypeHelper) SafeHtmlTemplates(com.google.gwt.safehtml.client.SafeHtmlTemplates) LogoutResponse(com.willshex.blogwt.shared.api.user.call.LogoutResponse) StatusType(com.willshex.gson.web.service.shared.StatusType) ImageElement(com.google.gwt.dom.client.ImageElement) SafeHtmlUtils(com.google.gwt.safehtml.shared.SafeHtmlUtils) HTMLPanel(com.google.gwt.user.client.ui.HTMLPanel) PermissionHelper(com.willshex.blogwt.shared.helper.PermissionHelper) ChangeUserDetailsResponse(com.willshex.blogwt.shared.api.user.call.ChangeUserDetailsResponse) SafeUri(com.google.gwt.safehtml.shared.SafeUri) LoginRequest(com.willshex.blogwt.shared.api.user.call.LoginRequest) LoginResponse(com.willshex.blogwt.shared.api.user.call.LoginResponse) NavigationController(com.willshex.blogwt.client.controller.NavigationController) DefaultEventBus(com.willshex.blogwt.client.DefaultEventBus) Document(com.google.gwt.dom.client.Document) Session(com.willshex.blogwt.shared.api.datatype.Session)

Example 8 with Session

use of com.willshex.blogwt.shared.api.datatype.Session in project blogwt by billy1380.

the class SessionValidator method lookupCheckAndExtend.

public static Session lookupCheckAndExtend(Session session, String name) throws ServiceException {
    Session lookupSession = lookup(session, name);
    Date now = new Date();
    if (lookupSession.expires.getTime() < now.getTime())
        throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, TYPE + ": " + name);
    lookupSession.user = UserServiceProvider.provide().getUser(keyToId(lookupSession.userKey));
    UserValidator.suspended(lookupSession.user);
    if ((lookupSession.expires.getTime() - now.getTime()) < ISessionService.MILLIS_MINUTES) {
        lookupSession = SessionServiceProvider.provide().extendSession(lookupSession);
    }
    return lookupSession;
}
Also used : InputValidationException(com.willshex.gson.web.service.server.InputValidationException) Date(java.util.Date) Session(com.willshex.blogwt.shared.api.datatype.Session)

Example 9 with Session

use of com.willshex.blogwt.shared.api.datatype.Session in project blogwt by billy1380.

the class ServletHelper method session.

public static Session session(HttpServletRequest request) {
    ISessionService sessionService = SessionServiceProvider.provide();
    Cookie[] cookies = request.getCookies();
    String sessionId = null;
    Session userSession = null;
    if (cookies != null) {
        for (Cookie currentCookie : cookies) {
            if ("session.id".equals(currentCookie.getName())) {
                sessionId = currentCookie.getValue();
                break;
            }
        }
        if (sessionId != null) {
            userSession = sessionService.getSession(Long.valueOf(sessionId));
            if (userSession != null) {
                try {
                    userSession = SessionValidator.lookupCheckAndExtend(userSession, "session");
                    UserHelper.stripPassword(userSession.user);
                    UserHelper.populateRolesAndPermissionsFromKeys(userSession.user);
                } catch (ServiceException e) {
                    userSession = null;
                }
            }
        }
    }
    return userSession;
}
Also used : Cookie(javax.servlet.http.Cookie) ServiceException(com.willshex.gson.web.service.server.ServiceException) ISessionService(com.willshex.blogwt.server.service.session.ISessionService) Session(com.willshex.blogwt.shared.api.datatype.Session)

Example 10 with Session

use of com.willshex.blogwt.shared.api.datatype.Session in project blogwt by billy1380.

the class SessionService method getUserSession.

/* (non-Javadoc)
	 * 
	 * @see com.willshex.blogwt.server.services.session.ISessionService
	 * #getUserSession(com.willshex.blogwt.shared.api.datatypes.User) */
@Override
public Session getUserSession(User user) {
    Session session = PersistenceHelper.one(load().filter("userKey", user));
    if (session != null && session.expires.getTime() < new Date().getTime()) {
        deleteSession(session);
        session = null;
    }
    return session;
}
Also used : Date(java.util.Date) Session(com.willshex.blogwt.shared.api.datatype.Session)

Aggregations

Session (com.willshex.blogwt.shared.api.datatype.Session)10 Date (java.util.Date)3 JsonElement (com.google.gson.JsonElement)2 GWT (com.google.gwt.core.client.GWT)1 AnchorElement (com.google.gwt.dom.client.AnchorElement)1 Document (com.google.gwt.dom.client.Document)1 Element (com.google.gwt.dom.client.Element)1 ImageElement (com.google.gwt.dom.client.ImageElement)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 SafeHtmlTemplates (com.google.gwt.safehtml.client.SafeHtmlTemplates)1 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1 SafeHtmlUtils (com.google.gwt.safehtml.shared.SafeHtmlUtils)1 SafeUri (com.google.gwt.safehtml.shared.SafeUri)1 UiBinder (com.google.gwt.uibinder.client.UiBinder)1 UiField (com.google.gwt.uibinder.client.UiField)1 Event (com.google.gwt.user.client.Event)1 EventListener (com.google.gwt.user.client.EventListener)1 Anchor (com.google.gwt.user.client.ui.Anchor)1 HTMLPanel (com.google.gwt.user.client.ui.HTMLPanel)1