Example usage for java.lang SecurityException toString

List of usage examples for java.lang SecurityException toString

Introduction

In this page you can find the example usage for java.lang SecurityException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.cloud.consoleproxy.ConsoleProxy.java

public static void startWithContext(Properties conf, Object context, byte[] ksBits, String ksPassword) {
    s_logger.info("Start console proxy with context");
    if (conf != null) {
        for (Object key : conf.keySet()) {
            s_logger.info("Context property " + (String) key + ": " + conf.getProperty((String) key));
        }//from w  w  w. j a  va 2s.  com
    }

    configLog4j();
    Logger.setFactory(new ConsoleProxyLoggerFactory());

    // Using reflection to setup private/secure communication channel towards management server
    ConsoleProxy.context = context;
    ConsoleProxy.ksBits = ksBits;
    ConsoleProxy.ksPassword = ksPassword;
    try {
        Class<?> contextClazz = Class.forName("com.cloud.agent.resource.consoleproxy.ConsoleProxyResource");
        authMethod = contextClazz.getDeclaredMethod("authenticateConsoleAccess", String.class, String.class,
                String.class, String.class, String.class, Boolean.class);
        reportMethod = contextClazz.getDeclaredMethod("reportLoadInfo", String.class);
        ensureRouteMethod = contextClazz.getDeclaredMethod("ensureRoute", String.class);
    } catch (SecurityException e) {
        s_logger.error("Unable to setup private channel due to SecurityException", e);
    } catch (NoSuchMethodException e) {
        s_logger.error("Unable to setup private channel due to NoSuchMethodException", e);
    } catch (IllegalArgumentException e) {
        s_logger.error("Unable to setup private channel due to IllegalArgumentException", e);
    } catch (ClassNotFoundException e) {
        s_logger.error("Unable to setup private channel due to ClassNotFoundException", e);
    }

    // merge properties from conf file
    InputStream confs = ConsoleProxy.class.getResourceAsStream("/conf/consoleproxy.properties");
    Properties props = new Properties();
    if (confs == null) {
        s_logger.info("Can't load consoleproxy.properties from classpath, will use default configuration");
    } else {
        try {
            props.load(confs);

            for (Object key : props.keySet()) {
                // give properties passed via context high priority, treat properties from consoleproxy.properties
                // as default values
                if (conf.get(key) == null)
                    conf.put(key, props.get(key));
            }
        } catch (Exception e) {
            s_logger.error(e.toString(), e);
        }
    }

    start(conf);
}

From source file:com.klaasnotfound.locationassistant.LocationAssistant.java

protected void checkInitialLocation() {
    if (!googleApiClient.isConnected() || !permissionGranted || !locationRequested || !locationStatusOk)
        return;/*ww w.j  a  v a  2 s .c om*/
    try {
        Location location = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
        onLocationChanged(location);
    } catch (SecurityException e) {
        if (!quiet)
            Log.e(getClass().getSimpleName(), "Error while requesting last location:\n " + e.toString());
        if (listener != null)
            listener.onError(ErrorType.RETRIEVAL, "Could not retrieve initial location:\n" + e.getMessage());
    }
}

From source file:com.klaasnotfound.locationassistant.LocationAssistant.java

private void requestLocationUpdates() {
    if (!googleApiClient.isConnected() || !permissionGranted || !locationRequested)
        return;//from   w w w.j av  a2s  .  co  m
    try {
        LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this);
        updatesRequested = true;
    } catch (SecurityException e) {
        if (!quiet)
            Log.e(getClass().getSimpleName(), "Error while requesting location updates:\n " + e.toString());
        if (listener != null)
            listener.onError(ErrorType.RETRIEVAL, "Could not request location updates:\n" + e.getMessage());
    }
}

From source file:com.klaasnotfound.locationassistant.LocationAssistant.java

private boolean checkLocationAvailability() {
    if (!googleApiClient.isConnected() || !permissionGranted)
        return false;
    try {//from w  w  w.  j av a  2 s .c  om
        LocationAvailability la = LocationServices.FusedLocationApi.getLocationAvailability(googleApiClient);
        return (la != null && la.isLocationAvailable());
    } catch (SecurityException e) {
        if (!quiet)
            Log.e(getClass().getSimpleName(), "Error while checking location availability:\n " + e.toString());
        if (listener != null)
            listener.onError(ErrorType.RETRIEVAL, "Could not check location availability:\n" + e.getMessage());
        return false;
    }
}

From source file:org.apache.tapestry.request.RequestContext.java

