Example usage for java.security GeneralSecurityException getMessage

List of usage examples for java.security GeneralSecurityException getMessage

Introduction

In this page you can find the example usage for java.security GeneralSecurityException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.globus.gsi.X509Credential.java

public PrivateKey getPrivateKey(String password) throws CredentialException {

    if (this.opensslKey.isEncrypted()) {
        if (password == null) {
            throw new CredentialException("Key encrypted, password required");
        } else {/*  w w w .  ja v  a 2  s .c  o m*/
            try {
                this.opensslKey.decrypt(password);
            } catch (GeneralSecurityException exp) {
                throw new CredentialException(exp.getMessage(), exp);
            }
        }
    }
    return this.opensslKey.getPrivateKey();

}

From source file:org.globus.gsi.X509Credential.java

/**
 * Returns strength of the private/public key in bits.
 *
 * @return strength of the key in bits. Returns -1 if unable to determine it.
 *///from  ww  w.  j a  v a  2s.co m
public int getStrength(String password) throws CredentialException {
    if (opensslKey == null) {
        return -1;
    }
    if (this.opensslKey.isEncrypted()) {
        if (password == null) {
            throw new CredentialException("Key encrypted, password required");
        } else {
            try {
                this.opensslKey.decrypt(password);
            } catch (GeneralSecurityException exp) {
                throw new CredentialException(exp.getMessage(), exp);
            }
        }
    }
    return ((RSAPrivateKey) opensslKey.getPrivateKey()).getModulus().bitLength();
}

From source file:org.dcm4chee.proxy.dimse.CStore.java

private Association newForwardAssociation(Association as, String callingAET, String calledAET, AAssociateRQ rq,
        ProxyAEExtension proxyAEE, HashMap<String, Association> fwdAssocs, ForwardRule rule) {
    rq.setCallingAET(callingAET);//from w  ww. j ava  2 s.c o m
    rq.setCalledAET(calledAET);
    Association asInvoked = null;
    try {
        asInvoked = ForwardConnectionUtils.openForwardAssociation(proxyAEE, as, rule, callingAET, calledAET, rq,
                aeCache);
    } catch (GeneralSecurityException e) {
        LOG.error("Failed to create SSL context: ", e.getMessage());
        as.setProperty(ProxyAEExtension.FILE_SUFFIX, RetryObject.GeneralSecurityException.getSuffix() + "0");
    } catch (ConfigurationException e) {
        LOG.error("Unable to load configuration for destination AET: ", e.getMessage());
        as.setProperty(ProxyAEExtension.FILE_SUFFIX, RetryObject.ConfigurationException.getSuffix() + "0");
    } catch (Exception e) {
        LOG.error("Unable to connect to {}: {}", new Object[] { calledAET, e.getMessage() });
        as.setProperty(ProxyAEExtension.FILE_SUFFIX, RetryObject.ConnectionException.getSuffix() + "0");
    }
    return asInvoked;
}

From source file:org.kuali.rice.krad.maintenance.MaintainableImpl.java

/**
 * Allows locking of maintenance objects other than the one of the current maintenance object.
 *
 * @param documentNumber of the locking maintenance document
 * @param documentTypeName of the maintenance document to be locked
 * @param dataObjectClass of the maintenance document to be locked
 * @param dataObject of the maintenance document to be locked
 * @return/*from w  w  w  .  j  a  va  2 s .  c  om*/
 */
protected List<MaintenanceLock> generateMaintenanceLocks(String documentNumber, String documentTypeName,
        Class<?> dataObjectClass, Object dataObject) {
    List<MaintenanceLock> maintenanceLocks = new ArrayList<MaintenanceLock>();
    StringBuffer lockRepresentation = new StringBuffer(dataObjectClass.getName());
    lockRepresentation.append(KRADConstants.Maintenance.LOCK_AFTER_CLASS_DELIM);

    DataObjectWrapper<Object> wrapper = getDataObjectService().wrap(dataObject);

    List<String> keyFieldNames = getDocumentDictionaryService().getLockingKeys(documentTypeName);

    for (Iterator<?> i = keyFieldNames.iterator(); i.hasNext();) {
        String fieldName = (String) i.next();

        Object fieldValue = wrapper.getPropertyValueNullSafe(fieldName);
        if (fieldValue == null) {
            fieldValue = "";
        }

        // check if field is a secure
        if (getDataObjectAuthorizationService().attributeValueNeedsToBeEncryptedOnFormsAndLinks(dataObjectClass,
                fieldName)) {
            try {
                if (CoreApiServiceLocator.getEncryptionService().isEnabled()) {
                    fieldValue = getEncryptionService().encrypt(fieldValue);
                }
            } catch (GeneralSecurityException e) {
                LOG.error("Unable to encrypt secure field for locking representation " + e.getMessage());
                throw new RuntimeException(
                        "Unable to encrypt secure field for locking representation " + e.getMessage());
            }
        }

        lockRepresentation.append(fieldName);
        lockRepresentation.append(KRADConstants.Maintenance.LOCK_AFTER_FIELDNAME_DELIM);
        lockRepresentation.append(String.valueOf(fieldValue));
        if (i.hasNext()) {
            lockRepresentation.append(KRADConstants.Maintenance.LOCK_AFTER_VALUE_DELIM);
        }
    }

    MaintenanceLock maintenanceLock = new MaintenanceLock();
    maintenanceLock.setDocumentNumber(documentNumber);
    maintenanceLock.setLockingRepresentation(lockRepresentation.toString());
    maintenanceLocks.add(maintenanceLock);

    return maintenanceLocks;
}

