LoginInfoBean.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Password Management Servlets (PWM)
  3. * http://www.pwm-project.org
  4. *
  5. * Copyright (c) 2006-2009 Novell, Inc.
  6. * Copyright (c) 2009-2018 The PWM Project
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. package password.pwm.bean;
  23. import com.google.gson.annotations.SerializedName;
  24. import lombok.Data;
  25. import password.pwm.PwmConstants;
  26. import password.pwm.error.PwmUnrecoverableException;
  27. import password.pwm.ldap.auth.AuthenticationType;
  28. import password.pwm.ldap.auth.PwmAuthenticationSource;
  29. import password.pwm.util.BasicAuthInfo;
  30. import password.pwm.util.PasswordData;
  31. import password.pwm.util.java.JsonUtil;
  32. import java.io.Serializable;
  33. import java.time.Instant;
  34. import java.util.ArrayList;
  35. import java.util.HashSet;
  36. import java.util.List;
  37. import java.util.Set;
  38. /**
  39. * <p>This bean is synchronized across application sessions by {@code SessionLoginProvider}.</p>
  40. *
  41. * <p>Short serialized names are used to shrink the effective size of the login cookie.</p>
  42. */
  43. @Data
  44. public class LoginInfoBean implements Serializable
  45. {
  46. public enum LoginFlag
  47. {
  48. skipOtp,
  49. skipNewPw,
  50. skipSetupCr,
  51. // bypass sso
  52. noSso,
  53. authRecordSet,
  54. forcePwChange
  55. }
  56. @SerializedName( "u" )
  57. private UserIdentity userIdentity;
  58. @SerializedName( "a" )
  59. private boolean authenticated;
  60. @SerializedName( "p" )
  61. private PasswordData userCurrentPassword;
  62. @SerializedName( "t" )
  63. private AuthenticationType type = AuthenticationType.UNAUTHENTICATED;
  64. @SerializedName( "af" )
  65. private List<AuthenticationType> authFlags = new ArrayList<>();
  66. @SerializedName( "as" )
  67. private PwmAuthenticationSource authSource;
  68. @SerializedName( "at" )
  69. private Instant authTime;
  70. @SerializedName( "rq" )
  71. private Instant reqTime;
  72. @SerializedName( "g" )
  73. private String guid;
  74. @SerializedName( "ba" )
  75. private BasicAuthInfo basicAuth;
  76. @SerializedName( "oe" )
  77. private Instant oauthExp;
  78. @SerializedName( "or" )
  79. private String oauthRefToken;
  80. @SerializedName( "c" )
  81. private int reqCounter;
  82. @SerializedName( "lf" )
  83. private Set<LoginFlag> loginFlags = new HashSet<>();
  84. public boolean isLoginFlag( final LoginFlag loginStateFlag )
  85. {
  86. return loginFlags.contains( loginStateFlag );
  87. }
  88. public void setFlag( final LoginFlag loginFlag )
  89. {
  90. loginFlags.add( loginFlag );
  91. }
  92. public void removeFlag( final LoginFlag loginFlag )
  93. {
  94. loginFlags.remove( loginFlag );
  95. }
  96. public String toDebugString( ) throws PwmUnrecoverableException
  97. {
  98. final LoginInfoBean debugLoginCookieBean = JsonUtil.cloneUsingJson( this, LoginInfoBean.class );
  99. debugLoginCookieBean.setUserCurrentPassword( new PasswordData( PwmConstants.LOG_REMOVED_VALUE_REPLACEMENT ) );
  100. return JsonUtil.serialize( debugLoginCookieBean );
  101. }
  102. }