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:org.lsc.jndi.FullDNJndiDstService.java

/**
 * The simple object getter according to its identifier.
 * /*from  www .j  a  v a  2s  . c o  m*/
 * @param dn DN of the entry to be returned, which is the name returned by {@link #getListPivots()}
 * @param pivotAttributes Unused.
 * @param fromSameService are the pivot attributes provided by the same service
 * @return The bean, or null if not found
 * @throws LscServiceException May throw a {@link NamingException} if the object is not found in the
 *             directory, or if more than one object would be returned. 
 */
public IBean getBean(String dn, LscDatasets pivotAttributes, boolean fromSameService)
        throws LscServiceException {

    try {
        SearchControls sc = new SearchControls();
        sc.setSearchScope(SearchControls.OBJECT_SCOPE);
        List<String> attrs = getAttrs();
        if (attrs != null) {
            sc.setReturningAttributes(attrs.toArray(new String[attrs.size()]));
        }
        SearchResult srObject = getJndiServices().readEntry(dn, getFilterId(), true, sc);
        Method method = beanClass.getMethod("getInstance",
                new Class[] { SearchResult.class, String.class, Class.class });
        return (IBean) method.invoke(null, new Object[] { srObject, jndiServices.completeDn(dn), beanClass });

    } catch (SecurityException e) {
        LOGGER.error(
                "Unable to get static method getInstance on {} ! This is probably a programmer's error ({})",
                beanClass.getName(), e);
        LOGGER.debug(e.toString(), e);
    } catch (NoSuchMethodException e) {
        LOGGER.error(
                "Unable to get static method getInstance on {} ! This is probably a programmer's error ({})",
                beanClass.getName(), e);
        LOGGER.debug(e.toString(), e);
    } catch (IllegalArgumentException e) {
        LOGGER.error(
                "Unable to get static method getInstance on {} ! This is probably a programmer's error ({})",
                beanClass.getName(), e);
        LOGGER.debug(e.toString(), e);
    } catch (IllegalAccessException e) {
        LOGGER.error(
                "Unable to get static method getInstance on {} ! This is probably a programmer's error ({})",
                beanClass.getName(), e);
        LOGGER.debug(e.toString(), e);
    } catch (InvocationTargetException e) {
        LOGGER.error(
                "Unable to get static method getInstance on {} ! This is probably a programmer's error ({})",
                beanClass.getName(), e);
        LOGGER.debug(e.toString(), e);
    } catch (NamingException e) {
        LOGGER.error("JNDI error while synchronizing {}: {} ", beanClass.getName(), e);
        LOGGER.debug(e.toString(), e);
        throw new LscServiceException(e.toString(), e);
    }
    return null;
}

From source file:org.sakaiproject.component.kerberos.user.KerberosUserDirectoryProvider.java

/**
 * Check if the user id is known to kerberos.
 * //  w ww .  j  a  v  a 2  s.co  m
 * @param user
 *        The user id.
 * @return true if successful, false if not.
 */
private boolean userKnownToKerberos(String user) {
    // use a dummy password
    String pw = "dummy";

    // Obtain a LoginContext, needed for authentication.
    // Tell it to use the LoginModule implementation specified
    // in the JAAS login configuration file and to use
    // use the specified CallbackHandler.
    LoginContext lc = null;
    try {
        CallbackHandler t = new UsernamePasswordCallback(user, pw);
        lc = new LoginContext(m_logincontext, t);
    } catch (LoginException le) {
        if (M_log.isDebugEnabled())
            M_log.debug("useKnownToKerberos(): " + le.toString());
        return false;
    } catch (SecurityException se) {
        if (M_log.isDebugEnabled())
            M_log.debug("useKnownToKerberos(): " + se.toString());
        return false;
    }

    try {
        // attempt authentication
        lc.login();
        lc.logout();

        if (M_log.isDebugEnabled())
            M_log.debug("useKnownToKerberos(" + user + "): Kerberos auth success");

        return true;
    } catch (LoginException le) {
        String msg = le.getMessage();

        // if this is the message, the user was good, the password was bad
        if (msg.startsWith(m_knownusermsg)) {
            if (M_log.isDebugEnabled())
                M_log.debug("userKnownToKerberos(" + user + "): Kerberos user known (bad pw)");

            return true;
        }

        // the other message is when the user is bad:
        if (M_log.isDebugEnabled())
            M_log.debug("userKnownToKerberos(" + user + "): Kerberos user unknown or invalid");

        return false;
    }

}

From source file:com.netfinworks.rest.convert.MultiPartFormDataParamConvert.java

private <T> Object getPropertyValue(T pojo, Class<?> clazz, String propertyName, String prefix)
        throws NoSuchMethodException {
    StringBuffer buf = new StringBuffer(propertyName);
    int char0 = buf.charAt(0);
    buf.setCharAt(0, (char) (char0 >= 97 ? char0 - 32 : char0));
    buf.insert(0, prefix);//from  w  ww.  j a  va2s.  co m
    Method m = null;
    try {
        m = clazz.getMethod(buf.toString(), emptyClazzArray);
        return m.invoke(pojo, new Object[0]);
    } catch (SecurityException e) {
        logger.debug("property can't be access! ");
        return null;
    } catch (NoSuchMethodException e) {
        logger.debug("property '{}' doesn't exist! ", buf.toString());
        throw e;
    } catch (IllegalArgumentException e) {
        logger.debug("method can't be invoke! wrong argument. " + e.toString());
        return null;
    } catch (IllegalAccessException e) {
        logger.debug("method can't be invoke! access exception. " + e.toString());
        return null;
    } catch (InvocationTargetException e) {
        logger.debug("method can't be invoke! invocation target. " + e.toString());
        return null;
    }

}

From source file:com.awt.supark.MainActivity.java

@Override
protected void onPause() {
    if (parkHandler.locationManager != null) {
        try {/*from w w  w.j a  v a2s .  c  o  m*/
            parkHandler.locationManager.removeUpdates(parkHandler);
        } catch (SecurityException e) {
            Log.i("SecExp", e.toString());
        }
    }
    super.onPause();
}

From source file:hack.ddakev.roadrant.MainActivity.java

@Override
public void onConnected(@Nullable Bundle bundle) {
    try {//w ww.  jav a2  s.c  o  m
        Location lastLoc = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
        if (lastLoc != null) {
            lat = lastLoc.getLatitude();
            lon = lastLoc.getLongitude();
        }

        LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, lr,
                (com.google.android.gms.location.LocationListener) this);
    } catch (SecurityException e) {
        System.out.println(e.toString());
    }
}

