Search in sources :

Example 11 with StringBuffer

use of java.lang.StringBuffer in project OpenAM by OpenRock.

the class MigrateWebAgentConfigurePropertiesTask method mergeConfigFiles.

/**
     * merge previous product's config file with the one newly generated.
     *
     * @param instanceConfigFileMigrate
     * @param instanceConfigFile
     * @throws Exception
     */
private void mergeConfigFiles(String instanceConfigFileMigrate, String instanceConfigFile, Properties mappedProperties) throws Exception {
    BufferedReader br = null;
    PrintWriter pw = null;
    FileInputStream fStream = null;
    String oldPropertyName = null;
    Debug.log("MigrateWebAgentConfigurePropertiesTask.mergeConfigFiles() - " + "config file to migrate from: " + instanceConfigFileMigrate + " config file to migrate to: " + instanceConfigFile);
    try {
        FileReader fr = new FileReader(instanceConfigFile);
        br = new BufferedReader(fr);
        String tmpFileName = instanceConfigFile + ".tmp";
        pw = new PrintWriter(new FileWriter(tmpFileName));
        String lineData = null;
        KeyValue keyValue = null;
        ArrayList migrateLines = null;
        while ((lineData = br.readLine()) != null) {
            lineData = lineData.trim();
            if (lineData.startsWith(FileUtils.HASH) || lineData.length() == 0) {
                // write back comment statement and empty line.
                pw.println(lineData);
            } else {
                keyValue = new KeyValue(lineData);
                if (nonMigratedParameters.contains(keyValue.getKey())) {
                    pw.println(lineData);
                    continue;
                }
                // For the new web agent property, get its corresponding
                // old property name
                oldPropertyName = mappedProperties.getProperty(keyValue.getParameter());
                migrateLines = getMigrateLines(keyValue.getParameter(), oldPropertyName, instanceConfigFileMigrate);
                Debug.log("MigrateWebAgentConfigurePropertiesTask.mergeConfigFiles()- " + "parameter: " + keyValue.getParameter() + " matched migration parameters: " + migrateLines);
                if (migrateLines.size() > 0) {
                    for (int i = 0; i < migrateLines.size(); i++) {
                        pw.println(migrateLines.get(i));
                    }
                } else {
                    if (lineData.indexOf(AGENT_ENCRYPT_KEY_PROPERTY) >= 0) {
                        // encrypt key property
                        StringBuffer newLineData = new StringBuffer();
                        int count = 0;
                        StringTokenizer st = new StringTokenizer(lineData, "=");
                        while (st.hasMoreElements()) {
                            String tok = st.nextToken();
                            if (count == 0) {
                                newLineData.append(tok);
                                newLineData.append("= ");
                            } else {
                                newLineData.append(AGENT_22_ENCRYPT_KEY_VALUE);
                            }
                            count++;
                        }
                        pw.println(newLineData);
                    } else {
                        // new parameter, write back.
                        pw.println(lineData);
                    }
                }
            }
        // end of if (lineData..
        }
        // end of while
        br.close();
        pw.flush();
        pw.close();
        FileUtils.copyFile(tmpFileName, instanceConfigFile);
        File tmpFile = new File(tmpFileName);
        tmpFile.delete();
    } catch (Exception ex) {
        if (br != null) {
            try {
                br.close();
            } catch (Exception ex1) {
            }
        }
        if (pw != null) {
            try {
                pw.close();
            } catch (Exception ex1) {
            }
        }
    }
}
Also used : FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) StringBuffer(java.lang.StringBuffer) StringTokenizer(java.util.StringTokenizer) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 12 with StringBuffer

use of java.lang.StringBuffer in project OpenAM by OpenRock.

the class FedletMetaData method createExtendedMetaData.

