Java Code Examples for java.security.InvalidParameterException

The following examples show how to use java.security.InvalidParameterException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: openjdk-jdk9   Source File: SunProvider.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public Object newInstance(Object ctrParamObj)
    throws NoSuchAlgorithmException {
    String type = getType();
    if (ctrParamObj != null) {
        throw new InvalidParameterException
            ("constructorParameter not used with " + type +
             " engines");
    }
    String algo = getAlgorithm();
    try {
        if (type.equals("GssApiMechanism")) {
            if (algo.equals("1.2.840.113554.1.2.2")) {
                return new Krb5MechFactory();
            } else if (algo.equals("1.3.6.1.5.5.2")) {
                return new SpNegoMechFactory();
            }
        }
    } catch (Exception ex) {
        throw new NoSuchAlgorithmException
            ("Error constructing " + type + " for " +
            algo + " using SunJGSS", ex);
    }
    throw new ProviderException("No impl for " + algo +
        " " + type);
}
 
Example 2
/**
     * Initializes this parameter generator for a certain strength
     * and source of randomness.
     *
     * @param strength the strength (size of prime) in bits
     * @param random the source of randomness
     */
    protected void engineInit(int strength, SecureRandom random) {
        if ((strength >= 512) && (strength <= 1024) && (strength % 64 == 0)) {
            this.valueN = 160;
        } else if (strength == 2048) {
            this.valueN = 224;
//      } else if (strength == 3072) {
//          this.valueN = 256;
        } else {
            throw new InvalidParameterException
                ("Prime size should be 512 - 1024, or 2048");
        }
        this.valueL = strength;
        this.seedLen = valueN;
        this.random = random;
    }
 
Example 3
Source Project: RipplePower   Source File: KeyPairGeneratorSpi.java    License: Apache License 2.0 6 votes vote down vote up
public void initialize(
    int             strength,
    SecureRandom    random)
{
    this.strength = strength;
    this.random = random;

    ECGenParameterSpec ecParams = (ECGenParameterSpec)ecParameters.get(Integers.valueOf(strength));
    if (ecParams == null)
    {
        throw new InvalidParameterException("unknown key size.");
    }

    try
    {
        initialize(ecParams, random);
    }
    catch (InvalidAlgorithmParameterException e)
    {
        throw new InvalidParameterException("key size not configurable.");
    }
}
 
Example 4
Source Project: keystore-explorer   Source File: EccUtil.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Determines the name of the domain parameters that were used for generating the key.
 *
 * @param key An EC key
 * @return The name of the domain parameters that were used for the EC key,
 *         or an empty string if curve is unknown.
 */
public static String getNamedCurve(Key key) {

	if (!(key instanceof ECKey)) {
		throw new InvalidParameterException("Not a EC private key.");
	}

	ECKey ecKey = (ECKey) key;
	ECParameterSpec params = ecKey.getParams();
	if (!(params instanceof ECNamedCurveSpec)) {
		return "";
	}

	ECNamedCurveSpec ecPrivateKeySpec = (ECNamedCurveSpec) params;
	String namedCurve = ecPrivateKeySpec.getName();
	return namedCurve;
}
 
Example 5
Source Project: RipplePower   Source File: ECCKeyGenParameterSpec.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructor.
 *
 * @param m degree of the finite field GF(2^m)
 * @param t error correction capability of the code
 * @throws InvalidParameterException if <tt>m &lt; 1</tt> or <tt>m &gt; 32</tt> or
 * <tt>t &lt; 0</tt> or <tt>t &gt; n</tt>.
 */
public ECCKeyGenParameterSpec(int m, int t)
    throws InvalidParameterException
{
    if (m < 1)
    {
        throw new InvalidParameterException("m must be positive");
    }
    if (m > 32)
    {
        throw new InvalidParameterException("m is too large");
    }
    this.m = m;
    n = 1 << m;
    if (t < 0)
    {
        throw new InvalidParameterException("t must be positive");
    }
    if (t > n)
    {
        throw new InvalidParameterException("t must be less than n = 2^m");
    }
    this.t = t;
    fieldPoly = PolynomialRingGF2.getIrreduciblePolynomial(m);
}
 
