001/******************************************************************************* 002 * Copyright 2017 The MIT Internet Trust Consortium 003 * 004 * Portions copyright 2011-2013 The MITRE Corporation 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); 007 * you may not use this file except in compliance with the License. 008 * You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 *******************************************************************************/ 018package org.mitre.oauth2.model; 019 020import java.util.Date; 021 022import javax.persistence.Basic; 023import javax.persistence.Column; 024import javax.persistence.Entity; 025import javax.persistence.GeneratedValue; 026import javax.persistence.GenerationType; 027import javax.persistence.Id; 028import javax.persistence.JoinColumn; 029import javax.persistence.ManyToOne; 030import javax.persistence.NamedQueries; 031import javax.persistence.NamedQuery; 032import javax.persistence.Table; 033import javax.persistence.Temporal; 034 035/** 036 * Entity class for authorization codes 037 * 038 * @author aanganes 039 * 040 */ 041@Entity 042@Table(name = "authorization_code") 043@NamedQueries({ 044 @NamedQuery(name = AuthorizationCodeEntity.QUERY_BY_VALUE, query = "select a from AuthorizationCodeEntity a where a.code = :code"), 045 @NamedQuery(name = AuthorizationCodeEntity.QUERY_EXPIRATION_BY_DATE, query = "select a from AuthorizationCodeEntity a where a.expiration <= :" + AuthorizationCodeEntity.PARAM_DATE) 046}) 047public class AuthorizationCodeEntity { 048 049 public static final String QUERY_BY_VALUE = "AuthorizationCodeEntity.getByValue"; 050 public static final String QUERY_EXPIRATION_BY_DATE = "AuthorizationCodeEntity.expirationByDate"; 051 052 public static final String PARAM_DATE = "date"; 053 054 private Long id; 055 056 private String code; 057 058 private AuthenticationHolderEntity authenticationHolder; 059 060 private Date expiration; 061 062 /** 063 * Default constructor. 064 */ 065 public AuthorizationCodeEntity() { 066 067 } 068 069 /** 070 * Create a new AuthorizationCodeEntity with the given code and AuthorizationRequestHolder. 071 * 072 * @param code the authorization code 073 * @param authRequest the AuthoriztionRequestHolder associated with the original code request 074 */ 075 public AuthorizationCodeEntity(String code, AuthenticationHolderEntity authenticationHolder, Date expiration) { 076 this.code = code; 077 this.authenticationHolder = authenticationHolder; 078 this.expiration = expiration; 079 } 080 081 /** 082 * @return the id 083 */ 084 @Id 085 @GeneratedValue(strategy = GenerationType.IDENTITY) 086 @Column(name = "id") 087 public Long getId() { 088 return id; 089 } 090 091 /** 092 * @param id the id to set 093 */ 094 public void setId(Long id) { 095 this.id = id; 096 } 097 098 /** 099 * @return the code 100 */ 101 @Basic 102 @Column(name = "code") 103 public String getCode() { 104 return code; 105 } 106 107 /** 108 * @param code the code to set 109 */ 110 public void setCode(String code) { 111 this.code = code; 112 } 113 114 /** 115 * The authentication in place when this token was created. 116 * @return the authentication 117 */ 118 @ManyToOne 119 @JoinColumn(name = "auth_holder_id") 120 public AuthenticationHolderEntity getAuthenticationHolder() { 121 return authenticationHolder; 122 } 123 124 /** 125 * @param authentication the authentication to set 126 */ 127 public void setAuthenticationHolder(AuthenticationHolderEntity authenticationHolder) { 128 this.authenticationHolder = authenticationHolder; 129 } 130 131 @Basic 132 @Temporal(javax.persistence.TemporalType.TIMESTAMP) 133 @Column(name = "expiration") 134 public Date getExpiration() { 135 return expiration; 136 } 137 138 public void setExpiration(Date expiration) { 139 this.expiration = expiration; 140 } 141}