use of java.security.InvalidParameterException in project jetty.project by eclipse.
the class CertificateValidator method validate.
/**
* validates a specific certificate inside of the keystore being passed in
*
* @param keyStore the keystore to validate against
* @param cert the certificate to validate
* @throws CertificateException if keystore error and unable to validate
*/
public void validate(KeyStore keyStore, Certificate cert) throws CertificateException {
Certificate[] certChain = null;
if (cert != null && cert instanceof X509Certificate) {
((X509Certificate) cert).checkValidity();
String certAlias = null;
try {
if (keyStore == null) {
throw new InvalidParameterException("Keystore cannot be null");
}
certAlias = keyStore.getCertificateAlias((X509Certificate) cert);
if (certAlias == null) {
certAlias = "JETTY" + String.format("%016X", __aliasCount.incrementAndGet());
keyStore.setCertificateEntry(certAlias, cert);
}
certChain = keyStore.getCertificateChain(certAlias);
if (certChain == null || certChain.length == 0) {
throw new IllegalStateException("Unable to retrieve certificate chain");
}
} catch (KeyStoreException kse) {
LOG.debug(kse);
throw new CertificateException("Unable to validate certificate" + (certAlias == null ? "" : " for alias [" + certAlias + "]") + ": " + kse.getMessage(), kse);
}
validate(certChain);
}
}
use of java.security.InvalidParameterException in project JessMA by ldcsaa.
the class FileUploader method parseFileItems.
private Result parseFileItems(List<FileItem> items, FileNameGenerator fnGenerator, String absolutePath, String encoding, List<FileItemInfo> fiis) {
for (FileItem item : items) {
if (item.isFormField())
parseFormField(item, encoding);
else {
if (GeneralHelper.isStrEmpty(item.getName()))
continue;
Result result = parseFileField(item, absolutePath, fnGenerator, fiis);
if (result != Result.SUCCESS) {
reset();
cause = new InvalidParameterException(String.format("file '%s' not accepted", item.getName()));
return result;
}
}
}
return Result.SUCCESS;
}
use of java.security.InvalidParameterException in project android_frameworks_base by ParanoidAndroid.
the class ContentService method notifyChange.
/**
* Notify observers of a particular user's view of the provider.
* @param userHandle the user whose view of the provider is to be notified. May be
* the calling user without requiring any permission, otherwise the caller needs to
* hold the INTERACT_ACROSS_USERS_FULL permission. Pseudousers USER_ALL and
* USER_CURRENT are properly interpreted; no other pseudousers are allowed.
*/
@Override
public void notifyChange(Uri uri, IContentObserver observer, boolean observerWantsSelfNotifications, boolean syncToNetwork, int userHandle) {
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "Notifying update of " + uri + " for user " + userHandle + " from observer " + observer + ", syncToNetwork " + syncToNetwork);
}
// Notify for any user other than the caller's own requires permission.
final int callingUserHandle = UserHandle.getCallingUserId();
if (userHandle != callingUserHandle) {
mContext.enforceCallingOrSelfPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL, "no permission to notify other users");
}
// We passed the permission check; resolve pseudouser targets as appropriate
if (userHandle < 0) {
if (userHandle == UserHandle.USER_CURRENT) {
userHandle = ActivityManager.getCurrentUser();
} else if (userHandle != UserHandle.USER_ALL) {
throw new InvalidParameterException("Bad user handle for notifyChange: " + userHandle);
}
}
final int uid = Binder.getCallingUid();
// This makes it so that future permission checks will be in the context of this
// process rather than the caller's process. We will restore this before returning.
long identityToken = clearCallingIdentity();
try {
ArrayList<ObserverCall> calls = new ArrayList<ObserverCall>();
synchronized (mRootNode) {
mRootNode.collectObserversLocked(uri, 0, observer, observerWantsSelfNotifications, userHandle, calls);
}
final int numCalls = calls.size();
for (int i = 0; i < numCalls; i++) {
ObserverCall oc = calls.get(i);
try {
oc.mObserver.onChange(oc.mSelfChange, uri);
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "Notified " + oc.mObserver + " of " + "update at " + uri);
}
} catch (RemoteException ex) {
synchronized (mRootNode) {
Log.w(TAG, "Found dead observer, removing");
IBinder binder = oc.mObserver.asBinder();
final ArrayList<ObserverNode.ObserverEntry> list = oc.mNode.mObservers;
int numList = list.size();
for (int j = 0; j < numList; j++) {
ObserverNode.ObserverEntry oe = list.get(j);
if (oe.observer.asBinder() == binder) {
list.remove(j);
j--;
numList--;
}
}
}
}
}
if (syncToNetwork) {
SyncManager syncManager = getSyncManager();
if (syncManager != null) {
syncManager.scheduleLocalSync(null, /* all accounts */
callingUserHandle, uid, uri.getAuthority());
}
}
} finally {
restoreCallingIdentity(identityToken);
}
}
use of java.security.InvalidParameterException in project XobotOS by xamarin.
the class JCEKeyGenerator method engineInit.
protected void engineInit(int keySize, SecureRandom random) {
try {
// BEGIN android-added
if (random == null) {
random = new SecureRandom();
}
// END android-added
engine.init(new KeyGenerationParameters(random, keySize));
uninitialised = false;
} catch (IllegalArgumentException e) {
throw new InvalidParameterException(e.getMessage());
}
}
use of java.security.InvalidParameterException in project azure-iot-sdk-java by Azure.
the class Mqtt method publish.
/**
* Method to publish to mqtt broker connection.
*
* @param publishTopic the topic to publish on mqtt broker connection.
* @param payload the payload to publish on publishTopic of mqtt broker connection.
* @throws IOException if failed to publish the mqtt topic.
*/
protected void publish(String publishTopic, byte[] payload) throws IOException {
synchronized (Mqtt.MQTT_LOCK) {
try {
if (Mqtt.info == null) {
System.out.println("Mqtt client should be initialised atleast once before using it");
throw new InvalidParameterException();
}
if (!Mqtt.info.mqttAsyncClient.isConnected()) {
/*
** Codes_SRS_Mqtt_25_012: [**If the MQTT connection is closed, the function shall throw an IOException.**]**
*/
throw new IOException("Cannot publish when mqtt client is disconnected");
}
if (publishTopic == null || publishTopic.length() == 0 || payload == null) {
/*
**Codes_SRS_Mqtt_25_013: [**If the either publishTopic is null or empty or if payload is null, the function shall throw an IOException.**]**
*/
throw new IOException("Cannot publish on null or empty publish topic");
}
while (Mqtt.info.mqttAsyncClient.getPendingDeliveryTokens().length >= MqttConnectionInfo.MAX_IN_FLIGHT_COUNT) {
/*
**Codes_SRS_Mqtt_25_048: [**publish shall check for pending publish tokens by calling getPendingDeliveryTokens.
* And if there are pending tokens publish shall sleep until the number of pending tokens are less than 10 as per paho limitations**]**
*/
Thread.sleep(10);
}
MqttMessage mqttMessage = (payload.length == 0) ? new MqttMessage() : new MqttMessage(payload);
mqttMessage.setQos(MqttConnectionInfo.QOS);
/*
**Codes_SRS_Mqtt_25_014: [**The function shall publish message payload on the publishTopic specified to the IoT Hub given in the configuration.**]**
*/
IMqttDeliveryToken publishToken = Mqtt.info.mqttAsyncClient.publish(publishTopic, mqttMessage);
} catch (MqttException e) {
/*
**Codes_SRS_Mqtt_25_047: [**If the Mqtt Client Async throws MqttException, the function shall throw an IOException with the message.**]**
*/
throw new IOException("Unable to publish message on topic : " + publishTopic + " because " + e.getCause() + e.getMessage());
} catch (InterruptedException e) {
throw new IOException("Interrupted, Unable to publish message on topic : " + publishTopic);
} catch (Exception e) {
throw new IOException("Unable to publish message on topic : " + publishTopic + " " + e.getCause() + e.getMessage());
}
}
}
Aggregations