Example 6
Source Project: simple-spring-memcached   Source File: DataIndexBuilder.java    License: MIT License 6 votes vote down vote up
@Override
protected void build(final AnnotationData data, final Annotation annotation, final Class<? extends Annotation> expectedAnnotationClass,
        final Method targetMethod) {
    if (isReturnDataUpdateContent(targetMethod)) {
        data.setReturnDataIndex(true);
        return;
    }

    final Integer foundIndex = getIndexOfAnnotatedParam(targetMethod, ParameterDataUpdateContent.class);
    if (foundIndex == null) {
        throw new InvalidParameterException(String.format(
                "No ReturnDataUpdateContent or ParameterDataUpdateContent annotation found on method [%s]", targetMethod.getName()));
    }

    data.setDataIndex(foundIndex);
}
 
Example 7
Source Project: chart-fx   Source File: GridPosition.java    License: Apache License 2.0 6 votes vote down vote up
public static HexagonMap.Direction getDirectionFromNumber(final int i) {
    switch (i) {
    case 0:
        return HexagonMap.Direction.NORTHWEST;
    case 1:
        return HexagonMap.Direction.NORTHEAST;
    case 2:
        return HexagonMap.Direction.EAST;
    case 3:
        return HexagonMap.Direction.SOUTHEAST;
    case 4:
        return HexagonMap.Direction.SOUTHWEST;
    case 5:
        return HexagonMap.Direction.WEST;
    default:
    }
    throw new InvalidParameterException("unknown direction: " + i);
}
 
Example 8
/**
    * See {@link IEventNotificationService#unsubscribe(String, String, Long, Long)
    */
   protected void unsubscribe(Event event, Integer userId) throws InvalidParameterException {
if (userId == null) {
    throw new InvalidParameterException("User ID can not be null.");
}
Iterator<Subscription> subscriptionIterator = event.getSubscriptions().iterator();
while (subscriptionIterator.hasNext()) {
    Subscription subscription = subscriptionIterator.next();
    if (subscription.getUserId().equals(userId)) {
	subscriptionIterator.remove();
    }
}
if (event.getSubscriptions().isEmpty()) {
    eventDAO.delete(event);
} else {
    eventDAO.insertOrUpdate(event);
}
   }
 
Example 9
Source Project: UltimateAndroid   Source File: PullRefreshLayout.java    License: Apache License 2.0 6 votes vote down vote up
public void setRefreshStyle(int type){
    setRefreshing(false);
    switch (type){
        case STYLE_CIRCLES:
            mRefreshDrawable = new CirclesDrawable(getContext(), this);
            break;
        case STYLE_WATER_DROP:
            mRefreshDrawable = new WaterDropDrawable(getContext(), this);
            break;
        case STYLE_RING:
            mRefreshDrawable = new RingDrawable(getContext(), this);
            break;
        default:
            throw new InvalidParameterException("Type does not exist");
    }
    mRefreshDrawable.setColorSchemeColors(mColorSchemeColors);
    mRefreshView.setImageDrawable(mRefreshDrawable);
}
 
Example 10
public void setX(float x) {
    if (x < 0.0f || x > 100.0f) {
        throw new InvalidParameterException("X value must be defined in percentage between 0 and 100");
    }

    this.x = x;
}
 
Example 11
Source Project: chart-fx   Source File: Function1D.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param xmin min. x range
 * @param xmax max x range
 * @param nsamples number of sample points
 * @return DataSet representation of the function
 */
default DataSet getDataSetEstimate(final double xmin, final double xmax, final int nsamples) {
    if (xmin > xmax || nsamples <= 0) {
        throw new InvalidParameterException("AbstractFunciton1D::getDataSetEstimate(" + xmin + "," + xmax + ","
                + nsamples + ") - " + "invalid range");
    }
    final double[] xValues = new double[nsamples];
    final double step = (xmax - xmin) / nsamples;
    for (int i = 0; i < nsamples; i++) {
        xValues[i] = xmin + i * step;
    }
    return getDataSetEstimate(xValues);
}
 
Example 12
Source Project: DDMQ   Source File: ZkServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean createOrUpdateCProxy(CProxyConfig config) throws Exception {
    if (!config.validate()) {
        LOGGER.error("invalid cproxy config, config={}", config);
        throw new InvalidParameterException("invalid cproxy config");
    }
    setZkData(getProxyPath(CARRERA_CPROXY, config.getInstance()), config);
    return true;
}
 
