[Carbon-dev] svn commit r19114 - in trunk/carbon-components/security/org.wso2.carbon.modules.security: . src/main/java/org/wso2/carbon/security src/main/java/org/wso2/carbon/security/internal src/main/java/org/wso2/carbon/security/service src/main/java/org/wso2/carbon/security/util src/main/java/org/wso2/carbon/service/mgt src/main/resources/org/wso2/carbon/security

dimuthul at wso2.com dimuthul at wso2.com
Thu Jul 10 21:20:08 PDT 2008


Author: dimuthul
Date: Thu Jul 10 21:20:07 2008
New Revision: 19114
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=19114

Log:
Cleaning up code.



Removed:
   trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/java/org/wso2/carbon/security/SecurityComponentException.java
Modified:
   trunk/carbon-components/security/org.wso2.carbon.modules.security/pom.xml
   trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/java/org/wso2/carbon/security/SecurityConfigAdmin.java
   trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/java/org/wso2/carbon/security/internal/Activator.java
   trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/java/org/wso2/carbon/security/service/SecurityConfigAdminServiceImpl.java
   trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/java/org/wso2/carbon/security/util/ServicePasswordCallbackHandler.java
   trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/java/org/wso2/carbon/service/mgt/ServiceAdmin.java
   trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/resources/org/wso2/carbon/security/errors.properties

Modified: trunk/carbon-components/security/org.wso2.carbon.modules.security/pom.xml
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/security/org.wso2.carbon.modules.security/pom.xml?rev=19114&r1=19113&r2=19114&view=diff
==============================================================================
--- trunk/carbon-components/security/org.wso2.carbon.modules.security/pom.xml	(original)
+++ trunk/carbon-components/security/org.wso2.carbon.modules.security/pom.xml	Thu Jul 10 21:20:07 2008
@@ -138,6 +138,7 @@
                             org.apache.rahas.impl.util
                         </Export-Package>
                         <Import-Package>
+                            org.wso2.carbon.utils.*,
                             org.apache.ws.security.*,
                             org.apache.ws.axis.security.*,
                             javax.xml.crypto.*,

Deleted: trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/java/org/wso2/carbon/security/SecurityComponentException.java
URL: http://wso2.org/svn/browse/wso2/None?pathrev=19113

Modified: trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/java/org/wso2/carbon/security/SecurityConfigAdmin.java
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/java/org/wso2/carbon/security/SecurityConfigAdmin.java?rev=19114&r1=19113&r2=19114&view=diff
==============================================================================
--- trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/java/org/wso2/carbon/security/SecurityConfigAdmin.java	(original)
+++ trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/java/org/wso2/carbon/security/SecurityConfigAdmin.java	Thu Jul 10 21:20:07 2008
@@ -44,6 +44,7 @@
 import org.apache.rampart.policy.RampartPolicyData;
 import org.apache.rampart.policy.model.CryptoConfig;
 import org.apache.rampart.policy.model.RampartConfig;
+import org.apache.ws.secpolicy.WSSPolicyException;
 import org.apache.ws.secpolicy.model.SecureConversationToken;
 import org.apache.ws.secpolicy.model.Token;
 import org.apache.ws.security.handler.WSHandlerConstants;
@@ -51,12 +52,12 @@
 import org.jaxen.SimpleNamespaceContext;
 import org.wso2.carbon.core.RegistryResources;
 import org.wso2.carbon.keystore.KeyStoreUtil;
-
 import org.wso2.carbon.secmgt.SecurityMgmtConstants;
 import org.wso2.carbon.security.util.ServerCrypto;
 import org.wso2.carbon.security.util.ServicePasswordCallbackHandler;
 import org.wso2.carbon.service.mgt.ServiceAdmin;
 import org.wso2.carbon.utils.ServerConfiguration;
+import org.wso2.carbon.utils.ServerException;
 import org.wso2.carbon.utils.WSO2Constants;
 import org.wso2.registry.Association;
 import org.wso2.registry.Collection;
@@ -64,7 +65,6 @@
 import org.wso2.registry.Resource;
 import org.wso2.registry.exceptions.RegistryException;
 
-
 /**
  * Admin service for configuring Security scenarios
  */
@@ -85,12 +85,12 @@
     }
 
     public void activateUsernameTokenAuthentication(String serviceName, String[] userGroups)
