Package org.wso2.carbon.security.keystore.service

Examples of org.wso2.carbon.security.keystore.service.KeyStoreData


          int lastIndex = fullname.lastIndexOf("/");
          String name = fullname.substring(lastIndex + 1);
          String type = store.getProperty(SecurityConstants.PROP_TYPE);
          String provider = store.getProperty(SecurityConstants.PROP_PROVIDER);

          KeyStoreData data = new KeyStoreData();
          data.setKeyStoreName(name);
          data.setKeyStoreType(type);
          data.setProvider(provider);

          String alias = store.getProperty(SecurityConstants.PROP_PRIVATE_KEY_ALIAS);
          if (alias != null) {
            data.setPrivateStore(true);
          } else {
            data.setPrivateStore(false);
          }

                    // Dump the generated public key to the file system for sub tenants
                    if(!isSuperTenant){
                        Association[] associations = registry.getAssociations(
                                ks[i],SecurityConstants.ASSOCIATION_TENANT_KS_PUB_KEY);
                        if(associations != null && associations.length > 0){
                            Resource pubKeyResource = registry.get(associations[0].getDestinationPath());
                            String fileName = generatePubCertFileName(ks[i],
                                                                      pubKeyResource.getProperty(
                                                                              SecurityConstants.PROP_TENANT_PUB_KEY_FILE_NAME_APPENDER));
                            String pubKeyFilePath = KeyStoreMgtUtil.dumpCert(
                                    MessageContext.getCurrentMessageContext().getConfigurationContext(),
                                    (byte[])pubKeyResource.getContent(), fileName);
                            data.setPubKeyFilePath(pubKeyFilePath);
                        }
                    }
          lst.add(data);

        }
        names = new KeyStoreData[lst.size() + 1];
        Iterator<KeyStoreData> ite = lst.iterator();
        int count = 0;
        while (ite.hasNext()) {
          names[count] = ite.next();
          count++;
        }

                if (isSuperTenant) {
                    KeyStoreData data = new KeyStoreData();
                    ServerConfiguration config = ServerConfiguration.getInstance();
                    String fileName = config
                            .getFirstProperty(RegistryResources.SecurityManagement.SERVER_PRIMARY_KEYSTORE_FILE);
                    String type = config
                            .getFirstProperty(RegistryResources.SecurityManagement.SERVER_PRIMARY_KEYSTORE_TYPE);
                    String name = KeyStoreUtil.getKeyStoreFileName(fileName);
                    data.setKeyStoreName(name);
                    data.setKeyStoreType(type);
                    data.setProvider(" ");
                    data.setPrivateStore(true);

                    names[count] = data;
                }

            }
View Full Code Here


    public String[] getCertAliasOfPrimaryKeyStore() throws SecurityConfigException {

        KeyStoreData[] keyStores = getKeyStores();

        KeyStoreData primaryKeystore = null;
        for (int i = 0; i < keyStores.length; i++) {
            if (KeyStoreUtil.isPrimaryStore(keyStores[i].getKeyStoreName())) {
                primaryKeystore = keyStores[i];
                break;
            }
        }
        if (primaryKeystore != null) {
            return getStoreEntries(primaryKeystore.getKeyStoreName());
        }

        throw new SecurityConfigException("Primary Keystore cannot be found.");
    }
View Full Code Here

      // Create a cert array
      CertData[] certs = certDataList.toArray(new CertData[certDataList.size()]);

      // Create a KeyStoreData bean, set the name and fill in the cert information
      KeyStoreData keyStoreData = new KeyStoreData();
      keyStoreData.setKeyStoreName(keyStoreName);
      keyStoreData.setCerts(certs);
      keyStoreData.setKeyStoreType(keyStoreType);

      aliases = keyStore.aliases();
      while (aliases.hasMoreElements()) {
        String alias = aliases.nextElement();
        // There be only one entry in WSAS related keystores
        if (keyStore.isKeyEntry(alias)) {
          X509Certificate cert = (X509Certificate) keyStore.getCertificate(alias);
          keyStoreData.setKey(fillCertData(cert, alias, formatter));

          PrivateKey key = (PrivateKey) keyStore.getKey(alias, privateKeyPassowrd
              .toCharArray());
          String pemKey;
          pemKey = "-----BEGIN PRIVATE KEY-----\n";
          pemKey += Base64.encode(key.getEncoded());
          pemKey += "\n-----END PRIVATE KEY-----";
          keyStoreData.setKeyValue(pemKey);
          break;

        }
      }
      return keyStoreData;
View Full Code Here

        }
    }

    public String[] getCertAliasOfPrimaryKeyStore() throws IdentityException {
        KeyStoreData[] keyStores = getKeyStores();
        KeyStoreData primaryKeyStore = null;
        for (int i = 0; i < keyStores.length; i++) {
            if (getTenantDomain() == null && KeyStoreUtil.isPrimaryStore(keyStores[i].getKeyStoreName())) {
                primaryKeyStore = keyStores[i];
                break;
            }
            else if (getTenantDomain() != null && SAMLSSOUtil.generateKSNameFromDomainName(getTenantDomain()).equals(
                    keyStores[i].getKeyStoreName())){
                primaryKeyStore = keyStores[i];
                break;
            }
        }
        if (primaryKeyStore != null) {
                return getStoreEntries(primaryKeyStore.getKeyStoreName());
        }
        throw new IdentityException("Primary Keystore cannot be found.");
    }
