Example usage for java.lang SecurityException SecurityException

List of usage examples for java.lang SecurityException SecurityException

Introduction

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

Prototype

public SecurityException() 

Source Link

Document

Constructs a SecurityException with no detail message.

Usage

From source file:org.traccar.web.server.model.DataServiceImpl.java

@Override
public User removeUser(User user) {
    User currentUser = getSessionUser();
    if (currentUser.getAdmin()) {
        EntityManager entityManager = getSessionEntityManager();
        synchronized (entityManager) {
            entityManager.getTransaction().begin();
            try {
                user = entityManager.merge(user);
                user.getDevices().clear();
                entityManager.remove(user);
                entityManager.getTransaction().commit();
                return user;
            } catch (RuntimeException e) {
                entityManager.getTransaction().rollback();
                throw e;
            }//from w  ww.jav  a2s .  c  om
        }
    } else {
        throw new SecurityException();
    }
}

From source file:eu.geopaparazzi.library.gps.GpsService.java

/**
 * Starts listening to the gps provider.
 *///  www  .jav  a  2  s .co  m
private void registerForLocationUpdates() {
    try {
        if (isMockMode) {
            log("Gps started using Mock locations");
            TestMock.startMocking(locationManager, this);
            isListeningForUpdates = true;
        } else {
            float minDistance = 0.2f;
            long waitForSecs = WAITSECONDS;

            if (ActivityCompat.checkSelfPermission(this,
                    Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                throw new SecurityException();
            }
            if (useNetworkPositions) {
                locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, waitForSecs * 1000l,
                        minDistance, this);
            } else {
                locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, waitForSecs * 1000l,
                        minDistance, this);
            }
            isListeningForUpdates = true;
            log("registered for updates.");
        }
        broadcast("triggered by registerForLocationUpdates");
    } catch (Exception e) {
        GPLog.error(this, null, e);
        isListeningForUpdates = false;
    }
}

From source file:org.traccar.web.server.model.DataServiceImpl.java

@Override
public ApplicationSettings updateApplicationSettings(ApplicationSettings applicationSettings) {
    if (applicationSettings == null) {
        return getApplicationSettings();
    } else {/*  w w w . j av  a  2  s  .c o  m*/
        EntityManager entityManager = getServletEntityManager();
        synchronized (entityManager) {
            User user = getSessionUser();
            if (user.getAdmin()) {
                entityManager.getTransaction().begin();
                try {
                    entityManager.merge(applicationSettings);
                    entityManager.getTransaction().commit();
                    this.applicationSettings = applicationSettings;
                    return applicationSettings;
                } catch (RuntimeException e) {
                    entityManager.getTransaction().rollback();
                    throw e;
                }
            } else {
                throw new SecurityException();
            }
        }
    }
}

From source file:com.owncloud.android.ui.activity.Uploader.java

