Example usage for java.security Provider getName

List of usage examples for java.security Provider getName

Introduction

In this page you can find the example usage for java.security Provider getName.

Prototype

public String getName() 

Source Link

Document

Returns the name of this provider.

Usage

From source file:com.cloud.network.NetworkModelImpl.java

@Override
public boolean canElementEnableIndividualServices(Provider provider) {
    NetworkElement element = getElementImplementingProvider(provider.getName());
    if (element == null) {
        throw new InvalidParameterValueException(
                "Unable to find the Network Element implementing the Service Provider '" + provider.getName()
                        + "'");
    }/*from  w ww .  jav a 2s .  c om*/
    return element.canEnableIndividualServices();
}

From source file:com.cloud.network.NetworkModelImpl.java

@Override
public void checkCapabilityForProvider(Set<Provider> providers, Service service, Capability cap,
        String capValue) {//from   ww  w .j a v a2s .c  o  m
    for (Provider provider : providers) {
        NetworkElement element = getElementImplementingProvider(provider.getName());
        if (element != null) {
            Map<Service, Map<Capability, String>> elementCapabilities = element.getCapabilities();
            if (elementCapabilities == null || !elementCapabilities.containsKey(service)) {
                throw new UnsupportedServiceException(
                        "Service " + service.getName() + " is not supported by the element=" + element.getName()
                                + " implementing Provider=" + provider.getName());
            }
            Map<Capability, String> serviceCapabilities = elementCapabilities.get(service);
            if (serviceCapabilities == null || serviceCapabilities.isEmpty()) {
                throw new UnsupportedServiceException(
                        "Service " + service.getName() + " doesn't have capabilites for element="
                                + element.getName() + " implementing Provider=" + provider.getName());
            }

            String value = serviceCapabilities.get(cap);
            if (value == null || value.isEmpty()) {
                throw new UnsupportedServiceException("Service " + service.getName()
                        + " doesn't have capability " + cap.getName() + " for element=" + element.getName()
                        + " implementing Provider=" + provider.getName());
            }

            if (!value.toLowerCase().contains(capValue.toLowerCase())) {
                throw new UnsupportedServiceException("Service " + service.getName() + " doesn't support value "
                        + capValue + " for capability " + cap.getName() + " for element=" + element.getName()
                        + " implementing Provider=" + provider.getName());
            }
        } else {
            throw new UnsupportedServiceException(
                    "Unable to find network element for provider " + provider.getName());
        }
    }
}

From source file:com.cloud.network.NetworkModelImpl.java

@Override
public Map<Provider, ArrayList<PublicIpAddress>> getProviderToIpList(Network network,
        Map<PublicIpAddress, Set<Service>> ipToServices) {
    NetworkOffering offering = _networkOfferingDao.findById(network.getNetworkOfferingId());
    if (!offering.isConserveMode()) {
        for (PublicIpAddress ip : ipToServices.keySet()) {
            Set<Service> services = new HashSet<Service>();
            services.addAll(ipToServices.get(ip));
            if (services != null && services.contains(Service.Firewall)) {
                services.remove(Service.Firewall);
            }/*from   ww w  .  j  av a 2 s  . co  m*/
            if (services != null && services.size() > 1) {
                throw new CloudRuntimeException("Ip " + ip.getAddress() + " is used by multiple services!");
            }
        }
    }
    Map<Service, Set<PublicIpAddress>> serviceToIps = new HashMap<Service, Set<PublicIpAddress>>();
    for (PublicIpAddress ip : ipToServices.keySet()) {
        for (Service service : ipToServices.get(ip)) {
            Set<PublicIpAddress> ips = serviceToIps.get(service);
            if (ips == null) {
                ips = new HashSet<PublicIpAddress>();
            }
            ips.add(ip);
            serviceToIps.put(service, ips);
        }
    }
    // TODO Check different provider for same IP
    Map<Provider, Set<Service>> providerToServices = getProviderServicesMap(network.getId());
    Map<Provider, ArrayList<PublicIpAddress>> providerToIpList = new HashMap<Provider, ArrayList<PublicIpAddress>>();
    for (Provider provider : providerToServices.keySet()) {
        if (!(getElementImplementingProvider(provider.getName()) instanceof IpDeployingRequester)) {
            continue;
        }
        Set<Service> services = providerToServices.get(provider);
        ArrayList<PublicIpAddress> ipList = new ArrayList<PublicIpAddress>();
        Set<PublicIpAddress> ipSet = new HashSet<PublicIpAddress>();
        for (Service service : services) {
            Set<PublicIpAddress> serviceIps = serviceToIps.get(service);
            if (serviceIps == null || serviceIps.isEmpty()) {
                continue;
            }
            ipSet.addAll(serviceIps);
        }
        Set<PublicIpAddress> sourceNatIps = serviceToIps.get(Service.SourceNat);
        if (sourceNatIps != null && !sourceNatIps.isEmpty()) {
            ipList.addAll(0, sourceNatIps);
            ipSet.removeAll(sourceNatIps);
        }
        ipList.addAll(ipSet);
        providerToIpList.put(provider, ipList);
    }
    return providerToIpList;
}

