Search in sources :

Example 1 with StringBuffer

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

the class MergeClientConfig method main.

public static void main(String[] args) {
    try {
        StringBuffer file1 = getInputStringBuffer(args[0], false);
        StringBuffer file2 = getInputStringBuffer(args[1], true);
        writeToFile(file1, file2, args[2]);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : StringBuffer(java.lang.StringBuffer) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with StringBuffer

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

the class MergeClientConfig method getInputStringBuffer.

/**
     * Returns input file as StringBuffer.
     * @param filename Name of the file.
     * @param skipCopyright if false, keep copyright notice in the beginning
     *        of the input file. if true, remove the copyright notice.
     * @return StringBuffer
     */
private static StringBuffer getInputStringBuffer(String filename, boolean skipCopyright) throws Exception {
    StringBuffer buff = new StringBuffer(20480);
    BufferedReader br = null;
    try {
        br = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
        while (true) {
            String line = br.readLine();
            if (line == null) {
                break;
            }
            if (skipCopyright && line.startsWith("#")) {
                continue;
            }
            // done skipping the copyright in the beginning of the file
            skipCopyright = false;
            buff.append(line).append("\n");
        }
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }
    return buff;
}
Also used : StringBuffer(java.lang.StringBuffer) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 3 with StringBuffer

use of java.lang.StringBuffer in project opennms by OpenNMS.

the class SimpleNode method dumpOidNamesSymbolTable.

// end writeOIDS
/**
 * Dump the oidNames symbol tables - primarily debugging routine
 */
public void dumpOidNamesSymbolTable() {
    StringBuffer sb = new StringBuffer();
    OidValues oidValues = null;
    String key = null;
    String oidName = null;
    sb.append("Symbol Table oidNames for text OID/OidValues\n");
    for (Enumeration e = oidNames.keys(); e.hasMoreElements(); ) {
        key = (String) e.nextElement();
        oidValues = (OidValues) oidNames.get(key);
        sb.append(key + "/" + oidValues.toString()).append("\n");
    }
    if (printDebug) {
        System.out.println(sb.toString());
    }
}
Also used : StringBuffer(java.lang.StringBuffer) Enumeration(java.util.Enumeration)

Example 4 with StringBuffer

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

the class LoggerJDK14 method toString.

/**
 * Prepare a printable version of this instance.
 * @return the String representation of this object
 */
public String toString() {
    // NOI18N
    StringBuffer buf = new StringBuffer("LoggerJDK14: ");
    // NOI18N
    buf.append(" name: ");
    // NOI18N
    buf.append(getName());
    // NOI18N
    buf.append(", super: ");
    // NOI18N
    buf.append(super.toString());
    // NOI18N
    buf.append(", logging level: ");
    // NOI18N
    buf.append(getLevel());
    return buf.toString();
}
Also used : StringBuffer(java.lang.StringBuffer)

Example 5 with StringBuffer

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

the class LDAPRealm method findAndBind.

/**
 * Supports mode=find-bind. See class documentation.
 */
public String[] findAndBind(String _username, char[] _password) throws LoginException {
    // do search for user, substituting %s for username
    _username = RFC2254Encode(_username);
    StringBuffer sb = new StringBuffer(getProperty(PARAM_SEARCH_FILTER));
    substitute(sb, SUBST_SUBJECT_NAME, _username);
    String userid = sb.toString();
    // attempt to bind as the user
    DirContext ctx = null;
    String srcFilter = null;
    String[] grpList = null;
    String dynFilter = null;
    String dynMember = getProperty(PARAM_DYNAMIC_GRP_TARGET);
    try {
        ctx = new InitialDirContext(getLdapBindProps());
        String realUserDN = userSearch(ctx, getProperty(PARAM_USERDN), userid);
        if (realUserDN == null) {
            String msg = sm.getString("ldaprealm.usernotfound", _username);
            throw new LoginException(msg);
        }
        boolean bindSuccessful = bindAsUser(realUserDN, _password);
        if (bindSuccessful == false) {
            String msg = sm.getString("ldaprealm.bindfailed", realUserDN);
            throw new LoginException(msg);
        }
        // search groups using above connection, substituting %d (and %s)
        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, realUserDN);
        substitute(dynSb, SUBST_SUBJECT_NAME, _username);
        substitute(dynSb, SUBST_SUBJECT_DN, realUserDN);
        srcFilter = sb.toString();
        dynFilter = dynSb.toString();
        ArrayList groupsList = new ArrayList();
        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)));
        grpList = new String[groupsList.size()];
        groupsList.toArray(grpList);
    } catch (Exception e) {
        LoginException le = new LoginException(e.toString());
        le.initCause(e);
        _logger.log(Level.SEVERE, "ldaprealm.exception", le);
        throw le;
    } finally {
        if (ctx != null) {
            try {
                ctx.close();
            } catch (NamingException e) {
            }
        }
    }
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "LDAP:Group search filter: " + srcFilter);
        StringBuffer gb = new StringBuffer();
        gb.append("Group memberships found: ");
        if (grpList.length > 0) {
            for (int i = 0; i < grpList.length; i++) {
                gb.append(" " + grpList[i]);
            }
        } else {
            gb.append("(null)");
        }
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "LDAP: " + gb.toString());
        }
    }
    grpList = addAssignGroups(grpList);
    grpList = this.addMappedGroupNames(grpList);
    setGroupNames(_username, grpList);
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "LDAP: login succeeded for: " + _username);
    }
    return grpList;
}
Also used : StringBuffer(java.lang.StringBuffer) LoginException(javax.security.auth.login.LoginException) NamingException(javax.naming.NamingException) InitialDirContext(javax.naming.directory.InitialDirContext) DirContext(javax.naming.directory.DirContext) InitialDirContext(javax.naming.directory.InitialDirContext) 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)

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