Example 13
public KafkaClientPropertiesBuilder withSaslJassConfig(String clientId, String clientSecretName, String oauthTokenEndpointUri) {
    if (clientId.isEmpty() || clientSecretName.isEmpty() || oauthTokenEndpointUri.isEmpty()) {
        throw new InvalidParameterException("You do not specify client-id, client-secret name or oauth-token-endpoint-uri inside kafka client!");
    }

    this.properties.setProperty(SaslConfigs.SASL_JAAS_CONFIG,
        "org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule " +
            "required " +
            "oauth.client.id=\"" + clientId + "\" " +
            "oauth.client.secret=\"" + clientSecretName + "\" " +
            "oauth.token.endpoint.uri=\"" + oauthTokenEndpointUri + "\";");

    return this;
}
 
Example 14
Source Project: IoTgo_Android_App   Source File: CertificateValidator.java    License: MIT License 5 votes vote down vote up
/**
 * validates a specific certificate inside of the keystore being passed in
 * 
 * @param keyStore
 * @param cert
 * @throws CertificateException
 */
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);
    } 
}
 
Example 15
Source Project: brooklyn-library   Source File: KafkaSupport.java    License: Apache License 2.0 5 votes vote down vote up
/**
     * Retrieve the next message on the given topic from the {@link KafkaCluster}.
     */
    public String getMessage(String topic) {
        ZooKeeperNode zookeeper = cluster.getZooKeeper();
        Optional<Entity> anyBrokerNodeInCluster = Iterables.tryFind(cluster.getCluster().getChildren(), Predicates.and(
                Predicates.instanceOf(KafkaBroker.class),
                EntityPredicates.attributeEqualTo(KafkaBroker.SERVICE_UP, true)));
        if (anyBrokerNodeInCluster.isPresent()) {
            KafkaBroker broker = (KafkaBroker)anyBrokerNodeInCluster.get();

            Properties props = new Properties();

            props.put("bootstrap.servers", format("%s:%d", broker.getAttribute(KafkaBroker.HOSTNAME), broker.getKafkaPort()));
            props.put("zookeeper.connect", format(zookeeper.getHostname(), zookeeper.getZookeeperPort()));
            props.put("group.id", "brooklyn");
            props.put("partition.assignment.strategy", "RoundRobin");
            props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
            props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");

            KafkaConsumer consumer = new KafkaConsumer(props);

            consumer.subscribe(topic);
            // FIXME unimplemented KafkaConsumer.poll
//            Object consumerRecords = consumer.poll(Duration.seconds(3).toMilliseconds()).get(topic);
            return "TEST_MESSAGE";
        } else {
            throw new InvalidParameterException("No kafka broker node found");
        }
    }
 
Example 16
Source Project: ServiceCutter   Source File: SolverConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
public void setAlgorithmParams(final Map<String, Double> mclParams) {
	if (mclParams != null) {
		this.algorithmParams = mclParams;
	} else {
		throw new InvalidParameterException("mclParams should not be null!");
	}
}
 
Example 17
Source Project: jdk8u60   Source File: AESKeyGenerator.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initializes this key generator for a certain keysize, using the given
 * source of randomness.
 *
 * @param keysize the keysize. This is an algorithm-specific
 * metric specified in number of bits.
 * @param random the source of randomness for this key generator
 */
protected void engineInit(int keysize, SecureRandom random) {
    if (((keysize % 8) != 0) ||
        (!AESCrypt.isKeySizeValid(keysize/8))) {
        throw new InvalidParameterException
            ("Wrong keysize: must be equal to 128, 192 or 256");
    }
    this.keySize = keysize/8;
    this.engineInit(random);
}
 
Example 18
@Override
public void validate(List<ValidationType> validationsToSkip) {
    if ((!validationsToSkip.contains(ValidationType.SKIP_ASSET_VALIDATION)
            && !validationsToSkip.contains(ValidationType.SKIP_VALIDATION))
            && (!SteemJConfig.getInstance().getVestsSymbol().equals(this.getVestingShares().getSymbol()))) {
        throw new InvalidParameterException("The vesting shares needs to be provided in VESTS.");
    }
}
 
