Package org.wso2.carbon.security

Examples of org.wso2.carbon.security.SecurityConfigException


        try {
            return new String(cryptoUtil.base64DecodeAndDecrypt(encryptedString));
        } catch (CryptoException e) {
            String msg = "Unable to decode and decrypt password string.";
            log.error(msg, e);
            throw new SecurityConfigException(msg, e);
        }
    }
View Full Code Here


            }
      return names;
    } catch (RegistryException e) {
      log.error(e.getMessage(), e);
      throw new SecurityConfigException(e.getMessage(), e);
    }
  }
View Full Code Here

  public void addKeyStoreWithFilePath(String filePath, String filename, String password,
      String provider, String type, String pvtkeyPass) throws SecurityConfigException {
    try {
      addKeyStore(readBytesFromFile(filePath), filename, password, provider, type, pvtkeyPass);
    } catch (IOException e) {
      throw new SecurityConfigException("Error while loading keystore from file " + filePath);
    }

  }
View Full Code Here

  }

  public void addKeyStore(byte[] content, String filename, String password, String provider,
      String type, String pvtkeyPass) throws SecurityConfigException {
    if (filename == null) {
      throw new SecurityConfigException("Key Store name can't be null");
    }
    try {
      if (KeyStoreUtil.isPrimaryStore(filename)) {
        throw new SecurityConfigException("Key store "+ filename + " already available");
      }

      String path = SecurityConstants.KEY_STORES + "/" + filename;
      if (registry.resourceExists(path)) {
        throw new SecurityConfigException("Key store "+ filename + " already available");
      }

      KeyStore keyStore = KeyStore.getInstance(type);
      keyStore.load(new ByteArrayInputStream(content), password.toCharArray());

      // check for more private keys
      Enumeration enumeration = keyStore.aliases();
      String pvtKeyAlias = null;
      while (enumeration.hasMoreElements()) {
        String alias = (String) enumeration.nextElement();
        if (keyStore.isKeyEntry(alias)) {
          if (pvtKeyAlias == null) {
            pvtKeyAlias = alias;
          } else {
            // more than one private key
            throw new SecurityConfigException("more than one private key");
          }
        }
      }

      // just to test weather pvt key password is correct.
      keyStore.getKey(pvtKeyAlias, pvtkeyPass.toCharArray());

      CryptoUtil cryptoUtil = CryptoUtil.getDefaultCryptoUtil();

      Resource resource = registry.newResource();
      resource.addProperty(SecurityConstants.PROP_PASSWORD, cryptoUtil
          .encryptAndBase64Encode(password.getBytes()));
      resource.addProperty(SecurityConstants.PROP_PROVIDER, provider);
      resource.addProperty(SecurityConstants.PROP_TYPE, type);

      if (pvtKeyAlias != null) {
        resource.addProperty(SecurityConstants.PROP_PRIVATE_KEY_ALIAS, pvtKeyAlias);
        resource.addProperty(SecurityConstants.PROP_PRIVATE_KEY_PASS, cryptoUtil
            .encryptAndBase64Encode(pvtkeyPass.getBytes()));
      }

      resource.setContent(content);
      registry.put(path, resource);
    } catch (SecurityConfigException e) {
      throw e;
    } catch (Exception e) {
      log.error(e.getMessage(), e);
      throw new SecurityConfigException(e.getMessage(), e);
    }
  }
View Full Code Here

  }

  public void deleteStore(String keyStoreName) throws SecurityConfigException {
    try {
      if (keyStoreName == null || (keyStoreName = keyStoreName.trim()).length() == 0) {
        throw new SecurityConfigException("Key Store name can't be null");
      }

      if (KeyStoreUtil.isPrimaryStore(keyStoreName)) {
        throw new SecurityConfigException("Not allowed to delete the primary key store : "
                        + keyStoreName);
      }

      String path = SecurityConstants.KEY_STORES + "/" + keyStoreName;
      boolean isFound = false;
      Association[] assocs = registry.getAllAssociations(path);
      if (assocs.length > 0) {
        isFound = true;
      }

            if (isFound) {
                throw new SecurityConfigException("Key store : " + keyStoreName +
                        " is already in use and can't be deleted");
      }
      registry.delete(path);
    } catch (RegistryException e) {
      log.error(e.getMessage(), e);
      throw new SecurityConfigException(e.getMessage(), e);
    }
  }