From source file:com.cloud.network.NetworkModelImpl.java

@Override
public boolean start() {
    // populate s_serviceToImplementedProvidersMap & s_providerToNetworkElementMap with current _networkElements
    // Need to do this in start() since _networkElements are not completely configured until then.
    for (NetworkElement element : networkElements) {
        Map<Service, Map<Capability, String>> capabilities = element.getCapabilities();
        Provider implementedProvider = element.getProvider();
        if (implementedProvider != null) {
            if (s_providerToNetworkElementMap.containsKey(implementedProvider.getName())) {
                s_logger.error(/*from  w w  w . j a  v a 2  s  .c o  m*/
                        "Cannot start NetworkModel: Provider <-> NetworkElement must be a one-to-one map, "
                                + "multiple NetworkElements found for Provider: "
                                + implementedProvider.getName());
                continue;
            }
            s_logger.info("Add provider <-> element map entry. " + implementedProvider.getName() + "-"
                    + element.getName() + "-" + element.getClass().getSimpleName());
            s_providerToNetworkElementMap.put(implementedProvider.getName(), element.getName());
        }
        if (capabilities != null && implementedProvider != null) {
            for (Service service : capabilities.keySet()) {
                if (s_serviceToImplementedProvidersMap.containsKey(service)) {
                    List<Provider> providers = s_serviceToImplementedProvidersMap.get(service);
                    providers.add(implementedProvider);
                } else {
                    List<Provider> providers = new ArrayList<Provider>();
                    providers.add(implementedProvider);
                    s_serviceToImplementedProvidersMap.put(service, providers);
                }
            }
        }
    }
    s_logger.info("Started Network Model");
    return true;
}

From source file:com.cloud.network.NetworkModelImpl.java

public boolean canIpUsedForService(PublicIp publicIp, Service service, Long networkId) {
    List<PublicIpAddress> ipList = new ArrayList<PublicIpAddress>();
    ipList.add(publicIp);/*  w  ww .  j  ava  2s  .  c o m*/
    Map<PublicIpAddress, Set<Service>> ipToServices = getIpToServices(ipList, false, true);
    Set<Service> services = ipToServices.get(publicIp);
    if (services == null || services.isEmpty()) {
        return true;
    }

    if (networkId == null) {
        networkId = publicIp.getAssociatedWithNetworkId();
    }

    // We only support one provider for one service now
    Map<Service, Set<Provider>> serviceToProviders = getServiceProvidersMap(networkId);
    // Since IP already has service to bind with, the oldProvider can't be null
    Set<Provider> newProviders = serviceToProviders.get(service);
    if (newProviders == null || newProviders.isEmpty()) {
        throw new InvalidParameterException("There is no new provider for IP " + publicIp.getAddress()
                + " of service " + service.getName() + "!");
    }
    Provider newProvider = (Provider) newProviders.toArray()[0];
    Set<Provider> oldProviders = serviceToProviders.get(services.toArray()[0]);
    Provider oldProvider = (Provider) oldProviders.toArray()[0];
    Network network = _networksDao.findById(networkId);
    NetworkElement oldElement = getElementImplementingProvider(oldProvider.getName());
    NetworkElement newElement = getElementImplementingProvider(newProvider.getName());
    if (oldElement instanceof IpDeployingRequester && newElement instanceof IpDeployingRequester) {
        IpDeployer oldIpDeployer = ((IpDeployingRequester) oldElement).getIpDeployer(network);
        IpDeployer newIpDeployer = ((IpDeployingRequester) newElement).getIpDeployer(network);
        // FIXME: I ignored this check
    } else {
        throw new InvalidParameterException("Ip cannot be applied for new provider!");
    }
    return true;
}