From source file:org.apache.jetspeed.portlets.spaces.PageNavigator.java

private List<NodeBean> getTemplatePageNodes(PortletRequest request) {
    List<NodeBean> templatePageNodes = (List<NodeBean>) request.getPortletSession(true)
            .getAttribute(TEMPLATE_PAGE_NODES);

    if (templatePageNodes == null) {
        templatePageNodes = new ArrayList<NodeBean>();

        String templatePages = request.getPreferences().getValue("templatePages", null);

        if (!StringUtils.isBlank(templatePages)) {
            String[] templatePagePaths = StringUtils.split(templatePages, ", \t\r\n");

            for (String templatePagePath : templatePagePaths) {
                try {
                    Page templatePage = pageManager.getPage(templatePagePath);
                    templatePageNodes.add(new NodeBean(templatePage));
                } catch (SecurityException e) {
                    // ignore security exception when retrieving template pages.
                } catch (Exception e) {
                    log.warn("Invalid template page path: " + templatePagePath + ". {}", e.toString());
                }//from  w  w w . j  a  va  2s  .c  o  m
            }
        }

        request.getPortletSession().setAttribute(TEMPLATE_PAGE_NODES, templatePageNodes);
    }

    return templatePageNodes;
}

From source file:org.powertac.logtool.common.DomainObjectReader.java