From source file:org.ssatguru.camel.salesforce.maven.CamelSalesforceMojo.java

protected SalesforceHttpClient createHttpClient() throws MojoExecutionException {

    final SalesforceHttpClient httpClient;

    // set ssl context parameters
    try {// ww w.  j ava 2 s. c o  m

        final SSLContextParameters contextParameters = sslContextParameters != null ? sslContextParameters
                : new SSLContextParameters();
        final SslContextFactory sslContextFactory = new SslContextFactory();
        sslContextFactory.setSslContext(contextParameters.createSSLContext());

        httpClient = new SalesforceHttpClient(sslContextFactory);

    } catch (GeneralSecurityException e) {
        throw new MojoExecutionException("Error creating default SSL context: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new MojoExecutionException("Error creating default SSL context: " + e.getMessage(), e);
    }

    // default settings
    httpClient.setConnectTimeout(DEFAULT_TIMEOUT);
    httpClient.setTimeout(DEFAULT_TIMEOUT);

    // enable redirects, no need for a RedirectListener class in Jetty 9
    httpClient.setFollowRedirects(true);

    // set HTTP client parameters
    if (httpClientProperties != null && !httpClientProperties.isEmpty()) {
        try {
            IntrospectionSupport.setProperties(httpClient, new HashMap<String, Object>(httpClientProperties));
        } catch (Exception e) {
            throw new MojoExecutionException("Error setting HTTP client properties: " + e.getMessage(), e);
        }
    }

    // wait for 1 second longer than the HTTP client response timeout
    responseTimeout = httpClient.getTimeout() + 1000L;

    // set http proxy settings
    // set HTTP proxy settings
    if (this.httpProxyHost != null && httpProxyPort != null) {
        Origin.Address proxyAddress = new Origin.Address(this.httpProxyHost, this.httpProxyPort);
        ProxyConfiguration.Proxy proxy;
        if (isHttpProxySocks4) {
            proxy = new Socks4Proxy(proxyAddress, isHttpProxySecure);
        } else {
            proxy = new HttpProxy(proxyAddress, isHttpProxySecure);
        }
        if (httpProxyIncludedAddresses != null && !httpProxyIncludedAddresses.isEmpty()) {
            proxy.getIncludedAddresses().addAll(httpProxyIncludedAddresses);
        }
        if (httpProxyExcludedAddresses != null && !httpProxyExcludedAddresses.isEmpty()) {
            proxy.getExcludedAddresses().addAll(httpProxyExcludedAddresses);
        }
        httpClient.getProxyConfiguration().getProxies().add(proxy);
    }
    if (this.httpProxyUsername != null && httpProxyPassword != null) {

        ObjectHelper.notEmpty(httpProxyAuthUri, "httpProxyAuthUri");
        ObjectHelper.notEmpty(httpProxyRealm, "httpProxyRealm");

        final Authentication authentication;
        if (httpProxyUseDigestAuth) {
            authentication = new DigestAuthentication(URI.create(httpProxyAuthUri), httpProxyRealm,
                    httpProxyUsername, httpProxyPassword);
        } else {
            authentication = new BasicAuthentication(URI.create(httpProxyAuthUri), httpProxyRealm,
                    httpProxyUsername, httpProxyPassword);
        }
        httpClient.getAuthenticationStore().addAuthentication(authentication);
    }

    // set session before calling start()
    final SalesforceSession session = new SalesforceSession(httpClient, httpClient.getTimeout(),
            new SalesforceLoginConfig(loginUrl, clientId, clientSecret, userName, password, false));
    httpClient.setSession(session);

    try {
        httpClient.start();
    } catch (Exception e) {
        throw new MojoExecutionException("Error creating HTTP client: " + e.getMessage(), e);
    }
    return httpClient;
}

From source file:org.kuali.rice.kns.util.FieldUtils.java

public static void populateSecureField(Field field, Object fieldValue) {
    // set encrypted & masked value if user does not have permission to see real value in UI
    // element.isSecure() => a non-null AttributeSecurity object is set in the field
    if (field.isSecure()) {
        try {// w  w w .  jav  a 2 s.c  om
            if (fieldValue != null && fieldValue.toString().endsWith(EncryptionService.HASH_POST_PREFIX)) {
                field.setEncryptedValue(fieldValue.toString());
            } else {
                if (CoreApiServiceLocator.getEncryptionService().isEnabled()) {
                    field.setEncryptedValue(CoreApiServiceLocator.getEncryptionService().encrypt(fieldValue)
                            + EncryptionService.ENCRYPTION_POST_PREFIX);
                }
            }
        } catch (GeneralSecurityException e) {
            throw new RuntimeException("Unable to encrypt secure field " + e.getMessage());
        }
        //field.setDisplayMaskValue(field.getAttributeSecurity().getDisplayMaskValue(fieldValue));
    }
}

From source file:org.apache.jmeter.protocol.http.proxy.JMeterProxyControl.java

public String[] getCertificateDetails() {
    if (isDynamicMode()) {
        try {//from ww w . j a  v a  2s. c  o  m
            X509Certificate caCert = (X509Certificate) sslKeyStore
                    .getCertificate(KeyToolUtils.getRootCAalias());
            if (caCert == null) {
                return new String[] { "Could not find certificate" };
            }
            return new String[] { caCert.getSubjectX500Principal().toString(),
                    "Fingerprint(SHA1): "
                            + JOrphanUtils.baToHexString(DigestUtils.sha1(caCert.getEncoded()), ' '),
                    "Created: " + caCert.getNotBefore().toString() };
        } catch (GeneralSecurityException e) {
            LOG.error("Problem reading root CA from keystore", e);
            return new String[] { "Problem with root certificate", e.getMessage() };
        }
    }
    return null; // should not happen
}

From source file:com.l2jfree.loginserver.manager.LoginManager.java

/**
 * Private constructor to avoid direct instantiation.
 * Initialize a key generator./*from  w ww.  j  a va2 s .  c  o m*/
 */
private LoginManager() {
    try {
        _log.info("LoginManager: initializing.");

        _hackProtection = new FastMap<InetAddress, FailedLoginAttempt>();

        _keyPairs = new ScrambledKeyPair[10];

        _service = (AccountsServices) L2Registry.getBean("AccountsServices");

        _connections = new FastList<L2Client>();

        KeyPairGenerator keygen = null;

        try {
            keygen = KeyPairGenerator.getInstance("RSA");
            RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(1024, RSAKeyGenParameterSpec.F4);
            keygen.initialize(spec);
        } catch (GeneralSecurityException e) {
            _log.fatal("Error in RSA setup:", e);
            _log.info("Server shutting down now");
            System.exit(1);
            return;
        }

        //generate the initial set of keys
        for (int i = 0; i < 10; i++) {
            _keyPairs[i] = new ScrambledKeyPair(keygen.generateKeyPair());
        }
        _log.info("LoginManager: Cached 10 KeyPairs for RSA communication");

        testCipher((RSAPrivateKey) _keyPairs[0].getPair().getPrivate());

        // Store keys for blowfish communication
        generateBlowFishKeys();
    } catch (GeneralSecurityException e) {
        _log.fatal("FATAL: Failed initializing LoginManager. Reason: " + e.getMessage(), e);
        System.exit(1);
    }

}

From source file:com.google.cloud.hadoop.gcsio.GoogleCloudStorageImpl.java

/**
 * Constructs an instance of GoogleCloudStorageImpl.
 *
 * @param credential OAuth2 credential that allows access to GCS
 * @throws IOException on IO error/*from  w  ww.java2 s  .co m*/
 */
public GoogleCloudStorageImpl(GoogleCloudStorageOptions options, Credential credential) throws IOException {
    Preconditions.checkArgument(options != null, "options must not be null");

    log.debug("GCS(%s)", options.getAppName());

    options.throwIfNotValid();

    this.storageOptions = options;

    Preconditions.checkArgument(credential != null, "credential must not be null");

    this.httpRequestInitializer = new RetryHttpInitializer(credential, options.getAppName());

    // HTTP transport used for interacting with Google APIs.
    ApacheHttpTransport.Builder httpTransportBuilder = new ApacheHttpTransport.Builder();
    try {
        httpTransportBuilder.trustCertificates(GoogleUtils.getCertificateTrustStore());
    } catch (GeneralSecurityException e) {
        log.error(e.getMessage(), e);
    }
    HttpHost proxyHost = options.getProxyHost();
    if (proxyHost != null) {
        httpTransportBuilder.setProxy(proxyHost);
    }

    // Create GCS instance.
    gcs = new Storage.Builder(httpTransportBuilder.build(), JSON_FACTORY, httpRequestInitializer)
            .setApplicationName(options.getAppName()).build();
}

From source file:com.mario22gmail.license.nfc_project.NavigationDrawerActivity.java

public void CreateApplicationButton(View view) {
    if (card != null) {
        try {/* w w  w  .  j av  a 2  s .  co m*/
            DesFireCreateApplication(card, 2);
        } catch (GeneralSecurityException e) {
            e.printStackTrace();
            Log.i(nfcDebugTag, "Create app security error" + e.getMessage());
        } catch (IOException e) {
            e.printStackTrace();
            Log.i(nfcDebugTag, "Create app io error" + e.getMessage());

        } catch (SmartCardException e) {
            e.printStackTrace();
            Log.i(nfcDebugTag, "Create app smart card error" + e.getMessage());

        }
    }
}