-            throws Exception {
-        try {
+            throws SecurityConfigException, AxisFault {
 
+        try {
             AxisService service = axisConfig.getService(serviceName);
             if (service == null) {
-                throw new SecurityComponentException("No such service");
+                throw new SecurityConfigException("nullService");
             }
             this.disableSecurityOnService(serviceName);
             String servicePath = RegistryResources.SERVICE_GROUPS
@@ -107,28 +107,32 @@
                 }
                 //addPasswordCallbackHandler(serviceName, userGroups);
 
-                ServicePasswordCallbackHandler handler = new ServicePasswordCallbackHandler(serviceName, 
-                        userGroups, registry);
+                ServicePasswordCallbackHandler handler = new ServicePasswordCallbackHandler(
+                        serviceName, userGroups, registry);
                 applyEndPointPolicy(serviceName, SecurityConstants.USERNAME_TOKEN_SCENARIO_ID,
                         new Properties());
             } else {
-                throw new SecurityComponentException("missingResource",
-                        new String[] { servicePath });
+                throw new SecurityConfigException("missingResource", new String[] { servicePath });
             }
-        } catch (Exception e) {
-            e.printStackTrace();
+        } catch (RegistryException e) {
+            log.debug(e);
+            throw new SecurityConfigException("registryError",
+                    new String[] { "while activating UT" }, e);
         }
+
     }
 