public void uploadFiles() {
    try {//from ww w.  j  av  a  2 s.  co  m

        // ArrayList for files with path in external storage
        ArrayList<String> local = new ArrayList<String>();
        ArrayList<String> remote = new ArrayList<String>();

        // this checks the mimeType 
        for (Parcelable mStream : mStreamsToUpload) {

            Uri uri = (Uri) mStream;
            String data = null;
            String filePath = "";

            if (uri != null) {
                if (uri.getScheme().equals("content")) {
                    String mimeType = getContentResolver().getType(uri);

                    if (mimeType.contains("image")) {
                        String[] CONTENT_PROJECTION = { Images.Media.DATA, Images.Media.DISPLAY_NAME,
                                Images.Media.MIME_TYPE, Images.Media.SIZE };
                        Cursor c = getContentResolver().query(uri, CONTENT_PROJECTION, null, null, null);
                        c.moveToFirst();
                        int index = c.getColumnIndex(Images.Media.DATA);
                        data = c.getString(index);
                        filePath = mUploadPath + c.getString(c.getColumnIndex(Images.Media.DISPLAY_NAME));

                    } else if (mimeType.contains("video")) {
                        String[] CONTENT_PROJECTION = { Video.Media.DATA, Video.Media.DISPLAY_NAME,
                                Video.Media.MIME_TYPE, Video.Media.SIZE, Video.Media.DATE_MODIFIED };
                        Cursor c = getContentResolver().query(uri, CONTENT_PROJECTION, null, null, null);
                        c.moveToFirst();
                        int index = c.getColumnIndex(Video.Media.DATA);
                        data = c.getString(index);
                        filePath = mUploadPath + c.getString(c.getColumnIndex(Video.Media.DISPLAY_NAME));

                    } else if (mimeType.contains("audio")) {
                        String[] CONTENT_PROJECTION = { Audio.Media.DATA, Audio.Media.DISPLAY_NAME,
                                Audio.Media.MIME_TYPE, Audio.Media.SIZE };
                        Cursor c = getContentResolver().query(uri, CONTENT_PROJECTION, null, null, null);
                        c.moveToFirst();
                        int index = c.getColumnIndex(Audio.Media.DATA);
                        data = c.getString(index);
                        filePath = mUploadPath + c.getString(c.getColumnIndex(Audio.Media.DISPLAY_NAME));

                    } else {
                        Cursor cursor = getContentResolver().query(uri,
                                new String[] { MediaStore.MediaColumns.DISPLAY_NAME }, null, null, null);
                        cursor.moveToFirst();
                        int nameIndex = cursor.getColumnIndex(cursor.getColumnNames()[0]);
                        if (nameIndex >= 0) {
                            filePath = mUploadPath + cursor.getString(nameIndex);
                        }
                    }

                } else if (uri.getScheme().equals("file")) {
                    filePath = Uri.decode(uri.toString()).replace(uri.getScheme() + "://", "");
                    if (filePath.contains("mnt")) {
                        String splitedFilePath[] = filePath.split("/mnt");
                        filePath = splitedFilePath[1];
                    }
                    final File file = new File(filePath);
                    data = file.getAbsolutePath();
                    filePath = mUploadPath + file.getName();
                } else {
                    throw new SecurityException();
                }
                if (data == null) {
                    mRemoteCacheData.add(filePath);
                    CopyTmpFileAsyncTask copyTask = new CopyTmpFileAsyncTask(this);
                    Object[] params = { uri, filePath, mRemoteCacheData.size() - 1, getAccount().name,
                            getContentResolver() };
                    mNumCacheFile++;
                    showWaitingCopyDialog();
                    copyTask.execute(params);
                } else {
                    remote.add(filePath);
                    local.add(data);
                }
            } else {
                throw new SecurityException();
            }

            Intent intent = new Intent(getApplicationContext(), FileUploader.class);
            intent.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_MULTIPLE_FILES);
            intent.putExtra(FileUploader.KEY_LOCAL_FILE, local.toArray(new String[local.size()]));
            intent.putExtra(FileUploader.KEY_REMOTE_FILE, remote.toArray(new String[remote.size()]));
            intent.putExtra(FileUploader.KEY_ACCOUNT, getAccount());
            startService(intent);

            //Save the path to shared preferences
            SharedPreferences.Editor appPrefs = PreferenceManager
                    .getDefaultSharedPreferences(getApplicationContext()).edit();
            appPrefs.putString("last_upload_path", mUploadPath);
            appPrefs.apply();

            finish();
        }

    } catch (SecurityException e) {
        String message = String.format(getString(R.string.uploader_error_forbidden_content),
                getString(R.string.app_name));
        Toast.makeText(this, message, Toast.LENGTH_LONG).show();
    }
}

From source file:com.amazonaws.client.metrics.AwsSdkMetrics.java

/**
 * Returns the credential provider for the default AWS SDK metric implementation.
 * This method is restricted to calls from the default AWS SDK metric implementation.
 * /*  w  w  w  .  j ava 2 s.c  o  m*/
 * @throws SecurityException if called outside the default AWS SDK metric implementation.
 */
public static AWSCredentialsProvider getCredentialProvider() {
    StackTraceElement[] e = Thread.currentThread().getStackTrace();
    for (int i = 0; i < e.length; i++) {
        if (e[i].getClassName().equals(DEFAULT_METRIC_COLLECTOR_FACTORY)) {
            return credentialProvider;
        }
    }
    SecurityException ex = new SecurityException();
    LogFactory.getLog(AwsSdkMetrics.class).warn("Illegal attempt to access the credential provider", ex);
    throw ex;
}

From source file:com.synox.android.ui.activity.Uploader.java