private void writeSystemProperties(IMarkupWriter writer) {
    Properties properties = null;

    object(writer, "JVM System Properties");

    try {/*from ww  w  .ja v a2  s. com*/
        properties = System.getProperties();
    } catch (SecurityException se) {
        writer.print("<p>");
        writer.print(se.toString());
        return;
    }

    String pathSeparator = System.getProperty("path.separator", ";");

    writer.begin("table");
    writer.attribute("class", "request-context-object");

    List names = new ArrayList(properties.keySet());
    Collections.sort(names);
    int count = names.size();

    for (int i = 0; i < count; i++) {

        if (i == 0)
            header(writer, "Name", "Value");

        String name = (String) names.get(i);

        String property = properties.getProperty(name);

        if (property != null && property.indexOf(pathSeparator) > 0 && name.endsWith(".path")) {
            writer.begin("tr");
            writer.attribute("class", getRowClass());

            writer.begin("th");
            writer.print(name);
            writer.end();

            writer.begin("td");
            writer.begin("ul");

            StringTokenizer tokenizer = new StringTokenizer(property, pathSeparator);

            while (tokenizer.hasMoreTokens()) {
                writer.beginEmpty("li");
                writer.print(tokenizer.nextToken());
            }

            writer.end("tr");
        } else {
            pair(writer, name, property);
        }
    }

    writer.end(); // System Properties
}

From source file:de.bogutzky.psychophysiocollector.app.MainActivity.java

private void stopStreamingInternalSensorData() {
    internalSensorManager.stopStreaming();
    ((GPSListener) locationListener).stopStreaming();
    if (locationManager != null) {
        try {//  ww  w . ja va  2  s .  co m
            locationManager.removeUpdates(locationListener);
        } catch (SecurityException e) {
            Log.e(TAG, e.toString());
        }
    }
}

From source file:com.youxifan.utils.EMail.java

/**
 *   Send Mail direct/*ww w .  j  a  v a  2  s .  com*/
 *   @return OK or error message
 */