-    public void disableSecurityOnService(String serviceName) throws Exception {
-        AxisService service = axisConfig.getService(serviceName);
-        if (service == null) {
-            throw new SecurityComponentException("AxisService is Null");
-        }
+    public void disableSecurityOnService(String serviceName) throws SecurityConfigException,
+            AxisFault {
 
         ServiceAdmin admin = new ServiceAdmin(axisConfig);
         try {
 
+            AxisService service = axisConfig.getService(serviceName);
+            if (service == null) {
+                throw new SecurityConfigException("AxisService is Null");
+            }
+
             // at registry
             String servicePath = RegistryResources.SERVICE_GROUPS
                     + service.getAxisServiceGroup().getServiceGroupName()
@@ -190,85 +194,36 @@
             Parameter param = new Parameter();
             param.setName(WSHandlerConstants.PW_CALLBACK_REF);
             service.removeParameter(param);
-
+        } catch (SecurityConfigException e) {
+            throw e;
         } catch (Exception e) {
-            e.printStackTrace();
-            throw new SecurityComponentException("errorApplyingPolicy", e);
+            log.error(e);
+            throw new SecurityConfigException("removingPolicy", e);
         }
     }
 
-    public void addConfidentiality(String serviceName) throws Exception {
-        this.disableSecurityOnService(serviceName);
-        ServicePasswordCallbackHandler handler = new ServicePasswordCallbackHandler(serviceName, 
-                                    null, registry);
-        Parameter param = new Parameter();
-        param.setName(WSHandlerConstants.PW_CALLBACK_REF);
-        param.setValue(handler);
-        AxisService service = axisConfig.getService(serviceName);
-        service.addParameter(param);
+    // not used ........ remove please
+    public void addConfidentiality(String serviceName) throws SecurityConfigException {
 
-        applyEndPointPolicy(serviceName, SecurityConstants.CONFIDENTIALITY_SCENARIO_ID,
-                getServerCryptoProperties(null, null));
     }
 
-    public void addIntegrity(String serviceName) throws Exception {
-        try {
-            this.disableSecurityOnService(serviceName);
-            ServicePasswordCallbackHandler handler = new ServicePasswordCallbackHandler(serviceName, 
-                    null, registry);
+    //not used ........ remove please
+    public void addIntegrity(String serviceName) throws SecurityConfigException {
 
-            Parameter param = new Parameter();
-            param.setName(WSHandlerConstants.PW_CALLBACK_REF);
-            param.setValue(handler);
-            AxisService service = axisConfig.getService(serviceName);
-            service.addParameter(param);
-
-            applyEndPointPolicy(serviceName, SecurityConstants.INTEGRITY_SCENARIO_ID,
-                    getServerCryptoProperties(null, null));
-        } catch (Exception e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-            throw e;
-        }
     }
 
-    public void addNonRepudiation(String serviceName, String keystoreName) throws Exception {
-        try {
-            this.disableSecurityOnService(serviceName);
-            ServicePasswordCallbackHandler handler = new ServicePasswordCallbackHandler(serviceName, null, registry);
-
-            Parameter param = new Parameter();
-            param.setName(WSHandlerConstants.PW_CALLBACK_REF);
-            param.setValue(handler);
-            AxisService service = axisConfig.getService(serviceName);
-            service.addParameter(param);
-
-            //not added trusted keystores ..... so do that now..........
-
-            String servicePath = RegistryResources.SERVICE_GROUPS
-                    + service.getAxisServiceGroup().getServiceGroupName()
-                    + RegistryResources.SERVICES + serviceName;
+    //not used ......... remove please
+    public void addNonRepudiation(String serviceName, String keystoreName)
+            throws SecurityConfigException {
 
-            String ksPath = SecurityMgmtConstants.KEY_STORES + "/" + keystoreName;
-            if (registry.resourceExists(ksPath)) {
-                registry.addAssociation(servicePath, ksPath,
-                        SecurityConstants.ASSOCIATION_PRIVATE_KEYSTORE);
-            }
-            applyEndPointPolicy(serviceName, SecurityConstants.NONREPUDIATION_SCENARIO_ID,
-                    getServerCryptoProperties(keystoreName, null));
-        } catch (Exception e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-            throw e;
-        }
     }
 
-    public void applySecurity(String serviceName, String policyId, String[] trustedStores, 
-            String privateStore, String[] userGroups) throws Exception {
+    public void applySecurity(String serviceName, String policyId, String[] trustedStores,
+            String privateStore, String[] userGroups) throws SecurityConfigException, AxisFault {
         try {
             this.disableSecurityOnService(serviceName);
-            ServicePasswordCallbackHandler handler = new ServicePasswordCallbackHandler(serviceName, 
-                                            userGroups, registry);
+            ServicePasswordCallbackHandler handler = new ServicePasswordCallbackHandler(
+                    serviceName, userGroups, registry);
 
             Parameter param = new Parameter();
             param.setName(WSHandlerConstants.PW_CALLBACK_REF);
@@ -309,23 +264,22 @@
                 }
             }
 
-            applyEndPointPolicy(serviceName, policyId,
-                    getServerCryptoProperties(privateStore, trustedStores));
+            applyEndPointPolicy(serviceName, policyId, getServerCryptoProperties(privateStore,
+                    trustedStores));
 
-        } catch (Exception e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-            throw e;
+        } catch (RegistryException e) {
+            log.error(e);
+            throw new SecurityConfigException("errorPersisting", e);
         }
     }
 
     protected void applyEndPointPolicy(String serviceName, String scenarioId, Properties props)
-            throws SecurityComponentException {
+            throws SecurityConfigException, AxisFault {
 
         try {
             AxisService service = axisConfig.getService(serviceName);
             if (service == null) {
-                throw new SecurityComponentException("AxisService is Null");
+                throw new SecurityConfigException("nullService");
             }
 
             if (scenarioId == SecurityConstants.SCENARIO_DISABLE_SECURITY) {
@@ -339,7 +293,7 @@
                 policy.addAssertion(rampartConfig);
             }
 
-            if ( isHttpsTransportOnly(policy)) {
+            if (isHttpsTransportOnly(policy)) {
                 setServiceTransports(serviceName, getHttpsTransports());
             } else {
                 setServiceTransports(serviceName, getAllTransports());
@@ -357,29 +311,33 @@
             }
             ServiceAdmin admin = new ServiceAdmin(this.axisConfig);
             admin.addPoliciesToService(service, policy, PolicyInclude.SERVICE_POLICY, modulePaths);
-
-        } catch (Exception e) {
-            e.printStackTrace();
-            throw new SecurityComponentException("errorApplyingPolicy", e);
+        } catch (ServerException e) {
+            log.error(e);
+            throw new SecurityConfigException("configuringService",
+                    new String[] { "while appliying Security policy" }, e);
         }
-
     }
 
-    private Policy loadPolicy(String scenarioId) throws Exception {
+    private Policy loadPolicy(String scenarioId) throws SecurityConfigException {
 
-        String resourceUri = SecurityConstants.SECURITY_POLICY + "/" + scenarioId;
-        Resource resource = registry.get(resourceUri);
-        InputStream in = resource.getContentStream();
+        try {
+            String resourceUri = SecurityConstants.SECURITY_POLICY + "/" + scenarioId;
+            Resource resource = registry.get(resourceUri);
+            InputStream in = resource.getContentStream();
 
-        XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(in);
-        StAXOMBuilder builder = new StAXOMBuilder(parser);
+            XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(in);
+            StAXOMBuilder builder = new StAXOMBuilder(parser);
 
-        return PolicyEngine.getPolicy(builder.getDocumentElement());
+            return PolicyEngine.getPolicy(builder.getDocumentElement());
+        } catch (Exception e) {
+            log.error(e);
+            throw new SecurityConfigException("loadingPolicy", e);
+        }
 
     }
 
     private void populateRampartConfig(RampartConfig rampartConfig, Properties props)
-            throws Exception {
+            throws SecurityConfigException {
         if (rampartConfig != null) {
 
             if (!props.isEmpty()) {
@@ -412,9 +370,8 @@
         }
     }
 
-
     private void disengageUnusedModuleFromAxisService(AxisService axisService,
-            List<String> checkList) throws Exception {
+            List<String> checkList) throws SecurityConfigException, AxisFault, RegistryException {
         String serviceResourcePath = RegistryResources.SERVICE_GROUPS
                 + axisService.getAxisServiceGroup().getServiceGroupName()
                 + RegistryResources.SERVICES + axisService.getName();
@@ -466,15 +423,16 @@
             }
 
         }
+
     }
 
-    public Properties getServerCryptoProperties(String privateStore, String[] trustedCertStores) 
-    throws RegistryException{
+    public Properties getServerCryptoProperties(String privateStore, String[] trustedCertStores)
+            throws RegistryException {
         Properties props = new Properties();
 
         ServerConfiguration config = ServerConfiguration.getInstance();
-        props.setProperty(ServerCrypto.PROP_ID_DEFAULT_ALIAS,
-                config.getFirstProperty(SecurityMgmtConstants.PROP_PRIMARY_KEYSTORE_KEY_ALIAS));
+        props.setProperty(ServerCrypto.PROP_ID_DEFAULT_ALIAS, config
+                .getFirstProperty(SecurityMgmtConstants.PROP_PRIMARY_KEYSTORE_KEY_ALIAS));
 
         if (trustedCertStores != null) {
             StringBuffer trstString = new StringBuffer();
@@ -486,19 +444,18 @@
                 props.setProperty(ServerCrypto.PROP_ID_TRUST_STORES, trstString.toString());
             }
         }
-        
+
         if (privateStore != null) {
             props.setProperty(ServerCrypto.PROP_ID_PRIVATE_STORE, privateStore);
             props.setProperty(USER, KeyStoreUtil.getPrivateKeyAlias(registry, privateStore));
-        }else{
-            props.setProperty(USER, 
-                    config.getFirstProperty(SecurityMgmtConstants.PROP_PRIMARY_KEYSTORE_KEY_ALIAS));
+        } else {
+            props.setProperty(USER, config
+                    .getFirstProperty(SecurityMgmtConstants.PROP_PRIMARY_KEYSTORE_KEY_ALIAS));
         }
 
         return props;
     }
-    
-    
+
     /**
      * Expose this service only via the specified transport
      * 
@@ -506,69 +463,73 @@
      * @param transportProtocols
      * @throws AxisFault
      **/
-    public void setServiceTransports(String serviceId,
-                    List<String> transportProtocols) throws Exception {
+    public void setServiceTransports(String serviceId, List<String> transportProtocols)
+            throws SecurityConfigException, AxisFault {
 
-            AxisService axisService = axisConfig.getService(serviceId);
-            
-            if (axisService == null) {
-                throw new SecurityComponentException("AxisService is Null");
-            }
-            
-            ArrayList<String> transports = new ArrayList<String>();
-            for (int i = 0; i < transportProtocols.size(); i++) {
-                    transports.add(transportProtocols.get(i));
-            }
-            axisService.setExposedTransports(transports);
+        AxisService axisService = axisConfig.getService(serviceId);
+
+        if (axisService == null) {
+            throw new SecurityConfigException("nullService");
+        }
 
-            log.info("Successfully add selected transport bindings to service "+ serviceId);
+        ArrayList<String> transports = new ArrayList<String>();
+        for (int i = 0; i < transportProtocols.size(); i++) {
+            transports.add(transportProtocols.get(i));
+        }
+        axisService.setExposedTransports(transports);
+
+        log.info("Successfully add selected transport bindings to service " + serviceId);
     }
-    
+
     /**
      * Check the policy to see whether the service should only be exposed in HTTPS
      * @param policy service policy
      * @return returns true if the service should only be exposed in HTTPS
      * @throws Exception
      */
-    public boolean isHttpsTransportOnly(Policy policy) throws Exception {
-       
+    public boolean isHttpsTransportOnly(Policy policy) throws SecurityConfigException {
+
         // When there is a transport binding sec policy assertion,
         // the service should be exposed only via HTTPS
         boolean httpsRequired = false;
-        
-        Iterator alternatives = policy.getAlternatives();
-        if (alternatives.hasNext()) {
-            List it = (List) alternatives.next();
-            
-            RampartPolicyData rampartPolicyData = RampartPolicyBuilder.build(it);
-            if (rampartPolicyData.isTransportBinding()) {
-                httpsRequired = true;
-            } else if (rampartPolicyData.isSymmetricBinding()) {
-                Token encrToken = rampartPolicyData.getEncryptionToken();
-                if (encrToken instanceof SecureConversationToken) {
-                    Policy bsPol = ((SecureConversationToken) encrToken).getBootstrapPolicy();
-                    Iterator alts = bsPol.getAlternatives();
-                    if (alts.hasNext()) {
+
+        try {
+            Iterator alternatives = policy.getAlternatives();
+            if (alternatives.hasNext()) {
+                List it = (List) alternatives.next();
+
+                RampartPolicyData rampartPolicyData = RampartPolicyBuilder.build(it);
+                if (rampartPolicyData.isTransportBinding()) {
+                    httpsRequired = true;
+                } else if (rampartPolicyData.isSymmetricBinding()) {
+                    Token encrToken = rampartPolicyData.getEncryptionToken();
+                    if (encrToken instanceof SecureConversationToken) {
+                        Policy bsPol = ((SecureConversationToken) encrToken).getBootstrapPolicy();
+                        Iterator alts = bsPol.getAlternatives();
+                        if (alts.hasNext()) {
+                        }
+                        List bsIt = (List) alts.next();
+                        RampartPolicyData bsRampartPolicyData = RampartPolicyBuilder.build(bsIt);
+                        httpsRequired = bsRampartPolicyData.isTransportBinding();
                     }
-                    List bsIt = (List) alts.next();
-                    RampartPolicyData bsRampartPolicyData = RampartPolicyBuilder.build(bsIt);
-                    httpsRequired = bsRampartPolicyData.isTransportBinding();
                 }
             }
-        }  
-        
+        } catch (WSSPolicyException e) {
+            log.error(e);
+            throw new SecurityConfigException("transportSwitch", e);
+        }
+
         return httpsRequired;
     }
-    
+
     /**
      * Get "https" transports in the AxisConfig
      * @return
      */
     public List<String> getHttpsTransports() {
-        
+
         List<String> httpsTransports = new ArrayList<String>();
-        for (Iterator iter = axisConfig.getTransportsIn().keySet().iterator();
-             iter.hasNext();) {
+        for (Iterator iter = axisConfig.getTransportsIn().keySet().iterator(); iter.hasNext();) {
             String transport = (String) iter.next();
             if (transport.toLowerCase().indexOf(SecurityConstants.HTTPS_TRANSPORT) != -1) {
                 httpsTransports.add(transport);
@@ -576,21 +537,19 @@
         }
         return httpsTransports;
     }
-    
+
     /**
      * Get all transports in AxisConfig
      * @return 
      */
     public List<String> getAllTransports() {
-        
+
         List<String> allTransports = new ArrayList<String>();
-        for (Iterator iter = axisConfig.getTransportsIn().keySet().iterator();
-             iter.hasNext();) {
+        for (Iterator iter = axisConfig.getTransportsIn().keySet().iterator(); iter.hasNext();) {
             String transport = (String) iter.next();
             allTransports.add(transport);
         }
         return allTransports;
     }
 
-   
 }

Modified: trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/java/org/wso2/carbon/security/internal/Activator.java
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/java/org/wso2/carbon/security/internal/Activator.java?rev=19114&r1=19113&r2=19114&view=diff
==============================================================================
--- trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/java/org/wso2/carbon/security/internal/Activator.java	(original)
+++ trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/java/org/wso2/carbon/security/internal/Activator.java	Thu Jul 10 21:20:07 2008
@@ -26,7 +26,7 @@
 import org.osgi.framework.ServiceReference;
 import org.wso2.carbon.registry.service.RegistryService;
 import org.wso2.carbon.security.util.XmlConfiguration;
-import org.wso2.carbon.security.SecurityComponentException;
+import org.wso2.carbon.security.SecurityConfigException;
 import org.wso2.carbon.security.SecurityConstants;
 import org.wso2.carbon.security.SecurityScenario;
 import org.wso2.carbon.security.SecurityScenarioDatabase;
@@ -125,7 +125,7 @@
                 }
             }
         } catch (Exception e) {
-            throw new SecurityComponentException("errorSettingupSecurityPolicyAssertionBuilders", e);
+            throw new SecurityConfigException("errorSettingupSecurityPolicyAssertionBuilders", e);
         }
                 
         ServiceReference reference =
@@ -134,7 +134,7 @@
         
         if (reference == null) {
             log.debug("WSO2 Registry is not available");
-            throw new SecurityComponentException("registryNotAvailable");
+            throw new SecurityConfigException("registryNotAvailable");
         } else {
             registryService = (RegistryService)bundleContext.getService(reference);
             log.debug("WSO2 Registry is available : " + registryService.getSystemRegistry());
@@ -191,12 +191,12 @@
             }
         } catch (Exception e) {
             log.error("Error initializing the org.wso2.carbon.security component", e);
-            throw new SecurityComponentException("initializationError", e);
+            throw new SecurityConfigException("initializationError", e);
         }
         
         //TODO :: Load the in memory database 
         //TODO :: Activate security on services
-
+        
     }
 
     public void stop(BundleContext bundleContext) throws Exception {

Modified: trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/java/org/wso2/carbon/security/service/SecurityConfigAdminServiceImpl.java
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/java/org/wso2/carbon/security/service/SecurityConfigAdminServiceImpl.java?rev=19114&r1=19113&r2=19114&view=diff
==============================================================================
--- trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/java/org/wso2/carbon/security/service/SecurityConfigAdminServiceImpl.java	(original)
+++ trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/java/org/wso2/carbon/security/service/SecurityConfigAdminServiceImpl.java	Thu Jul 10 21:20:07 2008
@@ -22,13 +22,9 @@
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.MessageContext;
-import org.wso2.carbon.security.SecurityComponentException;
 import org.wso2.carbon.security.SecurityConfigAdmin;
 import org.wso2.carbon.security.SecurityScenario;
 import org.wso2.carbon.security.SecurityScenarioDatabase;
-import org.wso2.carbon.usergroup.UserGroupAdmin;
-import org.wso2.registry.Registry;
-import org.wso2.registry.exceptions.RegistryException;
 
 public class SecurityConfigAdminServiceImpl implements SecurityConfigAdminInterface{
     

Modified: trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/java/org/wso2/carbon/security/util/ServicePasswordCallbackHandler.java
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/java/org/wso2/carbon/security/util/ServicePasswordCallbackHandler.java?rev=19114&r1=19113&r2=19114&view=diff
==============================================================================
--- trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/java/org/wso2/carbon/security/util/ServicePasswordCallbackHandler.java	(original)
+++ trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/java/org/wso2/carbon/security/util/ServicePasswordCallbackHandler.java	Thu Jul 10 21:20:07 2008
@@ -17,6 +17,7 @@
 package org.wso2.carbon.security.util;
 
 import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.security.KeyStore;
 import java.util.ArrayList;
@@ -39,6 +40,7 @@
 import org.wso2.carbon.keystore.KeyStoreUtil;
 import org.wso2.carbon.keystore.service.KeyStoreData;
 import org.wso2.carbon.secmgt.SecurityMgmtConstants;
+import org.wso2.carbon.security.SecurityConfigException;
 import org.wso2.carbon.utils.security.CryptoUtil;
 import org.wso2.registry.Association;
 import org.wso2.registry.Collection;
@@ -61,7 +63,7 @@
     
     
     public ServicePasswordCallbackHandler(String serviceId, String[] usergroups, 
-                                Registry registry) throws Exception {
+                                Registry registry) throws SecurityConfigException {
         this.serviceId = serviceId;
         if(usergroups != null){
             loadDataMaps(usergroups, registry);
@@ -128,33 +130,38 @@
         }
     }
 
-    public void loadDataMaps(String[] usergroups, Registry registry) throws RegistryException,
-            Exception {
-        for (int i = 0; i < usergroups.length; i++) {
-            
-            String userGroup = usergroups[i];
-            String path = SecurityMgmtConstants.USER_GROUPS+"/"+userGroup;
-            Resource resource = registry.get(path);
-            String userString= resource.getProperty(SecurityMgmtConstants.PROP_USERS);
-            userString = userString.substring(1, userString.length()-1);
-            String[] users = userString.split(",");
-
-            List<String> userList = new ArrayList<String>();
-            for (String user : users) {
-                userList.add(user);
-            }
+    public void loadDataMaps(String[] usergroups, Registry registry) throws SecurityConfigException{
+        try {
+            for (int i = 0; i < usergroups.length; i++) {
+                
+                String userGroup = usergroups[i];
+                String path = SecurityMgmtConstants.USER_GROUPS+"/"+userGroup;
+                Resource resource = registry.get(path);
+                String userString= resource.getProperty(SecurityMgmtConstants.PROP_USERS);
+                userString = userString.substring(1, userString.length()-1);
+                String[] users = userString.split(",");
+
+                List<String> userList = new ArrayList<String>();
+                for (String user : users) {
+                    userList.add(user);
+                }
 
-            Association[] ass = registry.getAssociations(resource.getPath(),
-                    SecurityMgmtConstants.ASSOCIATION_STORE_GROUP);
+                Association[] ass = registry.getAssociations(resource.getPath(),
+                        SecurityMgmtConstants.ASSOCIATION_STORE_GROUP);
 
-            String storePath = ass[0].getDestinationPath();
-            Resource storeResource = registry.get(storePath);
+                String storePath = ass[0].getDestinationPath();
+                Resource storeResource = registry.get(storePath);
 
-            Authenticator auth = createAuthenticator(storeResource);
-            int index = storePath.lastIndexOf("/");
-            String key = storePath.substring(index + 1);
-            this.auths.put(key, auth);
-            this.users.put(key, userList);
+                Authenticator auth = createAuthenticator(storeResource);
+                int index = storePath.lastIndexOf("/");
+                String key = storePath.substring(index + 1);
+                this.auths.put(key, auth);
+                this.users.put(key, userList);
+            }
+        } catch (RegistryException e) {
+           log.error(e);
+           throw new SecurityConfigException("registryError", 
+                                       new String[]{"while creating ServicePasswordcallback"}, e);
         }
     }
 
@@ -179,26 +186,30 @@
     }
     
     
-    public Authenticator createAuthenticator(Resource userStore) throws Exception {
+    public Authenticator createAuthenticator(Resource userStore) throws SecurityConfigException{
 
-        String authClass = userStore.getProperty(SecurityMgmtConstants.PROP_AUTHENTICATOR_CLASS);
+        try {
+            String authClass = userStore.getProperty(SecurityMgmtConstants.PROP_AUTHENTICATOR_CLASS);
 
-        Class clazz = Class.forName(authClass);
-        Authenticator auth = (Authenticator) clazz.newInstance();
-        Properties props = userStore.getProperties();
-        Method[] meths = clazz.getMethods();
-
-        for (int i = 0; i < meths.length; i++) {
-            String name = meths[i].getName();
-            if (!name.startsWith("set")) {
-                continue;
+            Class clazz = Class.forName(authClass);
+            Authenticator auth = (Authenticator) clazz.newInstance();
+            Properties props = userStore.getProperties();
+            Method[] meths = clazz.getMethods();
+
+            for (int i = 0; i < meths.length; i++) {
+                String name = meths[i].getName();
+                if (!name.startsWith("set")) {
+                    continue;
+                }
+                String key = name.substring(3);
+                String value = (String) props.get(key);
+                meths[i].invoke(auth, new Object[] { value });
             }
-            String key = name.substring(3);
-            String value = (String) props.get(key);
-            meths[i].invoke(auth, new Object[] { value });
+            return auth;
+        } catch (Exception e) {
+           log.debug(e);
+           throw new SecurityConfigException("creatingAuthenticator", e);
         }
-        return auth;
-
     }
 
     private String getPrivateKeyPassword(String username) throws IOException {

Modified: trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/java/org/wso2/carbon/service/mgt/ServiceAdmin.java
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/java/org/wso2/carbon/service/mgt/ServiceAdmin.java?rev=19114&r1=19113&r2=19114&view=diff
==============================================================================
--- trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/java/org/wso2/carbon/service/mgt/ServiceAdmin.java	(original)
+++ trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/java/org/wso2/carbon/service/mgt/ServiceAdmin.java	Thu Jul 10 21:20:07 2008
@@ -7,7 +7,9 @@
 import java.util.Map;
 import java.util.Properties;
 
+import javax.xml.stream.FactoryConfigurationError;
 import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
 
 import org.apache.axis2.AxisFault;
@@ -16,15 +18,15 @@
 import org.apache.axis2.description.AxisModule;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.Parameter;
-import org.apache.axis2.description.PolicyInclude;
 import org.apache.axis2.description.PolicySubject;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.neethi.Policy;
-import org.wso2.carbon.core.CarbonConstants;
 import org.wso2.carbon.core.RegistryResources;
 import org.wso2.carbon.secmgt.SecurityMgmtConstants;
 import org.wso2.carbon.security.SecurityConstants;
+import org.wso2.carbon.security.util.RahasUtil;
 import org.wso2.carbon.security.util.ServerCrypto;
+import org.wso2.carbon.utils.ServerException;
 import org.wso2.carbon.utils.WSO2Constants;
 import org.wso2.registry.Association;
 import org.wso2.registry.Collection;
@@ -32,10 +34,6 @@
 import org.wso2.registry.Resource;
 import org.wso2.registry.exceptions.RegistryException;
 
-import org.wso2.carbon.security.util.RahasUtil;
-
-import com.sun.jmx.defaults.ServiceName;
-
 public class ServiceAdmin {
 
     private Registry registry = null;
@@ -59,53 +57,67 @@
      * @throws Exception
      */
     public void addPoliciesToService(AxisService axisService, Policy policy, int policyType,
-            String[] modulePaths) throws Exception {
+            String[] modulePaths) throws ServerException {
 
-        // at registry
-        Resource policyResource = registry.newResource();
-        policyResource.setProperty(RegistryResources.ServiceProperties.POLICY_TYPE, String
-                .valueOf(policyType));
-        policyResource.setProperty(RegistryResources.ServiceProperties.POLICY_UUID, policy.getId());
-        // do a performance improvement
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(baos);
-        policy.serialize(writer);
-        writer.flush();
-        policyResource.setContent((String) baos.toString());
+        try {
+            // at registry
+            Resource policyResource = registry.newResource();
+            policyResource.setProperty(RegistryResources.ServiceProperties.POLICY_TYPE, String
+                    .valueOf(policyType));
+            policyResource.setProperty(RegistryResources.ServiceProperties.POLICY_UUID, policy.getId());
+            // do a performance improvement
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(baos);
+            policy.serialize(writer);
+            writer.flush();
+            policyResource.setContent((String) baos.toString());
+
+            String servicePath = RegistryResources.SERVICE_GROUPS
+                    + axisService.getAxisServiceGroup().getServiceGroupName()
+                    + RegistryResources.SERVICES + axisService.getName();
+            String policyResourcePath = servicePath + RegistryResources.POLICIES + policy.getId();
 
-        String servicePath = RegistryResources.SERVICE_GROUPS
-                + axisService.getAxisServiceGroup().getServiceGroupName()
-                + RegistryResources.SERVICES + axisService.getName();
-        String policyResourcePath = servicePath + RegistryResources.POLICIES + policy.getId();
+            System.out.println("Adding " + policyResourcePath);
+            registry.put(policyResourcePath, policyResource);
 
-        System.out.println("Adding " + policyResourcePath);
-        registry.put(policyResourcePath, policyResource);
+            // at axis2
+      Map endPointMap = axisService.getEndpoints();
+            Iterator ite = endPointMap.entrySet().iterator();
+            while (ite.hasNext()) {
+                Map.Entry entry = (Map.Entry) ite.next();
+                AxisEndpoint point = (AxisEndpoint) entry.getValue();
+                AxisBinding binding = point.getBinding();
+                binding.applyPolicy(policy);
+            }
+            
+            // handle each module required
+            for (String path : modulePaths) {
+                registry.addAssociation(policyResourcePath, path,
+                        RegistryResources.Associations.REQUIRED_MODULES);
+                String[] values = path.split("/");
+                String moduleName = values[values.length - 2];
+                String moduleVersion = values[values.length - 1];
 
-        // at axis2
-       Map endPointMap = axisService.getEndpoints();
-        Iterator ite = endPointMap.entrySet().iterator();
-        while (ite.hasNext()) {
-            Map.Entry entry = (Map.Entry) ite.next();
-            AxisEndpoint point = (AxisEndpoint) entry.getValue();
-            AxisBinding binding = point.getBinding();
-            binding.applyPolicy(policy);
-        }
-        
-        // handle each module required
-        for (String path : modulePaths) {
-            registry.addAssociation(policyResourcePath, path,
-                    RegistryResources.Associations.REQUIRED_MODULES);
-            String[] values = path.split("/");
-            String moduleName = values[values.length - 2];
-            String moduleVersion = values[values.length - 1];
-
-            // engage at axis2
-            AxisModule module = axisService.getAxisConfiguration().getModule(moduleName);
-            axisService.disengageModule(module);
-            axisService.engageModule(module);
-            if (moduleName.equalsIgnoreCase("rahas")){
-                setRahasParameters(axisService);
+                // engage at axis2
+                AxisModule module = axisService.getAxisConfiguration().getModule(moduleName);
+                axisService.disengageModule(module);
+                axisService.engageModule(module);
+                if (moduleName.equalsIgnoreCase("rahas")){
+                    setRahasParameters(axisService);
+                }
             }
+        } catch (AxisFault e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (RegistryException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (XMLStreamException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (FactoryConfigurationError e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
         }
 
     }

Modified: trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/resources/org/wso2/carbon/security/errors.properties
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/resources/org/wso2/carbon/security/errors.properties?rev=19114&r1=19113&r2=19114&view=diff
==============================================================================
--- trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/resources/org/wso2/carbon/security/errors.properties	(original)
+++ trunk/carbon-components/security/org.wso2.carbon.modules.security/src/main/resources/org/wso2/carbon/security/errors.properties	Thu Jul 10 21:20:07 2008
@@ -1,9 +1,14 @@
 errorApplyingPolicy = Error applying policy
 missingResource = Missing resource in registry : {0}
-registryError = Registry error
+registryError = Unexpected registry error. {0}
 errorDisengagingModules = Error disengaging modules - service : {0}, scenario : {1}
 errorRemovingServicePolicies = Error removing service policies of service : {0}
 errorSettingupSecurityPolicyAssertionBuilders = Error setting up security policy assertion builders
 initializationError=Error initializing the org.wso2.carbon.security component
 registryNotAvailable = WSO2 Registry is not available
-nullService = Please provide a valid service
\ No newline at end of file
+nullService = Please provide a valid service
+transportSwitch = Error while enable/disable transport
+loadingPolicy = Error loading policy
+creatingAuthenticator = Error creating authenticator
+removingPolicy = Error removing policy
+configuringService = Error configuring Axis Service : {0}



More information about the Carbon-dev mailing list