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@Entity
034@Table(name = "authentication_holder")
035@NamedQueries ({
036    @NamedQuery(name = "AuthenticationHolderEntity.getAll", query = "select a from AuthenticationHolderEntity a"),
037        @NamedQuery(name = "AuthenticationHolderEntity.getByAuthentication", query = "select a from AuthenticationHolderEntity a where a.authentication = :authentication"),
038        @NamedQuery(name = "AuthenticationHolderEntity.getUnusedAuthenticationHolders", query = "select a from AuthenticationHolderEntity a where a.id not in (select t.authenticationHolder.id from OAuth2AccessTokenEntity t) and a.id not in (select r.authenticationHolder.id from OAuth2RefreshTokenEntity r)")
039})
040public class AuthenticationHolderEntity {
041
042        private Long id;
043
044        private Long ownerId;
045
046        private OAuth2Authentication authentication;
047
048        public AuthenticationHolderEntity() {
049
050        }
051
052        @Id
053        @GeneratedValue(strategy = GenerationType.IDENTITY)
054        @Column(name = "id")
055        public Long getId() {
056                return id;
057        }
058
059        public void setId(Long id) {
060                this.id = id;
061        }
062
063        @Basic
064        @Column(name = "owner_id")
065        public Long getOwnerId() {
066                return ownerId;
067        }
068
069        public void setOwnerId(Long owner_id) {
070                this.ownerId = owner_id;
071        }
072
073        @Lob
074        @Basic(fetch=FetchType.LAZY)
075        @Column(name = "authentication")
076        public OAuth2Authentication getAuthentication() {
077                return authentication;
078        }
079
080        public void setAuthentication(OAuth2Authentication authentication) {
081                this.authentication = authentication;
082        }
083
084
085
086}