Search in sources :

Example 41 with Logger

use of org.jpos.util.Logger in project jPOS by jpos.

the class GenericSubFieldPackagerTest method testUnpackThrowsISOException3.

@Test
public void testUnpackThrowsISOException3() throws Throwable {
    GenericSubFieldPackager genericSubFieldPackager = new GenericSubFieldPackager();
    genericSubFieldPackager.setLogger(new Logger(), "testGenericSubFieldPackagerRealm");
    try {
        genericSubFieldPackager.unpack(new ISOMsg(), (byte[]) null);
        fail("Expected ISOException to be thrown");
    } catch (ISOException ex) {
        assertEquals("ex.getMessage()", "java.lang.NullPointerException", ex.getMessage());
        assertNull("ex.getNested().getMessage()", ex.getNested().getMessage());
    }
}
Also used : ISOException(org.jpos.iso.ISOException) ISOMsg(org.jpos.iso.ISOMsg) Logger(org.jpos.util.Logger) Test(org.junit.Test)

Example 42 with Logger

use of org.jpos.util.Logger in project jPOS by jpos.

the class JPOSLogger method isLevelEnabled.

protected boolean isLevelEnabled(int logLevel) {
    Logger logger = log.getLogger();
    Configuration cfg = logger.getConfiguration();
    if (cfg == null)
        cfg = new SimpleConfiguration();
    String levelString = cfg.get("slf4j.level", System.getProperty("slf4j.level"));
    int currentLogLevel = levelString != null ? stringToLevel(levelString) : DEFAULT_LOG_LEVEL;
    return (logLevel >= currentLogLevel);
}
Also used : Configuration(org.jpos.core.Configuration) SimpleConfiguration(org.jpos.core.SimpleConfiguration) SimpleConfiguration(org.jpos.core.SimpleConfiguration) Logger(org.jpos.util.Logger) LocationAwareLogger(org.slf4j.spi.LocationAwareLogger)

Example 43 with Logger

use of org.jpos.util.Logger in project jPOS by jpos.

the class TAIL method showLoggers.

private void showLoggers(CLIContext cli) {
    NameRegistrar nr = NameRegistrar.getInstance();
    int maxw = 0;
    Iterator iter = NameRegistrar.getAsMap().entrySet().iterator();
    StringBuilder sb = new StringBuilder("available loggers:");
    while (iter.hasNext()) {
        Map.Entry entry = (Map.Entry) iter.next();
        String key = (String) entry.getKey();
        if (key.startsWith("logger.") && entry.getValue() instanceof Logger) {
            sb.append(' ');
            sb.append(key.substring(7));
        }
    }
    cli.println(sb.toString());
}
Also used : NameRegistrar(org.jpos.util.NameRegistrar) Iterator(java.util.Iterator) Logger(org.jpos.util.Logger) Map(java.util.Map)

Example 44 with Logger

use of org.jpos.util.Logger in project jPOS by jpos.

the class TAIL method exec.

public void exec(CLIContext cli, String[] args) throws Exception {
    this.p = new PrintStream(cli.getReader().getTerminal().output());
    this.cli = cli;
    // cli.getReader().getTerminal().isAnsiSupported();
    this.ansi = false;
    if (args.length == 1) {
        usage(cli);
        return;
    }
    for (int i = 1; i < args.length; i++) {
        try {
            Logger logger = (Logger) NameRegistrar.get("logger." + args[i]);
            logger.addListener(this);
        } catch (NameRegistrar.NotFoundException e) {
            cli.println("Logger " + args[i] + " not found -- ignored.");
        }
    }
    // cli.getReader().readCharacter(new char[]{'q', 'Q'});
    cli.getReader().readLine();
    for (int i = 1; i < args.length; i++) {
        try {
            Logger logger = (Logger) NameRegistrar.get("logger." + args[i]);
            logger.removeListener(this);
        } catch (NameRegistrar.NotFoundException ignored) {
        // NOPMD OK to happen
        }
    }
}
Also used : PrintStream(java.io.PrintStream) NameRegistrar(org.jpos.util.NameRegistrar) Logger(org.jpos.util.Logger)

Example 45 with Logger

use of org.jpos.util.Logger in project jPOS by jpos.

the class Console method exec.