private void setId(Object thing, Long id) {
    Class<?> clazz = thing.getClass();
    Method setId;// w  ww  . ja v a  2s . c o m
    try {
        setId = clazz.getMethod("setId", long.class);
        setId.setAccessible(true);
        setId.invoke(thing, (long) id);
    } catch (SecurityException e) {
        log.error("Exception on setId(): " + e.toString());
    } catch (NoSuchMethodException e) {
        // normal result of no setId() method
        ReflectionTestUtils.setField(thing, "id", id);
    } catch (Exception e) {
        log.error("Error setting id value " + e.toString());
    }
}

From source file:org.powertac.logtool.common.DomainObjectReader.java

private Object resolveSimpleArg(Class<?> clazz, String arg) throws MissingDomainObject {
    // handle the simplest case first
    if (arg.equals("null"))
        return null;

    if (clazz.getName().startsWith("org.powertac")) {
        Method getId;//from   w w w  . j  a  va 2  s.co  m
        try {
            getId = clazz.getMethod("getId");
            if (getId.getReturnType() == long.class) {
                // this is a domain type; it may or may not be in the map
                Long key = Long.parseLong(arg);
                Object value = idMap.get(key);
                if (null != value) {
                    return value;
                } else {
                    // it's a domain object, but we cannot resolve it
                    // -- this should not happen.
                    log.info("Missing domain object " + key);
                    throw new MissingDomainObject("missing object id=" + key);
                }
            }
        } catch (SecurityException e) {
            log.error("Exception on getId(): " + e.toString());
            return null;
        } catch (NoSuchMethodException e) {
            // normal result of no getId() method
        } catch (NumberFormatException e) {
            // normal result of non-integer id value
        }
    }

    // arg is not an id value - check if it's supposed to be a primitive
    if (clazz.getName().equals("boolean")) {
        boolean value = Boolean.parseBoolean(arg);
        if (value) {
            return true; // resolved as boolean
        } else if (arg.equalsIgnoreCase("false")) {
            return false; // resolved as boolean
        } else
            return null; // does not resolve
    }

    if (clazz.getName().equals("long")) {
        try {
            long value = Long.parseLong(arg);
            return value;
        } catch (NumberFormatException nfe) {
            // not a long
            return null;
        }
    }

    if (clazz.getName().equals("int")) {
        try {
            int value = Integer.parseInt(arg);
            return value;
        } catch (NumberFormatException nfe) {
            // not an int
            return null;
        }
    }

    if (clazz.getName().equals("double") || clazz == Double.class) {
        try {
            double value = Double.parseDouble(arg);
            return value;
        } catch (NumberFormatException nfe) {
            // not a double
            return null;
        }
    }

    if (clazz.getName() == "java.lang.Double") {

    }

    // check for time value
    if (clazz.getName() == "org.joda.time.Instant") {
        try {
            Instant value = Instant.parse(arg);
            return value;
        } catch (IllegalArgumentException iae) {
            // make Instant from Long
            try {
                Long msec = Long.parseLong(arg);
                return new Instant(msec);
            } catch (Exception e) {
                // Long parse failure
                log.error("could not parse Long " + arg);
                return null;
            }
        } catch (Exception e) {
            // Instant parse failure
            log.error("could not parse Instant " + arg);
            return null;
        }
    }

    // check for type with String constructor
    try {
        Constructor<?> cons = clazz.getConstructor(String.class);
        return cons.newInstance(arg);
    } catch (NoSuchMethodException e) {
        // normal result of failure - fall through and try something else
    } catch (Exception e) {
        log.error("Exception looking up constructor for " + clazz.getName() + ": " + e.toString());
        return null;
    }
    // no type matched
    return null;
}