public void uploadFiles() {
    try {/*from w  w w  .j  a  va 2s  .  co  m*/

        // ArrayList for files with path in external storage
        ArrayList<String> local = new ArrayList<>();
        ArrayList<String> remote = new ArrayList<>();

        // this checks the mimeType
        for (Parcelable mStream : mStreamsToUpload) {

            Uri uri = (Uri) mStream;
            String data = null;
            String filePath = "";

            if (uri != null) {
                if (uri.getScheme().equals("content")) {
                    String mimeType = getContentResolver().getType(uri);

                    if (mimeType.contains("image")) {
                        String[] CONTENT_PROJECTION = { Images.Media.DATA, Images.Media.DISPLAY_NAME,
                                Images.Media.MIME_TYPE, Images.Media.SIZE };
                        Cursor c = getContentResolver().query(uri, CONTENT_PROJECTION, null, null, null);
                        c.moveToFirst();
                        int index = c.getColumnIndex(Images.Media.DATA);
                        data = c.getString(index);
                        filePath = mUploadPath + c.getString(c.getColumnIndex(Images.Media.DISPLAY_NAME));

                    } else if (mimeType.contains("video")) {
                        String[] CONTENT_PROJECTION = { Video.Media.DATA, Video.Media.DISPLAY_NAME,
                                Video.Media.MIME_TYPE, Video.Media.SIZE, Video.Media.DATE_MODIFIED };
                        Cursor c = getContentResolver().query(uri, CONTENT_PROJECTION, null, null, null);
                        c.moveToFirst();
                        int index = c.getColumnIndex(Video.Media.DATA);
                        data = c.getString(index);
                        filePath = mUploadPath + c.getString(c.getColumnIndex(Video.Media.DISPLAY_NAME));

                    } else if (mimeType.contains("audio")) {
                        String[] CONTENT_PROJECTION = { Audio.Media.DATA, Audio.Media.DISPLAY_NAME,
                                Audio.Media.MIME_TYPE, Audio.Media.SIZE };
                        Cursor c = getContentResolver().query(uri, CONTENT_PROJECTION, null, null, null);
                        c.moveToFirst();
                        int index = c.getColumnIndex(Audio.Media.DATA);
                        data = c.getString(index);
                        filePath = mUploadPath + c.getString(c.getColumnIndex(Audio.Media.DISPLAY_NAME));

                    } else {
                        Cursor cursor = getContentResolver().query(uri,
                                new String[] { MediaStore.MediaColumns.DISPLAY_NAME }, null, null, null);
                        cursor.moveToFirst();
                        int nameIndex = cursor.getColumnIndex(cursor.getColumnNames()[0]);
                        if (nameIndex >= 0) {
                            filePath = mUploadPath + cursor.getString(nameIndex);
                        }
                    }

                } else if (uri.getScheme().equals("file")) {
                    filePath = Uri.decode(uri.toString()).replace(uri.getScheme() + "://", "");
                    if (filePath.contains("mnt")) {
                        String splitedFilePath[] = filePath.split("/mnt");
                        filePath = splitedFilePath[1];
                    }
                    final File file = new File(filePath);
                    data = file.getAbsolutePath();
                    filePath = mUploadPath + file.getName();
                } else {
                    throw new SecurityException();
                }
                if (data == null) {
                    mRemoteCacheData.add(filePath);
                    CopyTmpFileAsyncTask copyTask = new CopyTmpFileAsyncTask(this);
                    Object[] params = { uri, filePath, mRemoteCacheData.size() - 1, getAccount().name,
                            getContentResolver() };
                    mNumCacheFile++;
                    showWaitingCopyDialog();
                    copyTask.execute(params);
                } else {
                    remote.add(filePath);
                    local.add(data);
                }
            } else {
                throw new SecurityException();
            }

            Intent intent = new Intent(getApplicationContext(), FileUploader.class);
            intent.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_MULTIPLE_FILES);
            intent.putExtra(FileUploader.KEY_LOCAL_FILE, local.toArray(new String[local.size()]));
            intent.putExtra(FileUploader.KEY_REMOTE_FILE, remote.toArray(new String[remote.size()]));
            intent.putExtra(FileUploader.KEY_ACCOUNT, getAccount());
            startService(intent);

            //Save the path to shared preferences
            SharedPreferences.Editor appPrefs = PreferenceManager
                    .getDefaultSharedPreferences(getApplicationContext()).edit();
            appPrefs.putString("last_upload_path", mUploadPath);
            appPrefs.apply();

            finish();
        }

    } catch (SecurityException e) {
        String message = String.format(getString(R.string.uploader_error_forbidden_content),
                getString(R.string.app_name));
        Toast.makeText(this, message, Toast.LENGTH_LONG).show();
    } catch (NullPointerException npe) {
        Log_OC.e(this.getClass().getName(), "Unknown error occurred. Message: " + npe.getLocalizedMessage());
    }
}