Example 19
Source Project: cloudbreak   Source File: ClusterTemplateTestAssertion.java    License: Apache License 2.0 5 votes vote down vote up
private static InstanceGroupV1Request getInstanceGroup(List<InstanceGroupV1Request> instanceGroups) {
    return instanceGroups
            .stream()
            .filter(ig -> HostGroupType.MASTER.getName().equals(ig.getName()))
            .findFirst()
            .orElseThrow(() -> new InvalidParameterException("Unable to find valid instancegroup by type"));
}
 
Example 20
public void setStrategy(AssertionFactory.Strategy strategy) {

    if (strategy == null) {
      throw new InvalidParameterException("'strategy' cannot be null.");
    }
    
    if (strategyReference.getAndSet(strategy) != strategy) {
      currentFactory = createFactory(strategy, exceptionMapperReference.get());
    }
  }
 
Example 21
Source Project: ripple-lib-java   Source File: ECCKeyGenParameterSpec.java    License: ISC License 5 votes vote down vote up
/**
 * Constructor.
 *
 * @param m    degree of the finite field GF(2^m)
 * @param t    error correction capability of the code
 * @param poly the field polynomial
 * @throws InvalidParameterException if <tt>m &lt; 1</tt> or <tt>m &gt; 32</tt> or
 * <tt>t &lt; 0</tt> or <tt>t &gt; n</tt> or
 * <tt>poly</tt> is not an irreducible field polynomial.
 */
public ECCKeyGenParameterSpec(int m, int t, int poly)
    throws InvalidParameterException
{
    this.m = m;
    if (m < 1)
    {
        throw new InvalidParameterException("m must be positive");
    }
    if (m > 32)
    {
        throw new InvalidParameterException(" m is too large");
    }
    this.n = 1 << m;
    this.t = t;
    if (t < 0)
    {
        throw new InvalidParameterException("t must be positive");
    }
    if (t > n)
    {
        throw new InvalidParameterException("t must be less than n = 2^m");
    }
    if ((PolynomialRingGF2.degree(poly) == m)
        && (PolynomialRingGF2.isIrreducible(poly)))
    {
        this.fieldPoly = poly;
    }
    else
    {
        throw new InvalidParameterException(
            "polynomial is not a field polynomial for GF(2^m)");
    }
}
 
Example 22
private static String getErrorMessage(TYPE type){
	switch(type){
		case BAD_FILE: 					return "Bad file format!";							
		case ERROR_FILE_OPEN:			return "Error while opening the file:";
		case ERROR_FILE_SAVE:			return "Error while saving the image!";
		case ERROR_FILE_CHOOSE:			return "Error while choosing the file!";
		case ERROR_FILE_NOT_FOUND: 		return "Error! File not found:"; 
		case NO_IMAGE_LOADED:			return "No image loaded!";			
		case IMAGE_RELOAD:				return "Error while reloading the image!";
		case ERROR_PLUGIN_NOT_FOUND:	return "Error: plug-in not found!";
		default: throw new InvalidParameterException("Unknown error type");
	}
}
 
Example 23
Source Project: TelegramBots   Source File: DefaultBotSession.java    License: MIT License 5 votes vote down vote up
@Override
public void setToken(String token) {
    if (this.token != null) {
        throw new InvalidParameterException("Token has already been set");
    }
    this.token = token;
}
 
Example 24
Source Project: lams   Source File: DeliveryMethodMail.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
   protected String send(Integer fromUserId, Integer toUserId, String subject, String message, boolean isHtmlFormat,
    String attachmentFilename) throws InvalidParameterException {
try {
    User toUser = (User) DeliveryMethodMail.userManagementService.findById(User.class, toUserId);
    if (toUser == null) {
	return "Target user with ID " + toUserId + " was not found.";
    }
    String toEmail = toUser.getEmail();
    if (!DeliveryMethodMail.emailValidator.isValid(toEmail)) {
	return "Target user's e-mail address is invalid.";
    }

    if (fromUserId == null) {
	Emailer.sendFromSupportEmail(subject, toEmail, message, isHtmlFormat, attachmentFilename);
    } else {
	User fromUser = (User) DeliveryMethodMail.userManagementService.findById(User.class, fromUserId);
	if (fromUser == null) {
	    return "Source user with ID " + fromUserId + " was not found.";
	}
	String fromEmail = fromUser.getEmail();
	if (!DeliveryMethodMail.emailValidator.isValid(fromEmail)) {
	    return "Source user's e-mail address is invalid.";
	}

	Emailer.send(subject, toEmail, "", fromEmail, "", message, isHtmlFormat, attachmentFilename);
    }
    return null;
} catch (Exception e) {
    String error = e.toString();
    logError(error);
    return error;
}
   }
 
