X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cadi%2Faaf%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fcadi%2Fpersist%2FPersistFile.java;h=db9852ec2868b7e03df145af7b7620b11d62f5b0;hb=1296352d8eafee57f982a4342ad79ada4aa56d28;hp=7aab519d532bbc5c88d9afbbeeab70a4cb205f0c;hpb=4b5a7d721d994a49057e9bfb403c7bff1b376660;p=aaf%2Fauthz.git diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/persist/PersistFile.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/persist/PersistFile.java index 7aab519d..db9852ec 100644 --- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/persist/PersistFile.java +++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/persist/PersistFile.java @@ -7,9 +7,9 @@ * 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. @@ -52,19 +52,19 @@ public class PersistFile { private static final String HASH_NO_MATCH = "Hash does not match in Persistence"; private static final Object LOCK = new Object(); - + protected static Symm symm; public Access access; protected final Path tokenPath; protected final String tokenDir; private static final boolean isWindows = System.getProperty("os.name").startsWith("Windows"); - + public PersistFile(Access access, String sub_dir) throws CadiException, APIException { this.access = access; tokenPath = Paths.get(access.getProperty(Config.CADI_TOKEN_DIR,"tokens"), sub_dir); try { - if(!Files.exists(tokenPath)) { - if(isWindows) { + if (!Files.exists(tokenPath)) { + if (isWindows) { // Sorry Windows users, you need to secure your own paths Files.createDirectories(tokenPath); } else { @@ -77,7 +77,7 @@ public class PersistFile { throw new CadiException(e); } synchronized(LOCK) { - if(symm==null) { + if (symm==null) { symm = Symm.obtain(access); } } @@ -94,7 +94,7 @@ public class PersistFile { final OutputStream dos = Files.newOutputStream(tpath, StandardOpenOption.CREATE,StandardOpenOption.WRITE); try { // Write Expires so that we can read unencrypted. - for(int i=0;i>i)&0xFF)); } @@ -104,15 +104,15 @@ public class PersistFile { CipherOutputStream os = enc.outputStream(dos, true); try { int size = cred==null?0:cred.length; - for(int i=0;i>i)&0xFF)); } - if(cred!=null) { + if (cred!=null) { os.write(cred); } df.newData().load(t).to(os); } finally { - // Note: Someone on the Web noticed that using a DataOutputStream would not full close out without a flush first, + // Note: Someone on the Web noticed that using a DataOutputStream would not full close out without a flush first, // leaving files open. try { os.flush(); @@ -128,7 +128,7 @@ public class PersistFile { return null; } }); - } catch(Exception e) { + } catch (Exception e) { throw new CadiException(e); } finally { dos.close(); @@ -141,45 +141,45 @@ public class PersistFile { } public T readDisk(final RosettaDF df, final byte[] cred, final String filename,final Holder hp, final Holder hl) throws CadiException { - if(hp.get()==null) { + if (hp.get()==null) { hp.set(Paths.get(tokenDir,filename)); } return readDisk(df,cred,hp.get(),hl); } - + public T readDisk(final RosettaDF df, final byte[] cred, final Path target, final Holder hexpired) throws CadiException { // Try from Disk T t = null; - if(Files.exists(target)) { + if (Files.exists(target)) { try { final InputStream is = Files.newInputStream(target,StandardOpenOption.READ); try { // Read Expired unencrypted long exp=0; - for(int i=0;i() { @Override public T exec(Encryption enc) throws Exception { CipherInputStream dis = enc.inputStream(is,false); try { int size=0; - for(int i=0;i256) { + if (size>256) { throw new CadiException("Invalid size in Token Persistence"); - } else if(cred!=null && size!=cred.length) { + } else if (cred!=null && size!=cred.length) { throw new CadiException(HASH_NO_MATCH); } - if(cred!=null) { + if (cred!=null) { byte[] array = new byte[size]; - if(dis.read(array)>0) { - for(int i=0;i0) { + for (int i=0;i hp) throws IOException { Path p = hp.get(); - if(p==null) { + if (p==null) { hp.set(p=Paths.get(tokenDir,filename)); } return Files.getLastModifiedTime(p);