From source file:com.cloud.network.NetworkModelImpl.java

@Override
public void canProviderSupportServices(Map<Provider, Set<Service>> providersMap) {
    for (Provider provider : providersMap.keySet()) {
        // check if services can be turned off
        NetworkElement element = getElementImplementingProvider(provider.getName());
        if (element == null) {
            throw new InvalidParameterValueException(
                    "Unable to find the Network Element implementing the Service Provider '"
                            + provider.getName() + "'");
        }/*  ww w .  ja v a  2 s .co m*/

        Set<Service> enabledServices = new HashSet<Service>();
        enabledServices.addAll(providersMap.get(provider));

        if (enabledServices != null && !enabledServices.isEmpty()) {
            if (!element.canEnableIndividualServices()) {
                Set<Service> requiredServices = new HashSet<Service>();
                requiredServices.addAll(element.getCapabilities().keySet());

                if (requiredServices.contains(Network.Service.Gateway)) {
                    requiredServices.remove(Network.Service.Gateway);
                }

                if (requiredServices.contains(Network.Service.Firewall)) {
                    requiredServices.remove(Network.Service.Firewall);
                }

                if (enabledServices.contains(Network.Service.Firewall)) {
                    enabledServices.remove(Network.Service.Firewall);
                }

                // exclude gateway service
                if (enabledServices.size() != requiredServices.size()) {
                    StringBuilder servicesSet = new StringBuilder();

                    for (Service requiredService : requiredServices) {
                        // skip gateway service as we don't allow setting it via API
                        if (requiredService == Service.Gateway) {
                            continue;
                        }
                        servicesSet.append(requiredService.getName() + ", ");
                    }
                    servicesSet.delete(servicesSet.toString().length() - 2, servicesSet.toString().length());

                    throw new InvalidParameterValueException(
                            "Cannot enable subset of Services, Please specify the complete list of Services: "
                                    + servicesSet.toString() + "  for Service Provider " + provider.getName());
                }
            }
            List<String> serviceList = new ArrayList<String>();
            for (Service service : enabledServices) {
                // check if the service is provided by this Provider
                if (!element.getCapabilities().containsKey(service)) {
                    throw new UnsupportedServiceException(
                            provider.getName() + " Provider cannot provide service " + service.getName());
                }
                serviceList.add(service.getName());
            }
            if (!element.verifyServicesCombination(enabledServices)) {
                throw new UnsupportedServiceException("Provider " + provider.getName()
                        + " doesn't support services combination: " + serviceList);
            }
        }
    }
}

From source file:org.cesecore.certificates.util.AlgorithmTools.java

