All Downloads are FREE. Search and download functionalities are using the official Maven repository.

leap.oauth2.server.OAuth2ExpirableEntity Maven / Gradle / Ivy

There is a newer version: 0.7.13b
Show newest version
/*
 * Copyright 2015 the original author or authors.
 *
 * Licensed 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
 *
 *      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 leap.oauth2.server;

import java.sql.Timestamp;

import leap.lang.expirable.TimeExpirable;

public abstract class OAuth2ExpirableEntity implements OAuth2Entity {

    @Created
    protected Timestamp created;

    @Expiration
    protected Timestamp expiration;

    public Timestamp getCreated() {
        return created;
    }
    
    public long getCreatedMs() {
        return created.getTime();
    }

    public void setCreated(Timestamp created) {
        this.created = created;
    }
    
    public void setCreatedMs(long created) {
        this.created = new Timestamp(created);
    }

    public Timestamp getExpiration() {
        return expiration;
    }
    
    public long getExpirationMs() {
        return expiration.getTime();
    }
    
    public void setExpiration(Timestamp expiration) {
        this.expiration = expiration;
    }

    public void setExpirationMs(long expiration) {
        this.expiration = new Timestamp(expiration);
    }
    
    public void setExpirationByExpiresIn(int expiresIn) {
        this.setExpirationMs(created.getTime() + expiresIn * 1000L);
    }
    
    public int getExpiresIn() {
        return (int)((getExpirationMs() - created.getTime()) / 1000L);
    }

    public void setTimeExpirable(TimeExpirable te) {
        setCreatedMs(te.getCreated());
        setExpirationByExpiresIn(te.getExpiresIn());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy