X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cadi%2Fcore%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fcadi%2Fconfig%2FUsersDump.java;h=4f7db1ab9d8a2ea1d732251a2693e79ed5f5c80f;hb=1296352d8eafee57f982a4342ad79ada4aa56d28;hp=5aea719ef5052322fe5aae17ce3058344aaf1f41;hpb=01c17dafca7527ebd8d43d22babea6e2136fc706;p=aaf%2Fauthz.git diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/config/UsersDump.java b/cadi/core/src/main/java/org/onap/aaf/cadi/config/UsersDump.java index 5aea719e..4f7db1ab 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/config/UsersDump.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/config/UsersDump.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. @@ -36,127 +36,127 @@ import org.onap.aaf.cadi.lur.LocalLur; public class UsersDump { - /** - * @param args - */ - public static boolean write(OutputStream os, AbsUserCache lur) { - PrintStream ps; - if(os instanceof PrintStream) { - ps = (PrintStream)os; - } else { - ps = new PrintStream(os); - } - try { - ps.println(""); - ps.println(""); - ps.println(""); + /** + * @param args + */ + public static boolean write(OutputStream os, AbsUserCache lur) { + PrintStream ps; + if (os instanceof PrintStream) { + ps = (PrintStream)os; + } else { + ps = new PrintStream(os); + } + try { + ps.println(""); + ps.println(""); + ps.println(""); + + // We loop through Users, but want to write Groups first... therefore, save off print + StringBuilder sb = new StringBuilder(); + + // Obtain all unique role names + HashSet groups = new HashSet<>(); + for (AbsUserCache.DumpInfo di : lur.dumpInfo()) { + sb.append("\n "); + + } + + // Print roles + for (String group : groups) { + ps.print(" "); + } + + ps.println(sb); - // We loop through Users, but want to write Groups first... therefore, save off print - StringBuilder sb = new StringBuilder(); - - // Obtain all unique role names - HashSet groups = new HashSet<>(); - for(AbsUserCache.DumpInfo di : lur.dumpInfo()) { - sb.append("\n "); + ps.println(""); + ps.flush(); + } catch (Exception t) { + t.printStackTrace(ps); + return false; + } + return true; + } - } + /** + * + * Note: This method returns a String if there's an error, or null if ok. + * This unusual style is necessitated by the fact that any Exceptions thrown are likely to + * be unlogged and hidden from view, making debugging almost impossible. + * + * @param writeto + * @param up + * @return + */ + public static String updateUsers(String writeto, LocalLur up) { + // Dump a Tomcat-user.xml lookalike (anywhere) + if (writeto!=null) { + // First read content + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + if (UsersDump.write(baos, up)) { + byte[] postulate = baos.toByteArray(); + // now get contents of file + File file = new File(writeto); + boolean writeIt; + if (file.exists()) { + try { + FileInputStream fis = new FileInputStream(file); + byte[] orig = new byte[(int)file.length()]; + int read; + try { + read = fis.read(orig); + } finally { + fis.close(); + } + if (read<=0) { + writeIt = false; + } else { + // Starting at third "<" ( line) + int startA=0, startB=0; + for (int i=0;startA"); - } - - ps.println(sb); + writeIt=orig.length-startA!=postulate.length-startB; // first, check if remaining length is the same + while (!writeIt && startA"); - ps.flush(); - } catch (Exception t) { - t.printStackTrace(ps); - return false; - } - return true; - } - - /** - * - * Note: This method returns a String if there's an error, or null if ok. - * This unusual style is necessitated by the fact that any Exceptions thrown are likely to - * be unlogged and hidden from view, making debugging almost impossible. - * - * @param writeto - * @param up - * @return - */ - public static String updateUsers(String writeto, LocalLur up) { - // Dump a Tomcat-user.xml lookalike (anywhere) - if(writeto!=null) { - // First read content - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - if(UsersDump.write(baos, up)) { - byte[] postulate = baos.toByteArray(); - // now get contents of file - File file = new File(writeto); - boolean writeIt; - if(file.exists()) { - try { - FileInputStream fis = new FileInputStream(file); - byte[] orig = new byte[(int)file.length()]; - int read; - try { - read = fis.read(orig); - } finally { - fis.close(); - } - if(read<=0) { - writeIt = false; - } else { - // Starting at third "<" ( line) - int startA=0, startB=0; - for(int i=0;startA