From source file:org.codehaus.plexus.archiver.zip.AbstractZipArchiver.java

private void createArchiveMain() throws ArchiverException, IOException {
    //noinspection deprecation
    if (!Archiver.DUPLICATES_SKIP.equals(duplicate)) {
        //noinspection deprecation
        setDuplicateBehavior(duplicate);
    }/*ww w  . ja v a2  s  .  c o  m*/

    ResourceIterator iter = getResources();
    if (!iter.hasNext() && !hasVirtualFiles()) {
        throw new ArchiverException("You must set at least one file.");
    }

    zipFile = getDestFile();

    if (zipFile == null) {
        throw new ArchiverException("You must set the destination " + archiveType + "file.");
    }

    if (zipFile.exists() && !zipFile.isFile()) {
        throw new ArchiverException(zipFile + " isn't a file.");
    }

    if (zipFile.exists() && !zipFile.canWrite()) {
        throw new ArchiverException(zipFile + " is read-only.");
    }

    // Whether or not an actual update is required -
    // we don't need to update if the original file doesn't exist

    addingNewFiles = true;

    if (doUpdate && !zipFile.exists()) {
        doUpdate = false;
        getLogger().debug("ignoring update attribute as " + archiveType + " doesn't exist.");
    }

    success = false;

    if (doUpdate) {
        renamedFile = FileUtils.createTempFile("zip", ".tmp", zipFile.getParentFile());
        renamedFile.deleteOnExit();

        try {
            FileUtils.rename(zipFile, renamedFile);
        } catch (SecurityException e) {
            getLogger().debug(e.toString());
            throw new ArchiverException(
                    "Not allowed to rename old file (" + zipFile.getAbsolutePath() + ") to temporary file", e);
        } catch (IOException e) {
            getLogger().debug(e.toString());
            throw new ArchiverException(
                    "Unable to rename old file (" + zipFile.getAbsolutePath() + ") to temporary file", e);
        }
    }

    String action = doUpdate ? "Updating " : "Building ";

    getLogger().info(action + archiveType + ": " + zipFile.getAbsolutePath());

    if (!skipWriting) {
        zipArchiveOutputStream = new ZipArchiveOutputStream(
                bufferedOutputStream(fileOutputStream(zipFile, "zip")));
        zipArchiveOutputStream.setEncoding(encoding);
        zipArchiveOutputStream
                .setCreateUnicodeExtraFields(ZipArchiveOutputStream.UnicodeExtraFieldPolicy.NOT_ENCODEABLE);
        zipArchiveOutputStream
                .setMethod(doCompress ? ZipArchiveOutputStream.DEFLATED : ZipArchiveOutputStream.STORED);

        zOut = new ConcurrentJarCreator(Runtime.getRuntime().availableProcessors());
    }
    initZipOutputStream(zOut);

    // Add the new files to the archive.
    addResources(iter, zOut);

    // If we've been successful on an update, delete the
    // temporary file
    if (doUpdate) {
        if (!renamedFile.delete()) {
            getLogger().warn("Warning: unable to delete temporary file " + renamedFile.getName());
        }
    }
    success = true;
}

From source file:tw.com.geminihsu.app01.fragment.Fragment_Client_Service_test.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    switch (requestCode) {
    case MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION: {
        // If request is cancelled, the result arrays are empty.
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            Toast.makeText(getActivity(), "permission was granted, :)", Toast.LENGTH_LONG).show();

            try {
                LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest,
                        this);
            } catch (SecurityException e) {
                Toast.makeText(getActivity(), "SecurityException:\n" + e.toString(), Toast.LENGTH_LONG).show();
            }/* w  ww  . j a  v a  2 s.  c o m*/
        } else {
            Toast.makeText(getActivity(), "permission denied, ...:(", Toast.LENGTH_LONG).show();
        }
        return;
    }

    }
}