001/******************************************************************************* 002 * Copyright 2014 The MITRE Corporation 003 * and the MIT Kerberos and Internet Trust Consortium 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 ******************************************************************************/ 017package org.mitre.oauth2.model; 018 019import javax.persistence.Basic; 020import javax.persistence.Column; 021import javax.persistence.Entity; 022import javax.persistence.FetchType; 023import javax.persistence.GeneratedValue; 024import javax.persistence.GenerationType; 025import javax.persistence.Id; 026import javax.persistence.Lob; 027import javax.persistence.NamedQueries; 028import javax.persistence.NamedQuery; 029import javax.persistence.Table; 030 031import org.springframework.security.oauth2.provider.OAuth2Authentication; 032 033/** 034 * Entity class for authorization codes 035 * 036 * @author aanganes 037 * 038 */ 039@Entity 040@Table(name = "authorization_code") 041@NamedQueries({ 042 @NamedQuery(name = "AuthorizationCodeEntity.getByValue", query = "select a from AuthorizationCodeEntity a where a.code = :code") 043}) 044public class AuthorizationCodeEntity { 045 046 private Long id; 047 048 private String code; 049 050 private OAuth2Authentication authentication; 051 052 /** 053 * Default constructor. 054 */ 055 public AuthorizationCodeEntity() { 056 057 } 058 059 /** 060 * Create a new AuthorizationCodeEntity with the given code and AuthorizationRequestHolder. 061 * 062 * @param code the authorization code 063 * @param authRequest the AuthoriztionRequestHolder associated with the original code request 064 */ 065 public AuthorizationCodeEntity(String code, OAuth2Authentication authRequest) { 066 this.code = code; 067 this.authentication = authRequest; 068 } 069 070 /** 071 * @return the id 072 */ 073 @Id 074 @GeneratedValue(strategy = GenerationType.IDENTITY) 075 @Column(name = "id") 076 public Long getId() { 077 return id; 078 } 079 080 /** 081 * @param id the id to set 082 */ 083 public void setId(Long id) { 084 this.id = id; 085 } 086 087 /** 088 * @return the code 089 */ 090 @Basic 091 @Column(name = "code") 092 public String getCode() { 093 return code; 094 } 095 096 /** 097 * @param code the code to set 098 */ 099 public void setCode(String code) { 100 this.code = code; 101 } 102 103 /** 104 * @return the authentication 105 */ 106 @Lob 107 @Basic(fetch=FetchType.EAGER) 108 @Column(name="authentication") 109 public OAuth2Authentication getAuthentication() { 110 return authentication; 111 } 112 113 /** 114 * @param authentication the authentication to set 115 */ 116 public void setAuthentication(OAuth2Authentication authentication) { 117 this.authentication = authentication; 118 } 119 120}