01: /*
02: * Copyright 2002-2005 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package info.jtrac.wicket;
18:
19: import info.jtrac.domain.ItemSearch;
20: import info.jtrac.domain.Space;
21: import info.jtrac.domain.User;
22: import org.apache.wicket.protocol.http.servlet.ServletWebRequest;
23: import org.springframework.util.StringUtils;
24: import org.apache.wicket.Request;
25: import org.apache.wicket.protocol.http.WebApplication;
26: import org.apache.wicket.protocol.http.WebSession;
27:
28: /**
29: * custom wicket session for JTrac
30: */
31: public class JtracSession extends WebSession {
32:
33: private User user;
34: private Space currentSpace;
35: private ItemSearch itemSearch;
36:
37: public JtracSession(final WebApplication application,
38: Request request) {
39: super (application, request);
40: int timeOut = ((JtracApplication) application).getJtrac()
41: .getSessionTimeoutInMinutes();
42: ((ServletWebRequest) request).getHttpServletRequest()
43: .getSession().setMaxInactiveInterval(timeOut * 60);
44: }
45:
46: public void setUser(User user) {
47: this .user = user;
48: if (user.getLocale() == null) {
49: // for downward compatibility, may be null in old JTrac versions
50: user.setLocale(((JtracApplication) getApplication())
51: .getJtrac().getDefaultLocale());
52: }
53: // flip locale only if different from existing
54: if (!getLocale().getDisplayName().equals(user.getLocale())) {
55: setLocale(StringUtils.parseLocaleString(user.getLocale()));
56: }
57: }
58:
59: public User getUser() {
60: return user;
61: }
62:
63: public boolean isAuthenticated() {
64: return user != null;
65: }
66:
67: public Space getCurrentSpace() {
68: return currentSpace;
69: }
70:
71: public void setCurrentSpace(Space currentSpace) {
72: this .currentSpace = currentSpace;
73: }
74:
75: public ItemSearch getItemSearch() {
76: return itemSearch;
77: }
78:
79: public void setItemSearch(ItemSearch itemSearch) {
80: this.itemSearch = itemSearch;
81: }
82:
83: }
|