public String send() {
    log.info("(" + m_smtpHost + ") " + m_from + " -> " + m_to);
    m_sentMsg = null;
    //
    if (!isValid(true)) {
        m_sentMsg = "Invalid Data";
        return m_sentMsg;
    }
    //
    Properties props = System.getProperties();
    props.put("mail.store.protocol", "smtp");
    props.put("mail.transport.protocol", "smtp");
    props.put("mail.host", m_smtpHost);
    //   Bit-Florin David
    props.put("mail.smtp.port", String.valueOf(m_smtpPort));
    //   TLS settings
    if (m_isSmtpTLS) {
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.socketFactory.port", String.valueOf(m_smtpPort));
        props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        props.put("mail.smtp.socketFactory.fallback", "false");
    }

    //
    Session session = null;
    try {
        if (m_auth != null) //   createAuthenticator was called
            props.put("mail.smtp.auth", "true");
        //         if (m_smtpHost.equalsIgnoreCase("smtp.gmail.com")) {
        //            // TODO: make it configurable
        //            // Enable gmail port and ttls - Hardcoded
        //            props.put("mail.smtp.port", "587");
        //            props.put("mail.smtp.starttls.enable", "true");
        //         }

        session = Session.getInstance(props, m_auth);
    } catch (SecurityException se) {
        log.warn("Auth=" + m_auth + " - " + se.toString());
        m_sentMsg = se.toString();
        return se.toString();
    } catch (Exception e) {
        log.warn("Auth=" + m_auth, e);
        m_sentMsg = e.toString();
        return e.toString();
    }

    try {
        //   m_msg = new MimeMessage(session);
        m_msg = new SMTPMessage(session);
        //   Addresses
        m_msg.setFrom(m_from);
        InternetAddress[] rec = getTos();
        if (rec.length == 1)
            m_msg.setRecipient(Message.RecipientType.TO, rec[0]);
        else
            m_msg.setRecipients(Message.RecipientType.TO, rec);
        rec = getCcs();
        if (rec != null && rec.length > 0)
            m_msg.setRecipients(Message.RecipientType.CC, rec);
        rec = getBccs();
        if (rec != null && rec.length > 0)
            m_msg.setRecipients(Message.RecipientType.BCC, rec);
        if (m_replyTo != null)
            m_msg.setReplyTo(new Address[] { m_replyTo });
        //
        m_msg.setSentDate(new java.util.Date());
        m_msg.setHeader("Comments", "Becit Mail");
        m_msg.setHeader("Comments", "Becit ERP Mail");
        //   m_msg.setDescription("Description");
        //   SMTP specifics
        m_msg.setAllow8bitMIME(true);
        //   Send notification on Failure & Success - no way to set envid in Java yet
        //   m_msg.setNotifyOptions (SMTPMessage.NOTIFY_FAILURE | SMTPMessage.NOTIFY_SUCCESS);
        //   Bounce only header
        m_msg.setReturnOption(SMTPMessage.RETURN_HDRS);
        //   m_msg.setHeader("X-Mailer", "msgsend");
        //
        setContent();
        m_msg.saveChanges();
        //   log.fine("message =" + m_msg);
        //
        //   Transport.send(msg);
        Transport t = session.getTransport("smtp");
        //   log.fine("transport=" + t);
        t.connect();
        //   t.connect(m_smtpHost, user, password);
        //   log.fine("transport connected");
        Transport.send(m_msg);
        //   t.sendMessage(msg, msg.getAllRecipients());
        log.info("Success - MessageID=" + m_msg.getMessageID());
    } catch (MessagingException me) {
        Exception ex = me;
        StringBuffer sb = new StringBuffer("(ME)");
        boolean printed = false;
        do {
            if (ex instanceof SendFailedException) {
                SendFailedException sfex = (SendFailedException) ex;
                Address[] invalid = sfex.getInvalidAddresses();
                if (!printed) {
                    if (invalid != null && invalid.length > 0) {
                        sb.append(" - Invalid:");
                        for (int i = 0; i < invalid.length; i++)
                            sb.append(" ").append(invalid[i]);

                    }
                    Address[] validUnsent = sfex.getValidUnsentAddresses();
                    if (validUnsent != null && validUnsent.length > 0) {
                        sb.append(" - ValidUnsent:");
                        for (int i = 0; i < validUnsent.length; i++)
                            sb.append(" ").append(validUnsent[i]);
                    }
                    Address[] validSent = sfex.getValidSentAddresses();
                    if (validSent != null && validSent.length > 0) {
                        sb.append(" - ValidSent:");
                        for (int i = 0; i < validSent.length; i++)
                            sb.append(" ").append(validSent[i]);
                    }
                    printed = true;
                }
                if (sfex.getNextException() == null)
                    sb.append(" ").append(sfex.getLocalizedMessage());
            } else if (ex instanceof AuthenticationFailedException) {
                sb.append(" - Invalid Username/Password - " + m_auth);
            } else //   other MessagingException 
            {
                String msg = ex.getLocalizedMessage();
                if (msg == null)
                    sb.append(": ").append(ex.toString());
                else {
                    if (msg.indexOf("Could not connect to SMTP host:") != -1) {
                        int index = msg.indexOf('\n');
                        if (index != -1)
                            msg = msg.substring(0, index);
                        String cc = "??";

                        msg += " - AD_Client_ID=" + cc;
                    }
                    String className = ex.getClass().getName();
                    if (className.indexOf("MessagingException") != -1)
                        sb.append(": ").append(msg);
                    else
                        sb.append(" ").append(className).append(": ").append(msg);
                }
            }
            //   Next Exception
            if (ex instanceof MessagingException)
                ex = ((MessagingException) ex).getNextException();
            else
                ex = null;
        } while (ex != null); //   error loop
        m_sentMsg = sb.toString();
        return sb.toString();
    } catch (Exception e) {
        log.warn("", e);
        m_sentMsg = e.getLocalizedMessage();
        return e.getLocalizedMessage();
    }
    //
    m_sentMsg = SENT_OK;
    return m_sentMsg;
}

From source file:org.cerberus.crud.dao.impl.ApplicationObjectDAO.java

@Override
public Answer uploadFile(int id, FileItem file) {
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED)
            .resolveDescription("DESCRIPTION", "cerberus_applicationobject_path Parameter not found");
    AnswerItem a = parameterService.readByKey("", "cerberus_applicationobject_path");
    if (a.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
        Parameter p = (Parameter) a.getItem();
        String uploadPath = p.getValue();
        File appDir = new File(uploadPath + "/" + id);
        if (!appDir.exists()) {
            try {
                appDir.mkdirs();/*  w  ww.  j  a va 2 s .com*/
            } catch (SecurityException se) {
                LOG.warn("Unable to create application dir: " + se.getMessage());
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED)
                        .resolveDescription("DESCRIPTION", se.toString());
                a.setResultMessage(msg);
            }
        }
        if (a.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
            deleteFolder(appDir, false);
            File picture = new File(uploadPath + "/" + id + "/" + file.getName());
            try {
                file.write(picture);
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("DESCRIPTION",
                        "Application Object file uploaded");
                msg.setDescription(msg.getDescription().replace("%ITEM%", "Application Object")
                        .replace("%OPERATION%", "Upload"));
            } catch (Exception e) {
                LOG.warn("Unable to upload application object file: " + e.getMessage());
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED)
                        .resolveDescription("DESCRIPTION", e.toString());
            }
        }
    } else {
        LOG.warn("cerberus_applicationobject_path Parameter not found");
    }
    a.setResultMessage(msg);
    return a;
}

