roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r541089 - in /roller/trunk: src/org/apache/roller/ui/core/security/RollerUserDetailsService.java web/WEB-INF/security.xml
Date Wed, 23 May 2007 21:17:06 GMT
Author: snoopdave
Date: Wed May 23 14:17:05 2007
New Revision: 541089

URL: http://svn.apache.org/viewvc?view=rev&rev=541089
Log:
Roller's own Acegi user details service, enables Acegi authentication to work regardless of
how Roller's database provider is configured. 

Added:
    roller/trunk/src/org/apache/roller/ui/core/security/RollerUserDetailsService.java
Modified:
    roller/trunk/web/WEB-INF/security.xml

Added: roller/trunk/src/org/apache/roller/ui/core/security/RollerUserDetailsService.java
URL: http://svn.apache.org/viewvc/roller/trunk/src/org/apache/roller/ui/core/security/RollerUserDetailsService.java?view=auto&rev=541089
==============================================================================
--- roller/trunk/src/org/apache/roller/ui/core/security/RollerUserDetailsService.java (added)
+++ roller/trunk/src/org/apache/roller/ui/core/security/RollerUserDetailsService.java Wed
May 23 14:17:05 2007
@@ -0,0 +1,52 @@
+package org.apache.roller.ui.core.security;
+
+import java.util.Iterator;
+import org.acegisecurity.GrantedAuthority;
+import org.acegisecurity.GrantedAuthorityImpl;
+import org.acegisecurity.userdetails.User;
+import org.acegisecurity.userdetails.UserDetails;
+import org.acegisecurity.userdetails.UserDetailsService;
+import org.acegisecurity.userdetails.UsernameNotFoundException;
+import org.apache.roller.RollerException;
+import org.apache.roller.business.Roller;
+import org.apache.roller.business.RollerFactory;
+import org.apache.roller.business.UserManager;
+import org.apache.roller.pojos.RoleData;
+import org.apache.roller.pojos.UserData;
+import org.springframework.dao.DataAccessException;
+import org.springframework.dao.DataRetrievalFailureException;
+
+/**
+ * Acegi user details service implemented using Roller API.
+ */
+public class RollerUserDetailsService implements UserDetailsService {
+
+    public UserDetails loadUserByUsername(String userName) 
+        throws UsernameNotFoundException, DataAccessException {
+        
+        UserData userData = null;
+        try {
+            Roller roller = RollerFactory.getRoller();
+            UserManager umgr = roller.getUserManager();
+            userData = umgr.getUserByUserName(userName, Boolean.TRUE); 
+        } catch (RollerException ex) {
+            throw new DataRetrievalFailureException("ERROR in user lookup", ex);
+        } 
+        
+        if (userData == null) {
+            throw new UsernameNotFoundException("ERROR no user: " + userName);
+        }
+        
+        GrantedAuthority[] authorities = 
+            new GrantedAuthorityImpl[userData.getRoles().size()];
+        int i = 0;
+        for (Iterator it = userData.getRoles().iterator(); it.hasNext();) {
+            RoleData role = (RoleData)it.next();
+            authorities[i++] = new GrantedAuthorityImpl(role.getRole());
+        }
+        
+        return new User(
+            userData.getUserName(), userData.getPassword(), true, authorities);
+    }
+    
+}

Modified: roller/trunk/web/WEB-INF/security.xml
URL: http://svn.apache.org/viewvc/roller/trunk/web/WEB-INF/security.xml?view=diff&rev=541089&r1=541088&r2=541089
==============================================================================
--- roller/trunk/web/WEB-INF/security.xml (original)
+++ roller/trunk/web/WEB-INF/security.xml Wed May 23 14:17:05 2007
@@ -132,20 +132,8 @@
          <property name="userCache" ref="userCache"/>
     </bean>
     
-    <!-- Read users from database -->
-    <bean id="jdbcAuthenticationDao" class="org.acegisecurity.userdetails.jdbc.JdbcDaoImpl">
-        <property name="dataSource">
-            <bean class="org.springframework.jndi.JndiObjectFactoryBean">
-                <property name="jndiName" value="java:comp/env/jdbc/rollerdb"/>
-            </bean>
-        </property>
-        <property name="usersByUsernameQuery">
-            <value>SELECT username,passphrase,isenabled FROM rolleruser WHERE username
= ?</value>
-        </property>
-        <property name="authoritiesByUsernameQuery">
-            <value>SELECT username,rolename FROM userrole WHERE username = ?</value>
-        </property>
-    </bean>
+    <!-- Read users from Roller API -->
+    <bean id="jdbcAuthenticationDao" class="org.apache.roller.ui.core.security.RollerUserDetailsService"/>
 
     <bean id="userCache" class="org.acegisecurity.providers.dao.cache.EhCacheBasedUserCache">
         <property name="cache">



Mime
View raw message