/** Check if the curve name is known by the first found PKCS#11 provider or default (if none was found)*/
public static boolean isNamedECKnownInDefaultProvider(String ecNamedCurveBc) {
    final Provider[] providers = Security.getProviders("KeyPairGenerator.EC");
    String providerName = providers[0].getName();
    try {//w  ww.  ja v  a  2 s  .com
        for (Provider ecProvider : providers) {
            //This will list something like: SunPKCS11-NSS, BC, SunPKCS11-<library>-slot<slotnumber>
            if (log.isDebugEnabled()) {
                log.debug("Found EC capable provider named: " + ecProvider.getName());
            }
            if (ecProvider.getName().startsWith("SunPKCS11-")
                    && !ecProvider.getName().startsWith("SunPKCS11-NSS")) {
                providerName = ecProvider.getName();
                break;
            }
        }
        final KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", providerName);
        kpg.initialize(new ECGenParameterSpec(ecNamedCurveBc));
        return true;
    } catch (InvalidAlgorithmParameterException e) {
        if (log.isDebugEnabled()) {
            log.debug(ecNamedCurveBc + " is not available in provider " + providerName);
        }
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(
                "EC capable provider " + providerName + " could no longer handle elliptic curve algorithm..",
                e);
    } catch (NoSuchProviderException e) {
        throw new RuntimeException("EC capable provider " + providerName + " disappeard unexpectedly.", e);
    }
    return false;
}

From source file:org.cesecore.keys.token.BaseCryptoToken.java

/**
 * Sets both signature and encryption providers. If encryption provider is the same as signature provider this class name can be null.
 *
 * @param jcaProviderClassName signature provider class name
 * @param jceProviderClassName encryption provider class name, can be null
 * @throws ClassNotFoundException if the class specified by jcaProviderClassName could not be found.
 * @throws IllegalAccessException if the default constructor for the class specified by jcaProviderClassName was not public
 * @throws InstantiationException if the class specified by jcaProviderClassName was an abstract class, an interface, an array class, a primitive
 *             type, or void; or if it has no nullary constructor; or if the instantiation fails for some other reason.
 * @see {@link #setJCAProvider(Provider)}
 *//* w w  w .  j a va 2  s .  c  om*/
protected void setProviders(String jcaProviderClassName, String jceProviderClassName)
        throws InstantiationException, IllegalAccessException, ClassNotFoundException {
    Provider jcaProvider = (Provider) Class.forName(jcaProviderClassName).newInstance();
    setProvider(jcaProvider);
    this.mJcaProviderName = jcaProvider.getName();
    if (jceProviderClassName != null) {
        try {
            Provider jceProvider = (Provider) Class.forName(jceProviderClassName).newInstance();
            setProvider(jceProvider);
            this.mJceProviderName = jceProvider.getName();
        } catch (Exception e) {
            log.error(intres.getLocalizedMessage("token.jceinitfail"), e);
        }
    } else {
        this.mJceProviderName = null;
    }
}

From source file:org.cesecore.keys.token.BaseCryptoToken.java

/**
 * If we only have one provider to handle both JCA and JCE, and perhaps it is not so straightforward to create the provider (for example PKCS#11
 * provider), we can create the provider in sub class and set it here, instead of calling setProviders.
 *
 * @param prov the fully constructed Provider
 * @see #setProviders(String, String)//from  w w w  . j  av a 2s . c  om
 */
protected void setJCAProvider(Provider prov) {
    setProvider(prov);
    this.mJcaProviderName = prov != null ? prov.getName() : null;
}

From source file:org.cesecore.keys.token.BaseCryptoToken.java

private void setProvider(Provider prov) {
    if (prov != null) {
        String pName = prov.getName();
        if (pName.startsWith("LunaJCA")) {
            // Luna Java provider does not contain support for RSA/ECB/PKCS1Padding but this is
            // the same as the alias below on small amounts of data
            prov.put("Alg.Alias.Cipher.RSA/NONE/NoPadding", "RSA//NoPadding");
            prov.put("Alg.Alias.Cipher.1.2.840.113549.1.1.1", "RSA//NoPadding");
            prov.put("Alg.Alias.Cipher.RSA/ECB/PKCS1Padding", "RSA//PKCS1v1_5");
            prov.put("Alg.Alias.Cipher.1.2.840.113549.3.7", "DES3/CBC/PKCS5Padding");
        }/*from   www . ja v  a2s  .  c  om*/
        if (Security.getProvider(pName) == null) {
            Security.addProvider(prov);
        }
        if (Security.getProvider(pName) == null) {
            throw new ProviderException("Not possible to install provider: " + pName);
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("No provider passed to setProvider()");
        }
    }
}