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(Throwable cause) 

Source Link

Document

Creates a SecurityException with the specified cause and a detail message of (cause==null ?

Usage

From source file:org.onecmdb.core.utils.wsdl.OneCMDBWebServiceImpl.java

public RFCBean[] compare(String auth, CiBean[] local, CiBean[] base, String[] keys) {
    long start = System.currentTimeMillis();
    log.info("WSDL: compare(" + auth + ", " + local + ", " + base + ")");
    // Update all beans.
    ISession session = onecmdb.getSession(auth);
    if (session == null) {
        throw new SecurityException("No Session found! Try to do auth() first!");
    }/*from www  .  java  2s  .co  m*/

    ImportBeanProvider importBeans = new ImportBeanProvider();
    importBeans.setValidation(false);
    importBeans.setSession(session);
    importBeans.setProvider(new MemoryBeanProvider(local));
    if (base != null) {
        importBeans.setBaseProvider(new MemoryBeanProvider(base));
    }

    List<IRFC> rfcs = importBeans.compare();
    List<RFCBean> rfcBeans = convert(session, rfcs);
    long stop = System.currentTimeMillis();
    log.info("WSDL: compare completed in " + (stop - start) + "ms result = " + rfcBeans.size());
    return (rfcBeans.toArray(new RFCBean[0]));
}

From source file:it.eng.spagobi.behaviouralmodel.lov.bo.QueryDetail.java

private void validateNumber(String value) {
    if (!(GenericValidator.isInt(value) || GenericValidator.isFloat(value) || GenericValidator.isDouble(value)
            || GenericValidator.isShort(value) || GenericValidator.isLong(value))) {
        throw new SecurityException("Input value " + value + " is not a valid number");
    }//from w  w w . j  av a 2  s. co m
}

From source file:com.google.android.apps.dashclock.DashClockService.java

private void enforceRegisteredCallingCallback(IDataConsumerHostCallback cb) {
    if (cb == null || !mRegisteredCallbacks.containsKey(cb.asBinder())) {
        throw new SecurityException("Caller should provide a registered callback.");
    }// w w w .  ja  v a  2s.  c om
}

From source file:org.mariotaku.twidere.provider.TwidereDataProvider.java

private void checkWritePermission(final int id, final String table) {
    switch (id) {
    case TABLE_ID_ACCOUNTS: {
        // Writing to accounts database is not allowed for third-party
        // applications.
        if (!mPermissionsManager.checkSignature(Binder.getCallingUid()))
            throw new SecurityException(
                    "Writing to accounts database is not allowed for third-party applications");
        break;/*from ww w .  ja v  a  2s . c o  m*/
    }
    case TABLE_ID_DIRECT_MESSAGES:
    case TABLE_ID_DIRECT_MESSAGES_INBOX:
    case TABLE_ID_DIRECT_MESSAGES_OUTBOX:
    case TABLE_ID_DIRECT_MESSAGES_CONVERSATION:
    case TABLE_ID_DIRECT_MESSAGES_CONVERSATION_SCREEN_NAME:
    case TABLE_ID_DIRECT_MESSAGES_CONVERSATIONS_ENTRY: {
        if (!checkPermission(PERMISSION_DIRECT_MESSAGES))
            throw new SecurityException(
                    "Access database " + table + " requires level PERMISSION_LEVEL_DIRECT_MESSAGES");
        break;
    }
    case TABLE_ID_STATUSES:
    case TABLE_ID_MENTIONS:
    case TABLE_ID_TABS:
    case TABLE_ID_DRAFTS:
    case TABLE_ID_CACHED_USERS:
    case TABLE_ID_FILTERED_USERS:
    case TABLE_ID_FILTERED_KEYWORDS:
    case TABLE_ID_FILTERED_SOURCES:
    case TABLE_ID_FILTERED_LINKS:
    case TABLE_ID_TRENDS_LOCAL:
    case TABLE_ID_CACHED_STATUSES:
    case TABLE_ID_CACHED_HASHTAGS: {
        if (!checkPermission(PERMISSION_WRITE))
            throw new SecurityException("Access database " + table + " requires level PERMISSION_LEVEL_WRITE");
        break;
    }
    }
}

From source file:br.gov.jfrj.siga.cd.AssinaturaDigital.java

/**
 * Read an existing PKCS#7 object from a DER encoded byte array
 *//*from www.  j  ava2s.co  m*/
protected static org.bouncycastle.asn1.cms.SignedData cmsSignedData(byte[] in) {
    ASN1InputStream din = new ASN1InputStream(new ByteArrayInputStream(in));

    //
    // Basic checks to make sure it's a PKCS#7 SignedData Object
    //
    ASN1Primitive cms;

    try {
        cms = din.readObject();
    } catch (IOException e) {
        throw new SecurityException("can't decode CMSSignedData object");
    } finally {
        try {
            din.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    if (!(cms instanceof ASN1Sequence)) {
        throw new SecurityException("Not a valid PKCS#7 object - not a sequence");
    }

    ContentInfo content = ContentInfo.getInstance(cms);

    org.bouncycastle.asn1.cms.SignedData data = org.bouncycastle.asn1.cms.SignedData
            .getInstance(content.getContent());

    return data;
}

From source file:it.eng.spagobi.behaviouralmodel.lov.bo.QueryDetail.java

private void validateDate(String value) {
    String dateFormat = GeneralUtilities.getServerDateFormat();
    String timestampFormat = GeneralUtilities.getServerTimeStampFormat();
    if (!GenericValidator.isDate(value, dateFormat, true)
            && !GenericValidator.isDate(value, timestampFormat, true)) {
        throw new SecurityException(
                "Input value " + value + " is not a valid date according to the date format " + dateFormat
                        + " or timestamp format " + timestampFormat);
    }//from  ww w. j  av  a 2  s.  c o  m
}

From source file:org.sakaiproject.iclicker.logic.IClickerLogic.java

/**
 * Verify the passed in encrypted SSO shared key is valid,
 * this will return false if the key is not configured
 * //  w  w w .jav  a 2 s.c  o  m
 * Key must have been encoded like so (where timestamp is the unix time in seconds):
 * sentKey = hex(sha1(sharedKey + ":" + timestamp)) + "|" + timestamp
 * 
 * @param key the passed in key (should already be sha-1 and hex encoded with the timestamp appended)
 * @return true if the key is valid, false if SSO shared keys are disabled
 * @throws IllegalArgumentException if the key format is invalid
 * @throws SecurityException if the key timestamp has expired or the key does not match
 */
public boolean verifyKey(String key) {
    if (StringUtils.isEmpty(key)) {
        throw new IllegalArgumentException("key must be set in order to verify the key");
    }
    boolean verified = false;
    if (singleSignOnHandling) {
        // encoding process requires the key and timestamp so split them from the passed in key
        int splitIndex = key.lastIndexOf('|');
        if ((splitIndex == -1) || (key.length() < splitIndex + 1)) {
            throw new IllegalArgumentException("i>clicker shared key (" + key
                    + ") format is invalid (no |), must be {encoded key}|{timestamp}");
        }
        String actualKey = key.substring(0, splitIndex);
        if (StringUtils.isEmpty(actualKey)) {
            throw new IllegalArgumentException("i>clicker shared key (" + key
                    + ") format is invalid (missing encoded key), must be {encoded key}|{timestamp}");
        }
        String timestampStr = key.substring(splitIndex + 1);
        if (StringUtils.isEmpty(timestampStr)) {
            throw new IllegalArgumentException("i>clicker shared key (" + key
                    + ") format is invalid (missing timestamp), must be {encoded key}|{timestamp}");
        }
        long timestamp;
        try {
            timestamp = Long.parseLong(timestampStr);
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("i>clicker shared key (" + key
                    + ") format is invalid (non numeric timestamp), must be {encoded key}|{timestamp}");
        }

        // check this key is still good (must be within 5 mins of now)
        long unixTime = System.currentTimeMillis() / 1000l;
        long timeDiff = Math.abs(timestamp - unixTime);
        if (timeDiff > 300l) {
            throw new SecurityException(
                    "i>clicker shared key (" + key + ") timestamp is out of date, this timestamp (" + timestamp
                            + ") is more than 5 minutes different from the current time (" + unixTime + ")");
        }

        // finally we verify the key with the one in the config
        byte[] sha1Bytes = DigestUtils.sha(singleSignOnSharedkey + ":" + timestamp);
        String sha1Hex = Hex.encodeHexString(sha1Bytes);
        if (!actualKey.equals(sha1Hex)) {
            throw new SecurityException(
                    "i>clicker encoded shared key (" + key + ") does not match with the key (" + sha1Hex
                            + ") in Sakai (using timestamp: " + timestamp + ")");
        }
        verified = true;
    }
    return verified;
}

From source file:com.google.android.apps.dashclock.DashClockService.java

private void enforceEnabledExtensionForCallback(IDataConsumerHostCallback cb, ComponentName extension) {
    enforceRegisteredCallingCallback(cb);
    List<ComponentName> extensions = mRegisteredCallbacks.get(cb.asBinder()).mExtensions;
    for (ComponentName ext : extensions) {
        if (ext.equals(extension)) {
            return;
        }//from  ww  w . j  a  v a2  s .co m
    }
    throw new SecurityException("Extension is not enabled for caller.");
}

From source file:com.csipsimple.db.DBProvider.java

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {

    // Constructs a new query builder and sets its table name
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    String finalSortOrder = sortOrder;
    String[] finalSelectionArgs = selectionArgs;
    String finalGrouping = null;//from ww w.  j  av a2s .  com
    String finalHaving = null;
    int type = URI_MATCHER.match(uri);

    Uri regUri = uri;

    // Security check to avoid data retrieval from outside
    int remoteUid = Binder.getCallingUid();
    int selfUid = android.os.Process.myUid();
    if (remoteUid != selfUid) {
        if (type == ACCOUNTS || type == ACCOUNTS_ID) {
            for (String proj : projection) {
                if (proj.toLowerCase().contains(SipProfile.FIELD_DATA) || proj.toLowerCase().contains("*")) {
                    throw new SecurityException("Password not readable from external apps");
                }
            }
        }
    }
    // Security check to avoid project of invalid fields or lazy projection
    List<String> possibles = getPossibleFieldsForType(type);
    if (possibles == null) {
        throw new SecurityException("You are asking wrong values " + type);
    }
    checkProjection(possibles, projection);
    checkSelection(possibles, selection);

    Cursor c;
    long id;
    switch (type) {
    case ACCOUNTS:
        qb.setTables(SipProfile.ACCOUNTS_TABLE_NAME);
        if (sortOrder == null) {
            finalSortOrder = SipProfile.FIELD_PRIORITY + " ASC";
        }
        break;
    case ACCOUNTS_ID:
        qb.setTables(SipProfile.ACCOUNTS_TABLE_NAME);
        qb.appendWhere(SipProfile.FIELD_ID + "=?");
        finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs,
                new String[] { uri.getLastPathSegment() });
        break;
    case CALLLOGS:
        qb.setTables(SipManager.CALLLOGS_TABLE_NAME);
        if (sortOrder == null) {
            finalSortOrder = CallLog.Calls.DATE + " DESC";
        }
        break;
    case CALLLOGS_ID:
        qb.setTables(SipManager.CALLLOGS_TABLE_NAME);
        qb.appendWhere(CallLog.Calls._ID + "=?");
        finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs,
                new String[] { uri.getLastPathSegment() });
        break;
    case FILTERS:
        qb.setTables(SipManager.FILTERS_TABLE_NAME);
        if (sortOrder == null) {
            finalSortOrder = Filter.DEFAULT_ORDER;
        }
        break;
    case FILTERS_ID:
        qb.setTables(SipManager.FILTERS_TABLE_NAME);
        qb.appendWhere(Filter._ID + "=?");
        finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs,
                new String[] { uri.getLastPathSegment() });
        break;
    case MESSAGES:
        qb.setTables(SipMessage.MESSAGES_TABLE_NAME);
        if (sortOrder == null) {
            finalSortOrder = SipMessage.FIELD_DATE + " DESC";
        }
        break;
    case MESSAGES_ID:
        qb.setTables(SipMessage.MESSAGES_TABLE_NAME);
        qb.appendWhere(SipMessage.FIELD_ID + "=?");
        finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs,
                new String[] { uri.getLastPathSegment() });
        break;
    case THREADS:
        qb.setTables(SipMessage.MESSAGES_TABLE_NAME);
        if (sortOrder == null) {
            finalSortOrder = SipMessage.FIELD_DATE + " DESC";
        }
        projection = new String[] { "ROWID AS _id", SipMessage.FIELD_FROM, SipMessage.FIELD_FROM_FULL,
                SipMessage.FIELD_TO,
                "CASE " + "WHEN " + SipMessage.FIELD_FROM + "='SELF' THEN " + SipMessage.FIELD_TO + " WHEN "
                        + SipMessage.FIELD_FROM + "!='SELF' THEN " + SipMessage.FIELD_FROM
                        + " END AS message_ordering",
                SipMessage.FIELD_BODY, "MAX(" + SipMessage.FIELD_DATE + ") AS " + SipMessage.FIELD_DATE,
                "MIN(" + SipMessage.FIELD_READ + ") AS " + SipMessage.FIELD_READ,
                //SipMessage.FIELD_READ,
                "COUNT(" + SipMessage.FIELD_DATE + ") AS counter" };
        //qb.appendWhere(SipMessage.FIELD_TYPE + " in (" + SipMessage.MESSAGE_TYPE_INBOX
        //        + "," + SipMessage.MESSAGE_TYPE_SENT + ")");
        finalGrouping = "message_ordering";
        regUri = SipMessage.MESSAGE_URI;
        break;
    case THREADS_ID:
        qb.setTables(SipMessage.MESSAGES_TABLE_NAME);
        if (sortOrder == null) {
            finalSortOrder = SipMessage.FIELD_DATE + " DESC";
        }
        projection = new String[] { "ROWID AS _id", SipMessage.FIELD_FROM, SipMessage.FIELD_TO,
                SipMessage.FIELD_BODY, SipMessage.FIELD_DATE, SipMessage.FIELD_MIME_TYPE, SipMessage.FIELD_TYPE,
                SipMessage.FIELD_STATUS, SipMessage.FIELD_FROM_FULL };
        qb.appendWhere(MESSAGES_THREAD_SELECTION);
        String from = uri.getLastPathSegment();
        finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs,
                new String[] { from, from });
        regUri = SipMessage.MESSAGE_URI;
        break;
    case ACCOUNTS_STATUS:
        synchronized (profilesStatus) {
            ContentValues[] cvs = new ContentValues[profilesStatus.size()];
            int i = 0;
            for (ContentValues ps : profilesStatus.values()) {
                cvs[i] = ps;
                i++;
            }
            c = getCursor(cvs);
        }
        if (c != null) {
            c.setNotificationUri(getContext().getContentResolver(), uri);
        }
        return c;
    case ACCOUNTS_STATUS_ID:
        id = ContentUris.parseId(uri);
        synchronized (profilesStatus) {
            ContentValues cv = profilesStatus.get(id);
            if (cv == null) {
                return null;
            }
            c = getCursor(new ContentValues[] { cv });
        }
        c.setNotificationUri(getContext().getContentResolver(), uri);
        return c;
    default:
        throw new IllegalArgumentException(UNKNOWN_URI_LOG + uri);
    }

    SQLiteDatabase db = mOpenHelper.getReadableDatabase();

    c = qb.query(db, projection, selection, finalSelectionArgs, finalGrouping, finalHaving, finalSortOrder);

    c.setNotificationUri(getContext().getContentResolver(), regUri);
    return c;
}