View Full Code Here

  public void importCertToStore(String fileName, String certData, String keyStoreName)
      throws SecurityConfigException {
    try {
      if (keyStoreName == null) {
        throw new SecurityConfigException("Key Store name can't be null");
      }

      KeyStoreManager keyMan = KeyStoreManager.getInstance((UserRegistry)registry);
      KeyStore ks = keyMan.getKeyStore(keyStoreName);

      byte[] bytes = Base64.decode(certData);
      CertificateFactory factory = CertificateFactory.getInstance("X.509");
      X509Certificate cert;
            try {
                cert = (X509Certificate) factory
                    .generateCertificate(new ByteArrayInputStream(bytes));
            } catch (CertificateException e) {
                log.error(e.getMessage(), e);
                throw new SecurityConfigException("Invalid format of the provided certificate file");
            }

      if (ks.getCertificateAlias(cert) != null) {
        // We already have this certificate in the key store - ignore
        // adding it twice
        return;
      }

      // String alias = this.getAlias(cert);
      ks.setCertificateEntry(fileName, cert);

      keyMan.updateKeyStore(keyStoreName, ks);

    } catch (SecurityConfigException e) {
      throw e;
    } catch (Exception e) {
      log.error(e.getMessage(), e);
      throw new SecurityConfigException(e.getMessage(), e);
    }

  }
View Full Code Here

      throws SecurityConfigException {
    String alias = null;

    try {
      if (keyStoreName == null) {
        throw new SecurityConfigException("Key Store name can't be null");
      }

      KeyStoreManager keyMan = KeyStoreManager.getInstance((UserRegistry)registry);
      KeyStore ks = keyMan.getKeyStore(keyStoreName);

      byte[] bytes = Base64.decode(certData);
      CertificateFactory factory = CertificateFactory.getInstance("X.509");
      X509Certificate cert;
            try {
                cert = (X509Certificate) factory
                    .generateCertificate(new ByteArrayInputStream(bytes));
            } catch (Exception e) {
                throw new SecurityConfigException("Invalid format of the provided certificate file");
            }

      if (ks.getCertificateAlias(cert) != null) {
        // We already have this certificate in the key store - ignore
        // adding it twice
        return null;
      }
      alias = cert.getSubjectDN().getName();
      // String alias = this.getAlias(cert);
      ks.setCertificateEntry(alias, cert);

      keyMan.updateKeyStore(keyStoreName, ks);

      return alias;

    } catch (SecurityConfigException e) {
      throw e;
    } catch (Exception e) {
      log.error(e.getMessage(), e);
      throw new SecurityConfigException(e.getMessage() ,
          e);
    }
  }
View Full Code Here

  public void removeCertFromStore(String alias, String keyStoreName)
      throws SecurityConfigException {
    try {
      if (keyStoreName == null) {
        throw new SecurityConfigException("Key Store name can't be null");
      }

      KeyStoreManager keyMan = KeyStoreManager.getInstance((UserRegistry)registry);
      KeyStore ks = keyMan.getKeyStore(keyStoreName);

      if (ks.getCertificate(alias) == null) {
        return;
      }

      ks.deleteEntry(alias);
      keyMan.updateKeyStore(keyStoreName, ks);
    } catch (SecurityConfigException e) {
      throw e;
    } catch (Exception e) {
      log.error(e.getMessage(), e);
      throw new SecurityConfigException(e.getMessage(), e);
    }
  }
View Full Code Here

                        + SAMLTokenIssuerConfig.SAML_ISSUER_CONFIG.getLocalPart());
            }

        } catch (Exception e) {
            log.error("Error while adding a trusted service", e);
            throw new SecurityConfigException(e.getMessage(), e);
        }
    }
View Full Code Here

      names = lst.toArray(new String[lst.size()]);
    } catch (SecurityConfigException e) {
      throw e;
    } catch (Exception e) {
      log.error(e.getMessage(), e);
      throw new SecurityConfigException(e.getMessage(), e);
    }

    return names;
  }
View Full Code Here

TOP

Related Classes of org.wso2.carbon.security.SecurityConfigException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.