2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
22 package org.onap.aaf.cadi.oauth;
24 import java.nio.file.Path;
26 import org.onap.aaf.cadi.persist.Persist;
27 import org.onap.aaf.cadi.persist.Persistable;
28 import org.onap.aaf.cadi.persist.Persisting;
30 import aafoauth.v2_0.Token;
34 * Tokens come from the Token Server with an "Expired In" setting. This class will take that, and
35 * create a date from time of Creation, which works with local code.
37 * We create a Derived class, so that it can be used as is the originating Token type.
39 * "expired" is local computer time
44 public class TimedToken extends Token implements Persistable<Token> {
45 private Persisting<Token> cacheable; // no double inheritance...
47 // public TimedToken(Token t, byte[] hash) {
48 // this(t,(System.currentTimeMillis()/1000)+t.getExpiresIn(),hash,null);
51 public TimedToken(Persist<Token,?> p, Token t, byte[] hash, Path path){
52 this(p,t,t.getExpiresIn()+(System.currentTimeMillis()/1000),hash, path);
55 public TimedToken(Persist<Token,?> p, Token t, long expires_secsFrom1970, byte[] hash, Path path) {
56 cacheable = new Persisting<Token>(p, t,expires_secsFrom1970, hash, path);
57 accessToken=t.getAccessToken();
58 expiresIn=t.getExpiresIn();
59 refreshToken=t.getRefreshToken();
62 tokenType = t.getTokenType();
68 return cacheable.get();
72 public boolean checkSyncTime() {
73 return cacheable.checkSyncTime();
77 public boolean checkReloadable() {
78 return cacheable.checkReloadable();
82 public boolean hasBeenTouched() {
83 return cacheable.hasBeenTouched();
87 public long expires() {
88 return cacheable.expires();
92 public boolean expired() {
93 return cacheable.expired();
97 public boolean match(byte[] hashIn) {
98 return cacheable.match(hashIn);
102 public byte[] getHash() {
103 return cacheable.getHash();
113 return cacheable.count();
117 * @see org.onap.aaf.cadi.oauth.Persistable#clearCount()
120 public void clearCount() {
121 cacheable.clearCount();
125 * @see org.onap.aaf.cadi.persist.Persistable#path()
129 return cacheable.path();