PageRenderTime 37ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/java/org/expressme/openid/Association.java

http://jopenid.googlecode.com/
Java | 105 lines | 44 code | 17 blank | 44 comment | 0 complexity | 452b2c0ded897b2361b3924e26e968cd MD5 | raw file
  1. package org.expressme.openid;
  2. import java.text.SimpleDateFormat;
  3. /**
  4. * Assocation between RP and OP, and will be cached in memory for a certain time.
  5. *
  6. * @author Michael Liao (askxuefeng@gmail.com)
  7. */
  8. public class Association {
  9. /**
  10. * Session type constant "no-encryption".
  11. */
  12. public static final String SESSION_TYPE_NO_ENCRYPTION = "no-encryption";
  13. /**
  14. * Association type constant "HMAC-SHA1".
  15. */
  16. public static final String ASSOC_TYPE_HMAC_SHA1 = "HMAC-SHA1";
  17. private String session_type;
  18. private String assoc_type;
  19. private String assoc_handle;
  20. private String mac_key;
  21. private byte[] raw_mac_key;
  22. private long expired;
  23. /**
  24. * Get session type.
  25. */
  26. public String getSessionType() { return session_type; }
  27. /**
  28. * Set session type.
  29. */
  30. public void setSessionType(String session_type) { this.session_type = session_type; }
  31. /**
  32. * Get association type.
  33. */
  34. public String getAssociationType() { return assoc_type; }
  35. /**
  36. * Set association type.
  37. */
  38. public void setAssociationType(String assoc_type) { this.assoc_type = assoc_type; }
  39. /**
  40. * Get association handle.
  41. */
  42. public String getAssociationHandle() { return assoc_handle; }
  43. /**
  44. * Set association handle.
  45. */
  46. public void setAssociationHandle(String assoc_handle) { this.assoc_handle = assoc_handle; }
  47. /**
  48. * Get MAC key.
  49. */
  50. public String getMacKey() { return mac_key; }
  51. /**
  52. * Set MAC key.
  53. */
  54. public void setMacKey(String mac_key) {
  55. this.mac_key = mac_key;
  56. this.raw_mac_key = Base64.decode(mac_key);
  57. }
  58. /**
  59. * Get raw MAC key as bytes.
  60. */
  61. public byte[] getRawMacKey() {
  62. return raw_mac_key;
  63. }
  64. /**
  65. * Set max age in milliseconds.
  66. */
  67. public void setMaxAge(long maxAgeInMilliseconds) {
  68. this.expired = System.currentTimeMillis() + maxAgeInMilliseconds;
  69. }
  70. /**
  71. * Detect if this association is expired.
  72. */
  73. public boolean isExpired() {
  74. return System.currentTimeMillis() >= expired;
  75. }
  76. @Override
  77. public String toString() {
  78. StringBuilder sb = new StringBuilder(1024);
  79. sb.append("Association [")
  80. .append("session_type:").append(session_type).append(", ")
  81. .append("assoc_type:").append(assoc_type).append(", ")
  82. .append("assoc_handle:").append(assoc_handle).append(", ")
  83. .append("mac_key:").append(mac_key).append(", ")
  84. .append("expired:").append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(expired))
  85. .append(']');
  86. return sb.toString();
  87. }
  88. }