Example 25
@Test
public void testConstructor() {
    try {
        new PostToProfileCommand("");
    } catch (InvalidParameterException ipe) {
        fail("empty String as a parameter should be accepted.");
    }
}
 
Example 26
/**
 * Creates a new {@link PdfPageTransition} instance.
 * 
 * @param style
 * @param transitionDuration
 * @param displayDuration
 * @return the newly created instance.
 * @throws InvalidParameterException
 *             if the input transition or display duration is not positive. if the input style is null.
 */
public static PdfPageTransition newInstance(PdfPageTransitionStyle style, int transitionDuration,
        int displayDuration) {

    if (transitionDuration < 1) {
        throw new InvalidParameterException("Input transition duration must be positive.");
    }
    if (displayDuration < 1) {
        throw new InvalidParameterException("Input display duration must be positive.");
    }
    if (style == null) {
        throw new InvalidParameterException("Input style cannot be null.");
    }
    return new PdfPageTransition(style, transitionDuration, displayDuration);
}
 
Example 27
Source Project: fusionauth-jwt   Source File: PEMEncoder.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Encode the provided key in a PEM format and return a string.
 * <p>
 * Both values may no be null.
 *
 * @param key the key, this parameter may be of type <code>PrivateKey</code> <code>PublicKey</code>
 * @return a PEM encoded key
 */
public String encode(Key key) {
  if (key instanceof PrivateKey) {
    return encode((PrivateKey) key, null);
  } else if (key instanceof PublicKey) {
    return encode(null, (PublicKey) key);
  }

  throw new PEMEncoderException(new InvalidParameterException("Unexpected key type. Expecting instance of [PrivateKey | PublicKey], found [" + key.getClass().getCanonicalName() + "]"));
}
 
Example 28
Source Project: jdk8u_jdk   Source File: AESKeyGenerator.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initializes this key generator for a certain keysize, using the given
 * source of randomness.
 *
 * @param keysize the keysize. This is an algorithm-specific
 * metric specified in number of bits.
 * @param random the source of randomness for this key generator
 */
protected void engineInit(int keysize, SecureRandom random) {
    if (((keysize % 8) != 0) ||
        (!AESCrypt.isKeySizeValid(keysize/8))) {
        throw new InvalidParameterException
            ("Wrong keysize: must be equal to 128, 192 or 256");
    }
    this.keySize = keysize/8;
    this.engineInit(random);
}
 
Example 29
/**
 * Initializes this key generator for a certain keysize, using the given
 * source of randomness.
 *
 * @param keysize the keysize. This is an algorithm-specific
 * metric specified in number of bits.
 * @param random the source of randomness for this key generator
 */
protected void engineInit(int keysize, SecureRandom random) {
    if (((keysize % 8) != 0) ||
        (!AESCrypt.isKeySizeValid(keysize/8))) {
        throw new InvalidParameterException
            ("Wrong keysize: must be equal to 128, 192 or 256");
    }
    this.keySize = keysize/8;
    this.engineInit(random);
}
 
Example 30
Source Project: components   Source File: DefaultSQLCreateTableAction.java    License: Apache License 2.0 5 votes vote down vote up
public DefaultSQLCreateTableAction(final String[] fullTableName, final Schema schema, boolean createIfNotExists, boolean drop,
    boolean dropIfExists) {
    if (fullTableName == null || fullTableName.length < 1) {
        throw new InvalidParameterException("Table name can't be null or empty");
    }

    this.fullTableName = fullTableName;
    this.schema = schema;
    this.createIfNotExists = createIfNotExists;

    this.drop = drop || dropIfExists;
    this.dropIfExists = dropIfExists;
}