From source file:org.metawatch.manager.MetaWatchService.java

@TargetApi(10)
private boolean connect() {

    try {/*  w w  w .j  a v  a2  s.c  om*/

        if (!Preferences.loaded)
            loadPreferences(this);

        MetaWatchService.fakeWatch = false;
        if (Preferences.watchMacAddress.equals("DIGITAL")) {
            MetaWatchService.fakeWatch = true;
            MetaWatchService.watchType = WatchType.DIGITAL;
        }
        if (Preferences.watchMacAddress.equals("ANALOG")) {
            MetaWatchService.fakeWatch = true;
            MetaWatchService.watchType = WatchType.ANALOG;
        }

        if (Preferences.logging)
            Log.d(MetaWatchStatus.TAG, "Remote device address: '" + Preferences.watchMacAddress + "'");

        if (!MetaWatchService.fakeWatch) {

            if (bluetoothAdapter == null)
                bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

            BluetoothDevice bluetoothDevice = bluetoothAdapter.getRemoteDevice(Preferences.watchMacAddress);

            int currentapiVersion = android.os.Build.VERSION.SDK_INT;

            if (Preferences.skipSDP) {
                Method method;
                if (Preferences.insecureBtSocket
                        && currentapiVersion >= android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
                    method = bluetoothDevice.getClass().getMethod("createInsecureRfcommSocket",
                            new Class[] { int.class });
                } else {
                    method = bluetoothDevice.getClass().getMethod("createRfcommSocket",
                            new Class[] { int.class });
                }
                bluetoothSocket = (BluetoothSocket) method.invoke(bluetoothDevice, 1);
            } else {
                UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");

                if (Preferences.insecureBtSocket
                        && currentapiVersion >= android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
                    bluetoothSocket = bluetoothDevice.createInsecureRfcommSocketToServiceRecord(uuid);
                } else {
                    bluetoothSocket = bluetoothDevice.createRfcommSocketToServiceRecord(uuid);
                }
            }

            bluetoothAdapter.cancelDiscovery();
            bluetoothSocket.connect();

            inputStream = bluetoothSocket.getInputStream();
            outputStream = bluetoothSocket.getOutputStream();
        }

        connectionState = ConnectionState.CONNECTED;
        setPreviousConnectionState(this, true);
        updateNotification();

        Protocol.getInstance(MetaWatchService.this).getDeviceType();

        NavigationManagement.processWatchConnection(this);

        // Unblock the message protocol queue, and the notification queue.
        mPauseQueue.open();

        return true;

    } catch (IOException ioexception) {
        if (Preferences.logging)
            Log.d(MetaWatchStatus.TAG, ioexception.toString());
    } catch (SecurityException e) {
        if (Preferences.logging)
            Log.d(MetaWatchStatus.TAG, e.toString());
    } catch (NoSuchMethodException e) {
        if (Preferences.logging)
            Log.d(MetaWatchStatus.TAG, e.toString());
    } catch (IllegalArgumentException e) {
        if (Preferences.logging)
            Log.d(MetaWatchStatus.TAG, e.toString());
    } catch (IllegalAccessException e) {
        if (Preferences.logging)
            Log.d(MetaWatchStatus.TAG, e.toString());
    } catch (InvocationTargetException e) {
        if (Preferences.logging)
            Log.d(MetaWatchStatus.TAG, e.toString());
    } catch (NullPointerException e) {
        if (Preferences.logging)
            Log.d(MetaWatchStatus.TAG, e.toString());
    } finally {
    }
    return false;
}

From source file:org.transdroid.core.gui.TorrentsActivity.java

private void addTorrentFromDownloads(Uri contentUri, String title) {

    try {/*from  www.ja  v  a2  s.  c o  m*/
        // Open the content uri as input stream and this via a local temporary file
        addTorrentFromStream(getContentResolver().openInputStream(contentUri), title);
    } catch (SecurityException e) {
        // No longer access to this file
        log.e(this, "No access given to " + contentUri.toString() + ": " + e.toString());
        SnackbarManager.show(Snackbar.with(this).text(R.string.error_torrentfile).colorResource(R.color.red));
    } catch (FileNotFoundException e) {
        log.e(this, contentUri.toString() + " does not exist: " + e.toString());
        SnackbarManager.show(Snackbar.with(this).text(R.string.error_torrentfile).colorResource(R.color.red));
    }
}