From source file:com.cerema.cloud2.ui.activity.Uploader.java

public void uploadFiles() {
    try {//from w  ww  .  j a v a2 s .c o m

        // ArrayList for files with path in external storage
        ArrayList<String> local = new ArrayList<String>();
        ArrayList<String> remote = new ArrayList<String>();

        // this checks the mimeType 
        for (Parcelable mStream : mStreamsToUpload) {

            Uri uri = (Uri) mStream;
            String data = null;
            String filePath = "";

            if (uri != null) {
                if (uri.getScheme().equals("content")) {
                    String mimeType = getContentResolver().getType(uri);

                    if (mimeType.contains("image")) {
                        String[] CONTENT_PROJECTION = { Images.Media.DATA, Images.Media.DISPLAY_NAME,
                                Images.Media.MIME_TYPE, Images.Media.SIZE };
                        Cursor c = getContentResolver().query(uri, CONTENT_PROJECTION, null, null, null);
                        c.moveToFirst();
                        int index = c.getColumnIndex(Images.Media.DATA);
                        data = c.getString(index);
                        local.add(data);
                        remote.add(mUploadPath + c.getString(c.getColumnIndex(Images.Media.DISPLAY_NAME)));

                    } else if (mimeType.contains("video")) {
                        String[] CONTENT_PROJECTION = { Video.Media.DATA, Video.Media.DISPLAY_NAME,
                                Video.Media.MIME_TYPE, Video.Media.SIZE, Video.Media.DATE_MODIFIED };
                        Cursor c = getContentResolver().query(uri, CONTENT_PROJECTION, null, null, null);
                        c.moveToFirst();
                        int index = c.getColumnIndex(Video.Media.DATA);
                        data = c.getString(index);
                        local.add(data);
                        remote.add(mUploadPath + c.getString(c.getColumnIndex(Video.Media.DISPLAY_NAME)));

                    } else if (mimeType.contains("audio")) {
                        String[] CONTENT_PROJECTION = { Audio.Media.DATA, Audio.Media.DISPLAY_NAME,
                                Audio.Media.MIME_TYPE, Audio.Media.SIZE };
                        Cursor c = getContentResolver().query(uri, CONTENT_PROJECTION, null, null, null);
                        c.moveToFirst();
                        int index = c.getColumnIndex(Audio.Media.DATA);
                        data = c.getString(index);
                        local.add(data);
                        remote.add(mUploadPath + c.getString(c.getColumnIndex(Audio.Media.DISPLAY_NAME)));

                    } else {
                        filePath = Uri.decode(uri.toString()).replace(uri.getScheme() + "://", "");
                        // cut everything whats before mnt. It occured to me that sometimes apps send
                        // their name into the URI
                        if (filePath.contains("mnt")) {
                            String splitedFilePath[] = filePath.split("/mnt");
                            filePath = splitedFilePath[1];
                        }
                        final File file = new File(filePath);
                        local.add(file.getAbsolutePath());
                        remote.add(mUploadPath + file.getName());
                    }
                } else if (uri.getScheme().equals("file")) {
                    filePath = Uri.decode(uri.toString()).replace(uri.getScheme() + "://", "");
                    if (filePath.contains("mnt")) {
                        String splitedFilePath[] = filePath.split("/mnt");
                        filePath = splitedFilePath[1];
                    }
                    final File file = new File(filePath);
                    data = file.getAbsolutePath();
                    filePath = mUploadPath + file.getName();
                } else {
                    throw new SecurityException();
                }
                if (data == null) {
                    mRemoteCacheData.add(filePath);
                    CopyTmpFileAsyncTask copyTask = new CopyTmpFileAsyncTask(this);
                    Object[] params = { uri, filePath, mRemoteCacheData.size() - 1, getAccount().name,
                            getContentResolver() };
                    mNumCacheFile++;
                    showWaitingCopyDialog();
                    copyTask.execute(params);
                }
            } else {
                throw new SecurityException();
            }

            Intent intent = new Intent(getApplicationContext(), FileUploader.class);
            intent.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_MULTIPLE_FILES);
            intent.putExtra(FileUploader.KEY_LOCAL_FILE, local.toArray(new String[local.size()]));
            intent.putExtra(FileUploader.KEY_REMOTE_FILE, remote.toArray(new String[remote.size()]));
            intent.putExtra(FileUploader.KEY_ACCOUNT, getAccount());
            startService(intent);

            //Save the path to shared preferences
            SharedPreferences.Editor appPrefs = PreferenceManager
                    .getDefaultSharedPreferences(getApplicationContext()).edit();
            appPrefs.putString("last_upload_path", mUploadPath);
            appPrefs.apply();

            finish();
        }

    } catch (SecurityException e) {
        String message = String.format(getString(R.string.uploader_error_forbidden_content),
                getString(R.string.app_name));
        Toast.makeText(this, message, Toast.LENGTH_LONG).show();
    }
}