public void exec(PrintStream outPS, PrintStream errPS, String[] args) {
    JCESecurityModule sm = new JCESecurityModule();
    Logger logger = new Logger();
    logger.addListener(new SimpleLogListener(outPS));
    sm.setLogger(logger, "jce-security-module");
    Properties cfgProps = new Properties();
    SimpleConfiguration cfg = new SimpleConfiguration(cfgProps);
    String commandName = null;
    // 10 is Maximum number of paramters for a command
    String[] commandParams = new String[10];
    outPS.println("Welcome to JCE Security Module console commander!");
    if (args.length == 0) {
        outPS.println("Usage: Console [-options] command [commandparameters...]");
        outPS.println("\nwhere options include:");
        outPS.println("    -lmk <filename>");
        outPS.println("                  to specify the Local Master Keys file");
        outPS.println("    -rebuildlmk   to rebuild new Local Master Keys");
        outPS.println("                  WARNING: old Local Master Keys gets overwritten");
        outPS.println("    -jce <provider classname>");
        outPS.println("                  to specify a JavaTM Cryptography Extension 1.2.1 provider");
        outPS.println("\nWhere command include: ");
        outPS.println("    GC <keyLength>");
        outPS.println("                  to generate a clear key component.");
        outPS.println("    FK <keyLength> <keyType> <component1> <component2> <component3>");
        outPS.println("                  to form a key from three clear components.");
        outPS.println("                  and returns the key encrypted under LMK");
        outPS.println("                  Odd parity is be forced before encryption under LMK");
        outPS.println("    CK <keyLength> <keyType> <KEYunderLMK>");
        outPS.println("                  to generate a key check value for a key encrypted under LMK.");
        outPS.println("    IK <keyLength> <keyType> <KEYunderKEK> ");
        outPS.println("       <kekLength> <kekType> <KEKunderLMK> <KEKcheckValue>");
        outPS.println("                  to import a key from encryption under KEK (eg. ZMK,TMK) to encryption under LMK");
        outPS.println("                  Odd parity is be forced before encryption under LMK");
        outPS.println("    KE <keyLength> <keyType> <KEYunderLMK> <KEYcheckValue> ");
        outPS.println("       <kekLength> <kekType> <KEKunderLMK> <KEKcheckValue> ");
        outPS.println("                  to translate (export) a key from encryption under LMK");
        outPS.println("                  to encryption under KEK (eg. ZMK,TMK)");
    } else {
        int argsCounter = 0;
        for (int j = 0; j < 10; j++) {
            if (argsCounter < args.length && args[argsCounter].toLowerCase().compareTo("-lmk") == 0) {
                argsCounter++;
                cfgProps.setProperty("lmk", args[argsCounter++]);
            }
            if (argsCounter < args.length && args[argsCounter].toLowerCase().compareTo("-jce") == 0) {
                argsCounter++;
                cfgProps.setProperty("provider", args[argsCounter++]);
            }
            if (argsCounter < args.length && args[argsCounter].toLowerCase().compareTo("-rebuildlmk") == 0) {
                argsCounter++;
                cfgProps.setProperty("rebuildlmk", "true");
            }
        }
        if (argsCounter < args.length) {
            commandName = args[argsCounter++];
            int i = 0;
            while (argsCounter < args.length) {
                commandParams[i++] = args[argsCounter++];
            }
        }
        // Configure JCE Security Module
        try {
            sm.setConfiguration(cfg);
        } catch (ConfigurationException e) {
            e.printStackTrace(errPS);
            return;
        }
        // Execute Command
        if (commandName != null) {
            try {
                short keyLength = (short) Integer.parseInt(commandParams[0]);
                if (commandName.toUpperCase().compareTo("GC") == 0) {
                    String clearKeyComponenetHexString = sm.generateClearKeyComponent(keyLength);
                } else if (commandName.toUpperCase().compareTo("FK") == 0) {
                    SecureDESKey KEYunderLMK = sm.formKEYfromThreeClearComponents(keyLength, commandParams[1].toUpperCase(), commandParams[2], commandParams[3], commandParams[4]);
                } else if (commandName.toUpperCase().compareTo("CK") == 0) {
                    byte[] keyCheckValue = sm.generateKeyCheckValue(new SecureDESKey(keyLength, commandParams[1].toUpperCase(), commandParams[2], ""));
                } else if (commandName.toUpperCase().compareTo("IK") == 0) {
                    SecureDESKey KEKunderLMK = new SecureDESKey((short) Integer.parseInt(commandParams[3]), commandParams[4].toUpperCase(), commandParams[5], commandParams[6]);
                    sm.importKey(keyLength, commandParams[1].toUpperCase(), ISOUtil.hex2byte(commandParams[2]), KEKunderLMK, true);
                } else if (commandName.toUpperCase().compareTo("KE") == 0) {
                    SecureDESKey KEKunderLMK = new SecureDESKey((short) Integer.parseInt(commandParams[4]), commandParams[5].toUpperCase(), commandParams[6], commandParams[7]);
                    SecureDESKey KEYunderLMK = new SecureDESKey(keyLength, commandParams[1].toUpperCase(), commandParams[2], commandParams[3]);
                    sm.exportKey(KEYunderLMK, KEKunderLMK);
                } else {
                    System.err.println("Unknown command: " + commandName);
                }
            } catch (SMException e) {
                e.printStackTrace(errPS);
            } catch (java.lang.NumberFormatException e) {
                errPS.println("Invalid KeyLength");
            }
        } else {
            errPS.println("No command specified");
        }
    }
}
Also used : SMException(org.jpos.security.SMException) Logger(org.jpos.util.Logger) Properties(java.util.Properties) SimpleLogListener(org.jpos.util.SimpleLogListener) ConfigurationException(org.jpos.core.ConfigurationException) SimpleConfiguration(org.jpos.core.SimpleConfiguration) SecureDESKey(org.jpos.security.SecureDESKey)

Aggregations

Logger (org.jpos.util.Logger)45 Test (org.junit.Test)36 SimpleConfiguration (org.jpos.core.SimpleConfiguration)7 SubConfiguration (org.jpos.core.SubConfiguration)5 ISOMsg (org.jpos.iso.ISOMsg)5 SimpleLogListener (org.jpos.util.SimpleLogListener)5 Properties (java.util.Properties)4 Configuration (org.jpos.core.Configuration)4 ISOFieldPackager (org.jpos.iso.ISOFieldPackager)4 ISOException (org.jpos.iso.ISOException)3 ConfigurationException (org.jpos.core.ConfigurationException)2 GZIPChannel (org.jpos.iso.channel.GZIPChannel)2 Log (org.jpos.util.Log)2 NameRegistrar (org.jpos.util.NameRegistrar)2 Before (org.junit.Before)2 PrintStream (java.io.PrintStream)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 IFA_LLLLCHAR (org.jpos.iso.IFA_LLLLCHAR)1 IFE_CHAR (org.jpos.iso.IFE_CHAR)1