/*
 * Licensed to Apereo under one or more contributor license
 * agreements. See the NOTICE file distributed with this work
 * for additional information regarding copyright ownership.
 * Apereo licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file
 * except in compliance with the License.  You may obtain a
 * copy of the License at the following location:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.jasig.cas.support.oauth.token;

import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import org.jasig.cas.authentication.principal.Service;
import org.jasig.cas.ticket.ServiceTicket;
import org.jasig.cas.ticket.ServiceTicketImpl;
import org.jasig.cas.ticket.Ticket;
import org.jasig.cas.ticket.TicketGrantingTicket;
import org.jasig.cas.ticket.TicketGrantingTicketImpl;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.Set;

/**
 * Access Token Implementation class.
 *
 * @author Michael Haselton
 * @since 4.1.0
 */
@Entity
@Table(name="ACCESSTOKEN")
public final class AccessTokenImpl extends AbstractToken implements AccessToken {

    /** Unique Id for serialization. */
    private static final long serialVersionUID = -2608145809180961597L;

    /** The TicketGrantingTicket this is associated with. */
    @OneToOne(targetEntity=TicketGrantingTicketImpl.class, orphanRemoval=true)
    @OnDelete(action= OnDeleteAction.CASCADE)
    private TicketGrantingTicket ticketGrantingTicket;

    /** The service associated with the tgt. */
    @Lob
    @Column(name="SERVICE")
    private Service service;

    /** The ServiceTicket this is associated with. */
    @OneToOne(targetEntity=ServiceTicketImpl.class, orphanRemoval=true)
    @OnDelete(action= OnDeleteAction.CASCADE)
    private ServiceTicket serviceTicket;

    /**
     * Instantiates a new access token impl.
     */
    public AccessTokenImpl() {
        // nothing to do
    }

    /**
     * Constructs a new AccessToken.
     *
     * @param id the id of the Ticket
     * @param type the token type
     * @param clientId the client id
     * @param principalId the principal id
     * @param ticketGrantingTicket the ticket granting ticket
     * @param service the service
     * @param serviceTicket the service ticket
     * @param scopes the granted scopes
     */
    public AccessTokenImpl(final String id, final TokenType type, final String clientId, final String principalId,
                           final TicketGrantingTicket ticketGrantingTicket, final Service service,
                           final ServiceTicket serviceTicket, final Set<String> scopes) {
        super(id, clientId, principalId, type, scopes);

        this.ticketGrantingTicket = ticketGrantingTicket;
        this.service = service;
        this.serviceTicket = serviceTicket;
    }

    @Override
    @Transient
    public Ticket getTicket() {
        if (getType() == TokenType.OFFLINE) {
            return this.serviceTicket;
        }

        return this.ticketGrantingTicket;
    }

    @Override
    public TicketGrantingTicket getTicketGrantingTicket() {
        if (getType() == TokenType.OFFLINE) {
            return this.serviceTicket.getGrantingTicket();
        }

        return this.ticketGrantingTicket;
    }

    @Override
    public Service getService() {
        return this.service;
    }

    @Override
    public ServiceTicket getServiceTicket() {
        return this.serviceTicket;
    }
}

@@ -928,16 +928,17 @@
 Action;%0A
+%0A
 import o
@@ -1215,16 +1215,86 @@
 tImpl;%0A%0A
+import javax.persistence.Access;%0Aimport javax.persistence.AccessType;%0A
 import j
@@ -1452,44 +1452,9 @@
 le;%0A
-import javax.persistence.Transient;
 %0A
+
 impo
@@ -1545,16 +1545,39 @@
 aselton%0A
+ * @author Longze Chen%0A
  * @sinc
@@ -1582,17 +1582,17 @@
 nce 4.1.
-0
+5
 %0A */%0A@En
@@ -1623,16 +1623,42 @@
 TOKEN%22)%0A
+@Access(AccessType.FIELD)%0A
 public f
@@ -2962,16 +2962,29 @@
 kenImpl(
+%0A            
 final St
@@ -2991,16 +2991,28 @@
 ring id,
+%0A           
  final T
@@ -3025,16 +3025,28 @@
 pe type,
+%0A           
  final S
@@ -3060,16 +3060,28 @@
 lientId,
+%0A           
  final S
@@ -3107,39 +3107,24 @@
             
-     
-          
 final Ticket
@@ -3155,24 +3155,36 @@
 ntingTicket,
+%0A           
  final Servi
@@ -3207,31 +3207,16 @@
         
-     
-          
 final Se
@@ -3241,16 +3241,28 @@
 eTicket,
+%0A           
  final S
@@ -3278,16 +3278,21 @@
 %3E scopes
+%0A    
 ) %7B%0A    
@@ -3503,23 +3503,8 @@
 ide%0A
-    @Transient%0A
     
@@ -3618,33 +3618,32 @@
 cket;%0A        %7D%0A
-%0A
         return t
@@ -3854,16 +3854,16 @@
 cket();%0A
+
         
@@ -3860,25 +3860,24 @@
 ;%0A        %7D%0A
-%0A
         retu

Fix oauth revoke - part 1