Author: vkumar
Date: Fri Sep 26 06:17:51 2008
New Revision: 699308

URL: http://svn.apache.org/viewvc?rev=699308&view=rev
Log:
Adding new assembly file and interface for Bean post processor

Added:
    
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/JetspeedBeanPostProcessor.java
   (with props)
    
portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedBeanInitializer.java
   (with props)
    
portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-portal-resources/src/main/resources/assembly/intializer.xml
   (with props)
Modified:
    
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/LdapAuthenticationProvider.java
    
portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-portal-resources/src/main/resources/assembly/security-ldap.xml
    portals/jetspeed-2/portal/branches/security-refactoring/pom.xml

Added: 
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/JetspeedBeanPostProcessor.java
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/JetspeedBeanPostProcessor.java?rev=699308&view=auto
==============================================================================
--- 
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/JetspeedBeanPostProcessor.java
 (added)
+++ 
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/JetspeedBeanPostProcessor.java
 Fri Sep 26 06:17:51 2008
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.security;
+
+import java.util.List;
+
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationEvent;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ContextRefreshedEvent;
+
+/**
+ * @author <a href="mailto:[EMAIL PROTECTED]">Vivek Kumar</a>
+ * @version $Id:
+ */
+public class JetspeedBeanPostProcessor implements ApplicationListener
+{
+    private ApplicationContext context;
+    private List<String> beanList = null;
+
+    /**
+     * @param beanList
+     */
+    public JetspeedBeanPostProcessor(List<String> beanList)
+    {
+        this.beanList = beanList;
+    }
+
+    public void onApplicationEvent(ApplicationEvent appEvent)
+    {
+        if (appEvent instanceof ContextRefreshedEvent)
+        {
+            ContextRefreshedEvent event = (ContextRefreshedEvent) appEvent;
+            this.context = event.getApplicationContext();
+            processBeans();
+        }
+    }
+
+    private void processBeans()
+    {
+        if (beanList != null)
+        {
+            JetspeedBeanInitializer intializer = null;
+            for (String bean : beanList)
+            {
+                try
+                {
+                    intializer = (JetspeedBeanInitializer) 
context.getBean(bean);
+                    intializer.intialize();
+                }
+                catch (Exception e)
+                {
+                    // Log error messages
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
+}

Propchange: 
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/JetspeedBeanPostProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/JetspeedBeanPostProcessor.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: 
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/LdapAuthenticationProvider.java
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/LdapAuthenticationProvider.java?rev=699308&r1=699307&r2=699308&view=diff
==============================================================================
--- 
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/LdapAuthenticationProvider.java
 (original)
+++ 
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/LdapAuthenticationProvider.java
 Fri Sep 26 06:17:51 2008
@@ -18,6 +18,7 @@
 
 import java.util.Hashtable;
 
+import javax.naming.AuthenticationException;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingEnumeration;
@@ -47,6 +48,7 @@
     private UserPasswordCredentialManager upcm;
     private UserManager manager;
     private LdapContextProxy context;
+
     public LdapAuthenticationProvider(String providerName, String 
providerDescription, String loginConfig, UserPasswordCredentialManager upcm,
                                       UserManager manager)
     {
@@ -59,6 +61,7 @@
     {
         this.context = context;
     }
+
     public void setSynchronizer(JetspeedSecuritySynchronizer synchronizer)
     {
         this.synchronizer = synchronizer;
@@ -70,39 +73,54 @@
         boolean authenticated = false;
         try
         {
-            authenticated = authenticateUser(userName, password);            
+            if (userName == null)
+            {
+                throw new 
SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.USER,userName));
+            }
+            if (password == null)
+            {
+                throw new 
SecurityException(SecurityException.PASSWORD_REQUIRED);
+            }
+
+            authenticated = authenticateUser(userName, password);
             if (authenticated)
             {
                 User user = getUser(userName);
                 authUser = new AuthenticatedUserImpl(user, new 
UserCredentialImpl(upcm.getPasswordCredential(user)));
             }
         }
-        catch (Exception e)
+        catch (SecurityException authEx)
         {
-            throw new 
SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.USER,
 userName), e);
+           if(authEx.getCause().getMessage().equalsIgnoreCase("[LDAP: error 
code 49 - Invalid Credentials]"))
+            {
+               throw new 
SecurityException(SecurityException.INCORRECT_PASSWORD);
+            }else{
+                throw authEx;
+            }
         }
         return authUser;
     }
 
     private User getUser(String userName) throws SecurityException
     {
-        if(synchronizer!=null)
+        if (synchronizer != null)
         {
             synchronizer.synchronizeUserPrincipal(userName);
-        }        
+        }
         return manager.getUser(userName);
     }
 
-    private boolean authenticateUser(String userName, String password) throws 
NamingException, SecurityException
+    private boolean authenticateUser(String userName, String password) throws 
SecurityException
     {
-        Hashtable env = context.getCtx().getEnvironment();
-
-        // String savedPassword = String.valueOf(getPassword(uid));
-        String oldCredential = (String) env.get(Context.SECURITY_CREDENTIALS);
-        String oldUsername = (String) env.get(Context.SECURITY_PRINCIPAL);
-        String dn = lookupByUid(userName);
         try
         {
+            Hashtable env = context.getCtx().getEnvironment();
+            
+            // String savedPassword = String.valueOf(getPassword(uid));
+            String oldCredential = (String) 
env.get(Context.SECURITY_CREDENTIALS);
+            String oldUsername = (String) env.get(Context.SECURITY_PRINCIPAL);
+            String dn = lookupByUid(userName);
+            
             if (dn == null)
             {
                 throw new 
SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.USER,
 userName));
@@ -119,17 +137,19 @@
             env.put(Context.SECURITY_CREDENTIALS, oldCredential);
             return true;
         }
-        catch (Exception e)
+        catch (AuthenticationException aex)
         {
-            e.printStackTrace();
-            // TODO: handle exception
+            throw new SecurityException(aex);
+
+        }
+        catch (NamingException nex)
+        {
+            throw new 
SecurityException(SecurityException.UNEXPECTED.createScoped("in logining 
in",JetspeedPrincipalType.USER,userName));
         }
-        return false;
     }
 
     public String lookupByUid(final String uid) throws SecurityException
     {
-        validateUid(uid);
         try
         {
             SearchControls cons = setSearchControls();
@@ -141,20 +161,10 @@
             throw new SecurityException(e);
         }
     }
-
-    protected void validateUid(String uid) throws SecurityException
-    {
-        String pattern = 
".*\\(.*|.*\\[.*|.*\\{.*|.*\\\\.*|.*\\^.*|.*\\$.*|.*\\|.*|.*\\).*|.*\\?.*|.*\\*.*|.*\\+.*|.*\\..*";
-        if (StringUtils.isEmpty(uid) || uid.matches(pattern))
-        {
-            throw new SecurityException(SecurityException.INVALID_UID);
-        }
-    }
-
     protected SearchControls setSearchControls()
     {
         SearchControls controls = new SearchControls();
-        controls.setReturningAttributes(new String[]{});
+        controls.setReturningAttributes(new String[] {});
         controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
         controls.setReturningObjFlag(true);
         return controls;
@@ -198,16 +208,16 @@
 
     private String getSearchSuffix()
     {
-        return  context.getUserFilter();
+        return context.getUserFilter();
     }
 
     private String getEntryPrefix()
     {
-        return  "cn";
+        return "cn";
     }
 
     private String getSearchDomain()
     {
-       return "";
+        return "";
     }
 }

Added: 
portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedBeanInitializer.java
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedBeanInitializer.java?rev=699308&view=auto
==============================================================================
--- 
portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedBeanInitializer.java
 (added)
+++ 
portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedBeanInitializer.java
 Fri Sep 26 06:17:51 2008
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.security;
+
+/** 
+ * @author <a href="mailto:[EMAIL PROTECTED]">Vivek Kumar</a>
+ * @version $Id:
+ */
+public interface JetspeedBeanInitializer
+{
+    void intialize();
+}

Propchange: 
portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedBeanInitializer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedBeanInitializer.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: 
portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-portal-resources/src/main/resources/assembly/intializer.xml
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-portal-resources/src/main/resources/assembly/intializer.xml?rev=699308&view=auto
==============================================================================
--- 
portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-portal-resources/src/main/resources/assembly/intializer.xml
 (added)
+++ 
portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-portal-resources/src/main/resources/assembly/intializer.xml
 Fri Sep 26 06:17:51 2008
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+       <!--
+               Licensed to the Apache Software Foundation (ASF) under one or 
more
+               contributor license agreements. See the NOTICE file distributed 
with
+               this work for additional information regarding copyright 
ownership.
+               The ASF licenses this file to You under the Apache License, 
Version
+               2.0 (the "License"); you may not use this file except in 
compliance
+               with the License. You may obtain a copy of the License at
+               http://www.apache.org/licenses/LICENSE-2.0 Unless required by
+               applicable law or agreed to in writing, software distributed 
under the
+               License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES 
OR
+               CONDITIONS OF ANY KIND, either express or implied. See the 
License for
+               the specific language governing permissions and limitations 
under the
+               License.
+       -->
+<beans xmlns="http://www.springframework.org/schema/beans";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd";>
+       <bean id="JetspeedBeanPostProcessor" 
class="org.apache.jetspeed.security.JetspeedBeanPostProcessor">
+               <meta key="j2:cat" value="ldap" />
+               <constructor-arg index="0">
+                       <list>
+                               
<value>org.apache.jetspeed.security.spi.JetspeedPostContextLoader</value>
+                       </list>
+               </constructor-arg>
+       </bean>
+</beans>
\ No newline at end of file

Propchange: 
portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-portal-resources/src/main/resources/assembly/intializer.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-portal-resources/src/main/resources/assembly/intializer.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: 
portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-portal-resources/src/main/resources/assembly/security-ldap.xml
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-portal-resources/src/main/resources/assembly/security-ldap.xml?rev=699308&r1=699307&r2=699308&view=diff
==============================================================================
--- 
portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-portal-resources/src/main/resources/assembly/security-ldap.xml
 (original)
+++ 
portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-portal-resources/src/main/resources/assembly/security-ldap.xml
 Fri Sep 26 06:17:51 2008
@@ -48,7 +48,7 @@
     <constructor-arg index="3" 
ref="org.apache.jetspeed.security.spi.UserPasswordCredentialManager" />
     <constructor-arg index="4" ref="org.apache.jetspeed.security.UserManager" 
/>
     <property name="context" ref="ldapContext" />
-    <property name="synchronizer" ref="JetspeedPrincipalSynchronizer" />
+    <property name="synchronizer" 
ref="org.apache.jetspeed.security.spi.JetspeedSecuritySynchronizer" />
   </bean>
 
   <bean id="org.apache.jetspeed.security.mapping.SecurityEntityManager"

Modified: portals/jetspeed-2/portal/branches/security-refactoring/pom.xml
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/pom.xml?rev=699308&r1=699307&r2=699308&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/pom.xml (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/pom.xml Fri Sep 26 
06:17:51 2008
@@ -180,7 +180,7 @@
       <name>Vivek Kumar</name>
       <id>vkumar</id>
       <email>[EMAIL PROTECTED]</email>
-      <timezone>+5:30</timezone>
+      <timezone>+5.5</timezone>
       <organization>Bluesunrise</organization>
       <organizationUrl>http://www.bluesunrise.com</organizationUrl>
       <roles>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to