Advertisement
Guest User

file

a guest
Nov 25th, 2015
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.67 KB | None | 0 0
  1. /*
  2. * Decompiled with CFR 0_110.
  3. *
  4. * Could not load the following classes:
  5. * com.fasterxml.jackson.databind.annotation.JsonDeserialize
  6. * com.fasterxml.jackson.databind.annotation.JsonSerialize
  7. * com.google.common.collect.Sets
  8. * com.nimbusds.jwt.JWT
  9. * javax.persistence.Basic
  10. * javax.persistence.CascadeType
  11. * javax.persistence.CollectionTable
  12. * javax.persistence.Column
  13. * javax.persistence.Convert
  14. * javax.persistence.ElementCollection
  15. * javax.persistence.Entity
  16. * javax.persistence.FetchType
  17. * javax.persistence.GeneratedValue
  18. * javax.persistence.GenerationType
  19. * javax.persistence.Id
  20. * javax.persistence.JoinColumn
  21. * javax.persistence.JoinTable
  22. * javax.persistence.ManyToOne
  23. * javax.persistence.NamedQueries
  24. * javax.persistence.NamedQuery
  25. * javax.persistence.OneToMany
  26. * javax.persistence.OneToOne
  27. * javax.persistence.Table
  28. * javax.persistence.Temporal
  29. * javax.persistence.TemporalType
  30. * javax.persistence.Transient
  31. * org.codehaus.jackson.map.annotate.JsonDeserialize
  32. * org.codehaus.jackson.map.annotate.JsonSerialize
  33. * org.mitre.oauth2.model.AuthenticationHolderEntity
  34. * org.mitre.oauth2.model.ClientDetailsEntity
  35. * org.mitre.oauth2.model.OAuth2RefreshTokenEntity
  36. * org.mitre.oauth2.model.convert.JWTStringConverter
  37. * org.mitre.uma.model.Permission
  38. * org.smartplatforms.oauth2.LaunchContextEntity
  39. * org.springframework.security.oauth2.common.OAuth2AccessToken
  40. * org.springframework.security.oauth2.common.OAuth2AccessTokenJackson1Deserializer
  41. * org.springframework.security.oauth2.common.OAuth2AccessTokenJackson1Serializer
  42. * org.springframework.security.oauth2.common.OAuth2AccessTokenJackson2Deserializer
  43. * org.springframework.security.oauth2.common.OAuth2AccessTokenJackson2Serializer
  44. * org.springframework.security.oauth2.common.OAuth2RefreshToken
  45. */
  46. package org.mitre.oauth2.model;
  47.  
  48. import com.google.common.collect.Sets;
  49. import com.nimbusds.jwt.JWT;
  50. import java.util.Date;
  51. import java.util.HashMap;
  52. import java.util.Map;
  53. import java.util.Set;
  54. import javax.persistence.Basic;
  55. import javax.persistence.CascadeType;
  56. import javax.persistence.CollectionTable;
  57. import javax.persistence.Column;
  58. import javax.persistence.Convert;
  59. import javax.persistence.ElementCollection;
  60. import javax.persistence.Entity;
  61. import javax.persistence.FetchType;
  62. import javax.persistence.GeneratedValue;
  63. import javax.persistence.GenerationType;
  64. import javax.persistence.Id;
  65. import javax.persistence.JoinColumn;
  66. import javax.persistence.JoinTable;
  67. import javax.persistence.ManyToOne;
  68. import javax.persistence.NamedQueries;
  69. import javax.persistence.NamedQuery;
  70. import javax.persistence.OneToMany;
  71. import javax.persistence.OneToOne;
  72. import javax.persistence.Table;
  73. import javax.persistence.Temporal;
  74. import javax.persistence.TemporalType;
  75. import javax.persistence.Transient;
  76. import org.codehaus.jackson.map.annotate.JsonDeserialize;
  77. import org.codehaus.jackson.map.annotate.JsonSerialize;
  78. import org.mitre.oauth2.model.AuthenticationHolderEntity;
  79. import org.mitre.oauth2.model.ClientDetailsEntity;
  80. import org.mitre.oauth2.model.OAuth2RefreshTokenEntity;
  81. import org.mitre.oauth2.model.convert.JWTStringConverter;
  82. import org.mitre.uma.model.Permission;
  83. import org.smartplatforms.oauth2.LaunchContextEntity;
  84. import org.springframework.security.oauth2.common.OAuth2AccessToken;
  85. import org.springframework.security.oauth2.common.OAuth2AccessTokenJackson1Deserializer;
  86. import org.springframework.security.oauth2.common.OAuth2AccessTokenJackson1Serializer;
  87. import org.springframework.security.oauth2.common.OAuth2AccessTokenJackson2Deserializer;
  88. import org.springframework.security.oauth2.common.OAuth2AccessTokenJackson2Serializer;
  89. import org.springframework.security.oauth2.common.OAuth2RefreshToken;
  90.  
  91. @Entity
  92. @Table(name="access_token")
  93. @NamedQueries(value={@NamedQuery(name="OAuth2AccessTokenEntity.getAll", query="select a from OAuth2AccessTokenEntity a"), @NamedQuery(name="OAuth2AccessTokenEntity.getAllExpiredByDate", query="select a from OAuth2AccessTokenEntity a where a.expiration <= :date"), @NamedQuery(name="OAuth2AccessTokenEntity.getByRefreshToken", query="select a from OAuth2AccessTokenEntity a where a.refreshToken = :refreshToken"), @NamedQuery(name="OAuth2AccessTokenEntity.getByClient", query="select a from OAuth2AccessTokenEntity a where a.client = :client"), @NamedQuery(name="OAuth2AccessTokenEntity.getByIdToken", query="select a from OAuth2AccessTokenEntity a where a.idToken = :idToken"), @NamedQuery(name="OAuth2AccessTokenEntity.getByTokenValue", query="select a from OAuth2AccessTokenEntity a where a.jwt = :tokenValue"), @NamedQuery(name="OAuth2AccessTokenEntity.getByResourceSet", query="select a from OAuth2AccessTokenEntity a join a.permissions p where p.resourceSet.id = :rsid")})
  94. @JsonSerialize(using=OAuth2AccessTokenJackson1Serializer.class)
  95. @JsonDeserialize(using=OAuth2AccessTokenJackson1Deserializer.class)
  96. @com.fasterxml.jackson.databind.annotation.JsonSerialize(using=OAuth2AccessTokenJackson2Serializer.class)
  97. @com.fasterxml.jackson.databind.annotation.JsonDeserialize(using=OAuth2AccessTokenJackson2Deserializer.class)
  98. public class OAuth2AccessTokenEntity
  99. implements OAuth2AccessToken {
  100. public static final String QUERY_BY_TOKEN_VALUE = "OAuth2AccessTokenEntity.getByTokenValue";
  101. public static final String QUERY_BY_ID_TOKEN = "OAuth2AccessTokenEntity.getByIdToken";
  102. public static final String QUERY_BY_CLIENT = "OAuth2AccessTokenEntity.getByClient";
  103. public static final String QUERY_BY_REFRESH_TOKEN = "OAuth2AccessTokenEntity.getByRefreshToken";
  104. public static final String QUERY_EXPIRED_BY_DATE = "OAuth2AccessTokenEntity.getAllExpiredByDate";
  105. public static final String QUERY_ALL = "OAuth2AccessTokenEntity.getAll";
  106. public static final String QUERY_BY_RESOURCE_SET = "OAuth2AccessTokenEntity.getByResourceSet";
  107. public static final String PARAM_TOKEN_VALUE = "tokenValue";
  108. public static final String PARAM_ID_TOKEN = "idToken";
  109. public static final String PARAM_CLIENT = "client";
  110. public static final String PARAM_REFERSH_TOKEN = "refreshToken";
  111. public static final String PARAM_DATE = "date";
  112. public static final String PARAM_RESOURCE_SET_ID = "rsid";
  113. public static String ID_TOKEN_FIELD_NAME = "id_token";
  114. private Long id;
  115. private ClientDetailsEntity client;
  116. private AuthenticationHolderEntity authenticationHolder;
  117. private JWT jwtValue;
  118. private OAuth2AccessTokenEntity idToken;
  119. private Date expiration;
  120. private String tokenType = "Bearer";
  121. private OAuth2RefreshTokenEntity refreshToken;
  122. private Set<String> scope;
  123. private Set<Permission> permissions;
  124. private Set<LaunchContextEntity> launchContextParams = Sets.newHashSet();
  125.  
  126. @Id
  127. @GeneratedValue(strategy=GenerationType.IDENTITY)
  128. @Column(name="id")
  129. public Long getId() {
  130. return this.id;
  131. }
  132.  
  133. public void setId(Long id) {
  134. this.id = id;
  135. }
  136.  
  137. @Transient
  138. public Map<String, Object> getAdditionalInformation() {
  139. HashMap<String, Object> map = new HashMap<String, Object>();
  140. if (this.getIdToken() != null) {
  141. map.put(ID_TOKEN_FIELD_NAME, this.getIdTokenString());
  142. }
  143. if (this.getLaunchContext() != null) {
  144. for (LaunchContextEntity cparam : this.getLaunchContext()) {
  145. String val = cparam.getValue();
  146. if (val.equals("true")) {
  147. map.put(cparam.getName(), true);
  148. continue;
  149. }
  150. if (val.equals("false")) {
  151. map.put(cparam.getName(), false);
  152. continue;
  153. }
  154. map.put(cparam.getName(), val);
  155. }
  156. }
  157. return map;
  158. }
  159.  
  160. @ManyToOne
  161. @JoinColumn(name="auth_holder_id")
  162. public AuthenticationHolderEntity getAuthenticationHolder() {
  163. return this.authenticationHolder;
  164. }
  165.  
  166. public void setAuthenticationHolder(AuthenticationHolderEntity authenticationHolder) {
  167. this.authenticationHolder = authenticationHolder;
  168. }
  169.  
  170. @ManyToOne
  171. @JoinColumn(name="client_id")
  172. public ClientDetailsEntity getClient() {
  173. return this.client;
  174. }
  175.  
  176. public void setClient(ClientDetailsEntity client) {
  177. this.client = client;
  178. }
  179.  
  180. @Transient
  181. public String getValue() {
  182. return this.jwtValue.serialize();
  183. }
  184.  
  185. @Basic
  186. @Temporal(value=TemporalType.TIMESTAMP)
  187. @Column(name="expiration")
  188. public Date getExpiration() {
  189. return this.expiration;
  190. }
  191.  
  192. public void setExpiration(Date expiration) {
  193. this.expiration = expiration;
  194. }
  195.  
  196. @Basic
  197. @Column(name="token_type")
  198. public String getTokenType() {
  199. return this.tokenType;
  200. }
  201.  
  202. public void setTokenType(String tokenType) {
  203. this.tokenType = tokenType;
  204. }
  205.  
  206. @ManyToOne
  207. @JoinColumn(name="refresh_token_id")
  208. public OAuth2RefreshTokenEntity getRefreshToken() {
  209. return this.refreshToken;
  210. }
  211.  
  212. public void setRefreshToken(OAuth2RefreshTokenEntity refreshToken) {
  213. this.refreshToken = refreshToken;
  214. }
  215.  
  216. public void setRefreshToken(OAuth2RefreshToken refreshToken) {
  217. if (!(refreshToken instanceof OAuth2RefreshTokenEntity)) {
  218. throw new IllegalArgumentException("Not a storable refresh token entity!");
  219. }
  220. this.setRefreshToken((OAuth2RefreshTokenEntity)refreshToken);
  221. }
  222.  
  223. @ElementCollection(fetch=FetchType.EAGER)
  224. @CollectionTable(joinColumns={@JoinColumn(name="owner_id")}, name="token_scope")
  225. public Set<String> getScope() {
  226. return this.scope;
  227. }
  228.  
  229. public void setScope(Set<String> scope) {
  230. this.scope = scope;
  231. }
  232.  
  233. @Transient
  234. public boolean isExpired() {
  235. return this.getExpiration() == null ? false : System.currentTimeMillis() > this.getExpiration().getTime();
  236. }
  237.  
  238. @OneToOne(cascade={CascadeType.ALL})
  239. @JoinColumn(name="id_token_id")
  240. public OAuth2AccessTokenEntity getIdToken() {
  241. return this.idToken;
  242. }
  243.  
  244. public void setIdToken(OAuth2AccessTokenEntity idToken) {
  245. this.idToken = idToken;
  246. }
  247.  
  248. @Transient
  249. public String getIdTokenString() {
  250. if (this.idToken != null) {
  251. return this.idToken.getValue();
  252. }
  253. return null;
  254. }
  255.  
  256. @OneToMany(cascade={CascadeType.ALL}, fetch=FetchType.EAGER)
  257. @JoinColumn(name="access_token_id")
  258. public Set<LaunchContextEntity> getLaunchContext() {
  259. return this.launchContextParams;
  260. }
  261.  
  262. public void setLaunchContext(Set<LaunchContextEntity> launchContextParams) {
  263. this.launchContextParams = launchContextParams;
  264. }
  265.  
  266. @Basic
  267. @Column(name="token_value")
  268. @Convert(converter=JWTStringConverter.class)
  269. public JWT getJwt() {
  270. return this.jwtValue;
  271. }
  272.  
  273. public void setJwt(JWT jwt) {
  274. this.jwtValue = jwt;
  275. }
  276.  
  277. @Transient
  278. public int getExpiresIn() {
  279. if (this.getExpiration() == null) {
  280. return -1;
  281. }
  282. int secondsRemaining = (int)((this.getExpiration().getTime() - System.currentTimeMillis()) / 1000);
  283. if (this.isExpired()) {
  284. return 0;
  285. }
  286. return secondsRemaining;
  287. }
  288.  
  289. @OneToMany(fetch=FetchType.EAGER, cascade={CascadeType.ALL})
  290. @JoinTable(name="access_token_permissions", joinColumns={@JoinColumn(name="access_token_id")}, inverseJoinColumns={@JoinColumn(name="permission_id")})
  291. public Set<Permission> getPermissions() {
  292. return this.permissions;
  293. }
  294.  
  295. public void setPermissions(Set<Permission> permissions) {
  296. this.permissions = permissions;
  297. }
  298. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement