You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GitBlitWebSession.java 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright 2011 gitblit.com.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  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. package com.gitblit.wicket;
  17. import java.util.TimeZone;
  18. import org.apache.wicket.Request;
  19. import org.apache.wicket.Session;
  20. import org.apache.wicket.protocol.http.WebSession;
  21. import org.apache.wicket.protocol.http.request.WebClientInfo;
  22. import com.gitblit.wicket.models.UserModel;
  23. public final class GitBlitWebSession extends WebSession {
  24. private static final long serialVersionUID = 1L;
  25. protected TimeZone timezone = null;
  26. private UserModel user = null;
  27. private String errorMessage = null;
  28. public GitBlitWebSession(Request request) {
  29. super(request);
  30. }
  31. public void invalidate() {
  32. super.invalidate();
  33. user = null;
  34. }
  35. public boolean isLoggedIn() {
  36. return user != null;
  37. }
  38. public boolean canAdmin() {
  39. if (user == null) {
  40. return false;
  41. }
  42. return user.canAdmin();
  43. }
  44. public UserModel getUser() {
  45. return user;
  46. }
  47. public void setUser(UserModel user) {
  48. this.user = user;
  49. }
  50. public TimeZone getTimezone() {
  51. if (timezone == null) {
  52. timezone = ((WebClientInfo) getClientInfo()).getProperties().getTimeZone();
  53. }
  54. // use server timezone if we can't determine the client timezone
  55. if (timezone == null) {
  56. timezone = TimeZone.getDefault();
  57. }
  58. return timezone;
  59. }
  60. public void cacheErrorMessage(String message) {
  61. this.errorMessage = message;
  62. }
  63. public String clearErrorMessage() {
  64. String msg = errorMessage;
  65. errorMessage = null;
  66. return msg;
  67. }
  68. public static GitBlitWebSession get() {
  69. return (GitBlitWebSession) Session.get();
  70. }
  71. }