public static String createExtendedMetaData(String realm, String entityId, List attrMapping, String fedletBaseUrl) throws WorkflowException {
    Map map = new HashMap();
    // For fedlet, we have root realm only
    map.put(MetaTemplateParameters.P_SP, Task.generateMetaAliasForSP("/"));
    String extendedData = CreateSAML2HostedProviderTemplate.createExtendedDataTemplate(entityId, map, null, false);
    int idx = extendedData.indexOf("<Attribute name=\"spAccountMapper\">");
    if (idx != -1) {
        extendedData = extendedData.substring(0, idx) + "<Attribute name=\"fedletAdapter\">\n" + "            <Value>com.sun.identity.saml2.plugins.DefaultFedletAdapter</Value>\n" + "        </Attribute>\n" + "        <Attribute name=\"fedletAdapterEnv\">\n" + "            <Value></Value>\n" + "        </Attribute>\n" + "        " + extendedData.substring(idx);
    }
    idx = extendedData.indexOf("<Attribute name=\"appLogoutUrl\">");
    if (idx != -1) {
        idx = extendedData.indexOf("<Value>", idx);
        int idx1 = extendedData.indexOf("</Value>", idx);
        extendedData = extendedData.substring(0, idx + 7) + fedletBaseUrl + "/logout" + extendedData.substring(idx1);
    }
    idx = extendedData.indexOf("<Attribute name=\"spAccountMapper\">");
    if (idx != -1) {
        idx = extendedData.indexOf("<Value>", idx);
        int idx1 = extendedData.indexOf("</Value>", idx);
        extendedData = extendedData.substring(0, idx + 7) + "com.sun.identity.saml2.plugins.DefaultLibrarySPAccountMapper" + extendedData.substring(idx1);
    }
    idx = extendedData.indexOf("<Attribute name=\"transientUser\">");
    if (idx != -1) {
        idx = extendedData.indexOf("<Value>", idx);
        int idx1 = extendedData.indexOf("</Value>", idx);
        extendedData = extendedData.substring(0, idx + 7) + "anonymous" + extendedData.substring(idx1);
    }
    idx = extendedData.indexOf("<Attribute name=\"saeSPUrl\">");
    if (idx != -1) {
        idx = extendedData.indexOf("<Value>", idx);
        int idx1 = extendedData.indexOf("</Value>", idx);
        extendedData = extendedData.substring(0, idx + 7) + extendedData.substring(idx1);
    }
    idx = extendedData.indexOf("<Attribute name=\"attributeMap\">");
    if (idx != -1) {
        if ((attrMapping != null) && !attrMapping.isEmpty()) {
            StringBuffer buff = new StringBuffer();
            for (Iterator i = attrMapping.iterator(); i.hasNext(); ) {
                buff.append("\n           <Value>").append((String) i.next()).append("</Value>");
            }
            idx = extendedData.indexOf(">", idx);
            extendedData = extendedData.substring(0, idx + 1) + buff.toString() + extendedData.substring(idx + 1);
        } else {
            idx = extendedData.indexOf(">", idx);
            extendedData = extendedData.substring(0, idx + 1) + "\n           <Value>*=*</Value>" + extendedData.substring(idx + 1);
        }
    }
    return extendedData;
}
Also used : StringBuffer(java.lang.StringBuffer) HashMap(java.util.HashMap) Iterator(java.util.Iterator) Map(java.util.Map) HashMap(java.util.HashMap)

Example 13 with StringBuffer

use of java.lang.StringBuffer in project cogcomp-nlp by CogComp.

the class MASCevaluationResult method getOverallAnalytics.

public static String getOverallAnalytics(MASCevaluationResult[] input) {
    HashMap<String, String[]> map = new HashMap<String, String[]>();
    HashMap<String, Integer> count = new HashMap<String, Integer>();
    int total = 0;
    int correct = 0;
    for (MASCevaluationResult anInput : input) {
        total += anInput.getTotal();
        correct += anInput.getCorrect();
        ArrayList<String[]> allErrors = anInput.getErrors();
        for (String[] allError : allErrors) {
            String key = allError[0] + ":" + allError[1];
            if (map.containsKey(key)) {
                count.put(key, count.get(key) + 1);
            } else {
                count.put(key, 1);
                map.put(key, allError);
            }
        }
    }
    count = sortByValues(count);
    StringBuffer buffer = new StringBuffer();
    buffer.append("==============================================================\n");
    buffer.append("Overall Accuracy:").append((double) (correct) / (double) (total) * 100).append("%\n");
    buffer.append("Error Analytics: \n");
    buffer.append(String.format("%20s%5s%20s%20s%20s\n", "RAW", "POS", "BASE", "RESULT", "COUNT"));
    Set set = count.entrySet();
    for (Object aSet : set) {
        Map.Entry me = (Map.Entry) aSet;
        String key = (String) me.getKey();
        int counter = (Integer) me.getValue();
        String[] temp = map.get(key);
        buffer.append(String.format("%20s%5s%20s%20s%20d\n", temp[0], temp[1], temp[2], temp[3], counter));
    }
    buffer.append("==============================================================\n");
    return buffer.toString();
}
Also used : HashMap(java.util.HashMap) StringBuffer(java.lang.StringBuffer) HashMap(java.util.HashMap)

Example 14 with StringBuffer

use of java.lang.StringBuffer in project Payara by payara.