From source file:eu.geopaparazzi.library.gps.GpsService.java

public void onGpsStatusChanged(int event) {
    if (ActivityCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        throw new SecurityException();
    }//from  w  w w. j  av  a  2s .  com
    mStatus = locationManager.getGpsStatus(mStatus);

    // check fix
    boolean tmpGotFix = GpsStatusInfo.checkFix(gotFix, lastLocationupdateMillis, event);
    if (!tmpGotFix) {
        // check if it is just standing still
        GpsStatusInfo info = new GpsStatusInfo(mStatus);
        int satForFixCount = info.getSatUsedInFixCount();
        if (satForFixCount > 2) {
            tmpGotFix = true;
            // updating loc update, assuming the still filter is giving troubles
            lastLocationupdateMillis = SystemClock.elapsedRealtime();
        }
    }

    // if (DOLOGPOSITION) {
    // StringBuilder sb = new StringBuilder();
    // sb.append("gotFix: ").append(gotFix).append(" tmpGotFix: ").append(tmpGotFix).append("\n");
    // GPLog.addLogEntry("GPSSERVICE", sb.toString());
    // }

    if (tmpGotFix != gotFix) {
        gotFix = tmpGotFix;
        broadcast("triggered by onGpsStatusChanged on fix change: " + gotFix);
    } else {
        gotFix = tmpGotFix;
        if (!tmpGotFix && isProviderEnabled) {
            broadcast("triggered by onGpsStatusChanged on fix change: " + gotFix);
        }
    }

    if (!gotFix) {
        lastGpsLocation = null;
    }
}

From source file:com.ksc.metrics.KscSdkMetrics.java

/**
 * Returns the credential provider for the default AWS SDK metric implementation.
 * This method is restricted to calls from the default AWS SDK metric implementation.
 *
 * @throws SecurityException if called outside the default AWS SDK metric implementation.
 *///  ww  w .java2s.c  o  m
public static AWSCredentialsProvider getCredentialProvider() {
    StackTraceElement[] e = Thread.currentThread().getStackTrace();
    for (int i = 0; i < e.length; i++) {
        if (e[i].getClassName().equals(DEFAULT_METRIC_COLLECTOR_FACTORY)) {
            return credentialProvider;
        }
    }
    SecurityException ex = new SecurityException();
    LogFactory.getLog(KscSdkMetrics.class).warn("Illegal attempt to access the credential provider", ex);
    throw ex;
}

From source file:net.creativeparkour.GameManager.java

static void supprimerFichiersTemps(UUID uuidJoueur, UUID uuidMap, boolean ajouterExclusion) {
    if (uuidJoueur == null && uuidMap == null)
        throw new SecurityException();
    else {/*from   w  w w. jav  a2 s  .  c o  m*/
        List<String> exclusions = exclusions_temps.getStringList("list");
        for (File f : getFichiersTemps()) {
            Map<String, UUID> uuids = CPUtils.timeFileUUIDs(f.getName());
            if ((uuidJoueur == null || uuids.get("player").equals(uuidJoueur))
                    && (uuidMap == null || uuids.get("map").equals(uuidMap))) {
                f.delete();
                String nomFichier = f.getName().replace(".yml", "");
                if (!exclusions.contains(nomFichier) && ajouterExclusion)
                    exclusions.add(nomFichier);
            }
        }
        exclusions_temps.set("list", exclusions);
        try {
            exclusions_temps.save(fichier_exclusions_temps);
        } catch (IOException e) {
            Bukkit.getLogger()
                    .warning("An error occured while loading file 'CreativeParkour/deleted times.yml'");
            e.printStackTrace();
        }
    }
}