Search in sources :

Example 1 with SecureAS400

use of com.ibm.as400.access.SecureAS400 in project nagios-for-i by IBM.

the class CheckIBMiStatus method main.

public static void main(String[] args) {
    int retValue = Constants.UNKNOWN;
    try {
        ParseArgs(args);
        socket = new Socket(Constants.SERVER, Constants.PORT);
        socket.setReuseAddress(true);
        socket.setSoLinger(true, 0);
        ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
        oos.writeObject(argsMap);
        socket.shutdownOutput();
        InputStream is = socket.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String result = null;
        if ((result = br.readLine()) != null) {
            String message;
            while ((message = br.readLine()) != null) {
                System.out.println(message);
            }
            retValue = Integer.parseInt(result);
        }
    } catch (IOException e) {
        try {
            String metric = argsMap.get("-M");
            String system = argsMap.get("-H");
            Action action = ActionFactory.get(metric);
            StringBuffer response = new StringBuffer();
            if (!HostConfigInfo.load()) {
                System.err.println("load file Nagios.host.java.config.ser error");
                System.exit(retValue);
            }
            if ("HMC".equalsIgnoreCase(metric)) {
                retValue = action.execute(null, argsMap, response);
            } else {
                String user = HostConfigInfo.getUserID(system);
                String pass = HostConfigInfo.getPassword(system);
                if (user == null || pass == null) {
                    System.err.println("Host user profile not set");
                    System.exit(retValue);
                }
                String password = Base64Coder.decodeString(pass);
                argsMap.put("-U", user);
                argsMap.put("-P", password);
                AS400 as400 = null;
                String ssl = argsMap.get("-SSL");
                if (ssl != null && ssl.equalsIgnoreCase("Y")) {
                    as400 = new SecureAS400(system, user, password);
                } else {
                    as400 = new AS400(system, user, password);
                }
                as400.setGuiAvailable(false);
                as400.validateSignon();
                retValue = action.execute(as400, argsMap, response);
            }
            System.out.println(response);
        } catch (Exception e1) {
            retValue = Constants.UNKNOWN;
            e1.printStackTrace();
        }
    } finally {
        try {
            if (socket != null) {
                socket.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    System.exit(retValue);
}
Also used : Action(com.ibm.nagios.service.Action) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) IOException(java.io.IOException) SecureAS400(com.ibm.as400.access.SecureAS400) BufferedReader(java.io.BufferedReader) AS400(com.ibm.as400.access.AS400) SecureAS400(com.ibm.as400.access.SecureAS400) Socket(java.net.Socket)

Example 2 with SecureAS400

use of com.ibm.as400.access.SecureAS400 in project openicf by Evolveum.

the class OS400Connector method init.

/**
 * Callback method to receive the {@link Configuration}.
 *
 * @see Connector#init(org.identityconnectors.framework.spi.Configuration)
 */
public void init(Configuration configuration1) {
    this.configuration = (OS400Configuration) configuration1;
    if (as400 == null) {
        try {
            final StringBuilder clear = new StringBuilder();
            GuardedString.Accessor accessor = new GuardedString.Accessor() {

                public void access(char[] clearChars) {
                    clear.append(clearChars);
                }
            };
            configuration.getPassword().access(accessor);
            if (configuration.isSsl()) {
                as400 = new SecureAS400(configuration.getHost(), configuration.getRemoteUser(), clear.toString());
            } else {
                as400 = new AS400(configuration.getHost(), configuration.getRemoteUser(), clear.toString());
            }
            clear.setLength(0);
            if (as400 == null) {
                throw new ConnectorException("Connection Exception");
            }
            if (!as400.validateSignon()) {
                throw new ConnectorSecurityException("Login Error");
            }
            try {
                as400.setGuiAvailable(false);
                fetchPasswordLevel();
            } catch (Exception e) {
            }
        } catch (AS400SecurityException e) {
            throw new ConnectorSecurityException(e);
        } catch (IOException e) {
            throw new ConnectorIOException(e);
        }
    }
}
Also used : ConnectorIOException(org.identityconnectors.framework.common.exceptions.ConnectorIOException) SecureAS400(com.ibm.as400.access.SecureAS400) AS400SecurityException(com.ibm.as400.access.AS400SecurityException) ConnectorException(org.identityconnectors.framework.common.exceptions.ConnectorException) SecureAS400(com.ibm.as400.access.SecureAS400) AS400(com.ibm.as400.access.AS400) GuardedString(org.identityconnectors.common.security.GuardedString) ConnectorSecurityException(org.identityconnectors.framework.common.exceptions.ConnectorSecurityException) ConnectorIOException(org.identityconnectors.framework.common.exceptions.ConnectorIOException) IOException(java.io.IOException) ConnectorSecurityException(org.identityconnectors.framework.common.exceptions.ConnectorSecurityException) IntrospectionException(java.beans.IntrospectionException) ConnectorIOException(org.identityconnectors.framework.common.exceptions.ConnectorIOException) ConnectorException(org.identityconnectors.framework.common.exceptions.ConnectorException) RequestNotSupportedException(com.ibm.as400.access.RequestNotSupportedException) IOException(java.io.IOException) AS400SecurityException(com.ibm.as400.access.AS400SecurityException)

Aggregations

AS400 (com.ibm.as400.access.AS400)2 SecureAS400 (com.ibm.as400.access.SecureAS400)2 IOException (java.io.IOException)2 AS400SecurityException (com.ibm.as400.access.AS400SecurityException)1 RequestNotSupportedException (com.ibm.as400.access.RequestNotSupportedException)1 Action (com.ibm.nagios.service.Action)1 IntrospectionException (java.beans.IntrospectionException)1 BufferedReader (java.io.BufferedReader)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 ObjectOutputStream (java.io.ObjectOutputStream)1 Socket (java.net.Socket)1 GuardedString (org.identityconnectors.common.security.GuardedString)1 ConnectorException (org.identityconnectors.framework.common.exceptions.ConnectorException)1 ConnectorIOException (org.identityconnectors.framework.common.exceptions.ConnectorIOException)1 ConnectorSecurityException (org.identityconnectors.framework.common.exceptions.ConnectorSecurityException)1