the class LDAPRealm method getGroups.

private List<String> getGroups(String userDN) {
    // no authentication has happened through the realm.
    DirContext ctx = null;
    String srcFilter = null;
    String dynFilter = null;
    String dynMember = getProperty(PARAM_DYNAMIC_GRP_TARGET);
    try {
        ctx = new InitialDirContext(getLdapBindProps());
        String _username = userDN;
        try {
            X500Name name = new X500Name(userDN);
            _username = name.getCommonName();
        } catch (IOException e) {
        // Ignoring the exception to suppot simple group names as userDN
        // Issue GLASSFISH-19595
        }
        if (_username == null && userDN != null && userDN.startsWith("uid")) {
            // handle uid=XXX here where cn is not present
            // TODO :maybe there is a better way to handle this??
            int first = userDN.indexOf("uid=");
            int last = userDN.indexOf(",");
            if (first != -1 && last != -1) {
                _username = userDN.substring(first + 4, last);
            }
        }
        StringBuffer sb = new StringBuffer(getProperty(PARAM_GRP_SEARCH_FILTER));
        StringBuffer dynSb = new StringBuffer(getProperty(PARAM_DYNAMIC_GRP_FILTER));
        substitute(sb, SUBST_SUBJECT_NAME, _username);
        substitute(sb, SUBST_SUBJECT_DN, userDN);
        substitute(dynSb, SUBST_SUBJECT_NAME, _username);
        substitute(dynSb, SUBST_SUBJECT_DN, userDN);
        srcFilter = sb.toString();
        dynFilter = dynSb.toString();
        List<String> groupsList = new ArrayList<String>();
        groupsList.addAll(groupSearch(ctx, getProperty(PARAM_GRPDN), srcFilter, getProperty(PARAM_GRP_TARGET)));
        // search filter is constructed internally as
        // as a groupofURLS
        groupsList.addAll(dynamicGroupSearch(ctx, getProperty(PARAM_GRPDN), dynMember, dynFilter, getProperty(PARAM_GRP_TARGET)));
        return groupsList;
    } catch (Exception e) {
        _logger.log(Level.WARNING, "ldaprealm.groupsearcherror", e);
    } finally {
        if (ctx != null) {
            try {
                ctx.close();
            } catch (NamingException e) {
                _logger.log(Level.WARNING, "ldaprealm.exception", e);
            }
        }
    }
    return null;
}
Also used : StringBuffer(java.lang.StringBuffer) NamingException(javax.naming.NamingException) InitialDirContext(javax.naming.directory.InitialDirContext) DirContext(javax.naming.directory.DirContext) InitialDirContext(javax.naming.directory.InitialDirContext) X500Name(sun.security.x509.X500Name) IOException(java.io.IOException) LoginException(javax.security.auth.login.LoginException) BadRealmException(com.sun.enterprise.security.auth.realm.BadRealmException) NamingException(javax.naming.NamingException) NoSuchRealmException(com.sun.enterprise.security.auth.realm.NoSuchRealmException) InvalidOperationException(com.sun.enterprise.security.auth.realm.InvalidOperationException) IOException(java.io.IOException) NoSuchUserException(com.sun.enterprise.security.auth.realm.NoSuchUserException)

Example 15 with StringBuffer

use of java.lang.StringBuffer in project Payara by payara.

the class UnprocessedChangeEvents method toString.

public String toString() {
    StringBuffer result = new StringBuffer("UnprocessedChangeEvents: " + size());
    if (size() != 0) {
        result.append(" {");
        for (final UnprocessedChangeEvent e : mUnprocessed) {
            result.append(e).append(", ");
        }
        result.append("}");
    }
    return result.toString();
}
Also used : StringBuffer(java.lang.StringBuffer)

Aggregations

StringBuffer (java.lang.StringBuffer)16 IOException (java.io.IOException)6 BadRealmException (com.sun.enterprise.security.auth.realm.BadRealmException)3 InvalidOperationException (com.sun.enterprise.security.auth.realm.InvalidOperationException)3 NoSuchRealmException (com.sun.enterprise.security.auth.realm.NoSuchRealmException)3 NoSuchUserException (com.sun.enterprise.security.auth.realm.NoSuchUserException)3 NamingException (javax.naming.NamingException)3 LoginException (javax.security.auth.login.LoginException)3 BufferedReader (java.io.BufferedReader)2 FileInputStream (java.io.FileInputStream)2 Enumeration (java.util.Enumeration)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 DirContext (javax.naming.directory.DirContext)2 InitialDirContext (javax.naming.directory.InitialDirContext)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1