View Full Code Here

    try {
      KeyStoreData[] keystores = getServiceKeyStores(serviceName);
      KeyStoreManager keyMan = KeyStoreManager.getInstance(null);
      KeyStoreAdmin keyAdmin = new KeyStoreAdmin(IdentityTenantUtil.getRegistry(null, null));
      KeyStoreData privateStore = null;
      KeyStoreData keyStoreData = null;

      if (keystores != null && keystores.length > 0) {
        for (int i = 0; i < keystores.length; i++) {
          if (KeyStoreUtil.isPrimaryStore(keystores[i].getKeyStoreName())) {
            privateStore = keystores[i];
            break;
          }
        }
      }

      if (privateStore != null) {
        // policy has a private key store
        keyStoreData = keyAdmin.getKeystoreInfo(privateStore.getKeyStoreName());
        cert = getCertificate(privateStore.getKeyStoreName(), keyStoreData.getKey()
            .getAlias());
      } else {
        // this is for UT token policy
        ServerConfiguration config = ServerConfiguration.getInstance();
        String keyalias = config.getFirstProperty("Security.KeyStore.KeyAlias");
View Full Code Here

        }

        public void run() {
            try {
                MessageContext msgCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
                Event<MessageContext> event = new Event(msgCtx);
                subscriptions = subscriptionManager.getMatchingSubscriptions(event);
            } catch (EventException e) {
                handleException("Matching subscriptions fetching error", e);
            }
View Full Code Here

     * @throws EventException event
     */
    private void processGetStatusRequest(MessageContext mc,
                                         ResponseMessageBuilder messageBuilder)
            throws AxisFault, EventException {
        Subscription subscription =
                SubscriptionMessageBuilder.createGetStatusMessage(mc);
        if (log.isDebugEnabled()) {
            log.debug("GetStatus request recived for SynapseSubscription ID : " +
                    subscription.getId());
        }
        subscription = subscriptionManager.getSubscription(subscription.getId());
        if (subscription != null) {
            if (log.isDebugEnabled()) {
                log.debug("Sending GetStatus responce for SynapseSubscription ID : " +
                        subscription.getId());
            }
            //send the responce
            SOAPEnvelope soapEnvelope = messageBuilder.genGetStatusResponse(subscription);
            dispatchResponse(soapEnvelope, EventingConstants.WSE_GET_STATUS_RESPONSE,
                    mc, false);
View Full Code Here

            // Adding static subscriptions
            List<Subscription> staticSubscriptionList =
                    eventSource.getSubscriptionManager().getStaticSubscriptions();
            for (Iterator<Subscription> iterator = staticSubscriptionList.iterator();
                 iterator.hasNext();) {
                Subscription staticSubscription = iterator.next();
                OMElement staticSubElem =
                        fac.createOMElement("subscription", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
                staticSubElem.addAttribute(
                        fac.createOMAttribute("id", nullNS, staticSubscription.getId()));
                OMElement filterElem =
                        fac.createOMElement("filter", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
                filterElem.addAttribute(fac.createOMAttribute("source", nullNS,
                        (String) staticSubscription.getFilterValue()));
                filterElem.addAttribute(fac.createOMAttribute("dialect", nullNS,
                        (String) staticSubscription.getFilterDialect()));
                staticSubElem.addChild(filterElem);
                OMElement endpointElem =
                        fac.createOMElement("endpoint", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
                OMElement addressElem =
                        fac.createOMElement("address", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
                addressElem.addAttribute(
                        fac.createOMAttribute("uri", nullNS, staticSubscription.getEndpointUrl()));
                endpointElem.addChild(addressElem);
                staticSubElem.addChild(endpointElem);
                if (staticSubscription.getExpires() != null) {
                    OMElement expiresElem =
                            fac.createOMElement("expires", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
                    fac.createOMText(expiresElem,
                            ConverterUtil.convertToString(staticSubscription.getExpires()));
                    staticSubElem.addChild(expiresElem);
                }
                evenSourceElem.addChild(staticSubElem);
            }
View Full Code Here


    public SynapseSubscription() {
        this.setId(UIDGenerator.generateURNString());
        this.setDeliveryMode(EventingConstants.WSE_DEFAULT_DELIVERY_MODE);
        SubscriptionData subscriptionData = new SubscriptionData();
        subscriptionData.setProperty(SynapseEventingConstants.STATIC_ENTRY, "false");
        this.setSubscriptionData(subscriptionData);
    }
View Full Code Here

                    .getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "class"));
            if (clazz != null) {
                String className = clazz.getAttributeValue();
                try {
                    Class subscriptionManagerClass = Class.forName(className);
                    SubscriptionManager manager =
                            (SubscriptionManager) subscriptionManagerClass.newInstance();
                    Iterator itr = subscriptionManagerElem.getChildrenWithName(PROPERTIES_QNAME);
                    while (itr.hasNext()) {
                        OMElement propElem = (OMElement) itr.next();
                        String propName =
                                propElem.getAttribute(new QName("name")).getAttributeValue();
                        String propValue =
                                propElem.getAttribute(new QName("value")).getAttributeValue();
                        if (propName != null && !"".equals(propName.trim()) &&
                                propValue != null && !"".equals(propValue.trim())) {

                            propName = propName.trim();
                            propValue = propValue.trim();

                            PasswordManager passwordManager =
                                    PasswordManager.getInstance();
                            String key = eventSource.getName() + "." + propName;

                            if (passwordManager.isInitialized()
                                    && passwordManager.isTokenProtected(key)) {
                                eventSource.putConfigurationProperty(propName, propValue);
                                propValue = passwordManager.resolve(propValue);
                            }

                            manager.addProperty(propName, propValue);
                        }
                    }
                    eventSource.setSubscriptionManager(manager);
                    eventSource.getSubscriptionManager()
                            .init(); // Initialise before doing further processing, required for static subscriptions
View Full Code Here

TOP

Related Classes of org.wso2.carbon.security.keystore.service.KeyStoreData

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.