Permalink
Browse files

First half of separating the "local accounts" stuff from the "LDAP ac…

…counts" stuff
  • Loading branch information...
mindcrime committed Dec 30, 2010
1 parent b60aa6c commit 10eac6ce607136826c596a5aab3feb7f6fa86e66
Showing with 1,010 additions and 488 deletions.
  1. +2 −0 .classpath
  2. +4 −0 grails-app/conf/Config.groovy
  3. +35 −0 grails-app/conf/spring/resources.groovy
  4. +1 −1 grails-app/controllers/org/fogbeam/quoddy/HomeController.groovy
  5. +4 −1 grails-app/controllers/org/fogbeam/quoddy/InstallerController.groovy
  6. +14 −43 grails-app/controllers/org/fogbeam/quoddy/LoginController.groovy
  7. +62 −7 grails-app/controllers/org/fogbeam/quoddy/SearchController.groovy
  8. +22 −3 grails-app/controllers/org/fogbeam/quoddy/UserController.groovy
  9. +7 −0 grails-app/domain/org/fogbeam/quoddy/LocalAccount.groovy
  10. +3 −2 grails-app/domain/org/fogbeam/quoddy/User.groovy
  11. +32 −0 grails-app/listeners/org/fogbeam/quoddy/listeners/QuoddySessionListener.groovy
  12. +328 −0 grails-app/services/org/fogbeam/quoddy/LdapFriendService.groovy
  13. +7 −0 grails-app/services/org/fogbeam/quoddy/LdapGroupService.groovy
  14. +206 −0 grails-app/services/org/fogbeam/quoddy/LdapPersonService.groovy
  15. +65 −0 grails-app/services/org/fogbeam/quoddy/LocalAccountService.groovy
  16. +6 −0 grails-app/services/org/fogbeam/quoddy/LocalFriendService.groovy
  17. +6 −0 grails-app/services/org/fogbeam/quoddy/LocalGroupService.groovy
  18. +88 −0 grails-app/services/org/fogbeam/quoddy/LoginService.groovy
  19. +2 −2 grails-app/services/org/fogbeam/quoddy/{LDAPPersonService.groovy → ProfileService.groovy}
  20. +50 −416 grails-app/services/org/fogbeam/quoddy/UserService.groovy
  21. +5 −2 grails-app/views/_sidebar.gsp
  22. +3 −1 grails-app/views/search/friendSearchResults.gsp
  23. +3 −1 grails-app/views/search/iFollowSearchResults.gsp
  24. +4 −5 grails-app/views/search/index.gsp
  25. +24 −0 grails-app/views/search/peopleSearchResults.gsp
  26. +4 −1 grails-app/views/search/searchFriends.gsp
  27. +5 −2 grails-app/views/search/searchIFollow.gsp
  28. +17 −0 grails-app/views/search/searchPeople.gsp
  29. +1 −1 grails-app/views/search/showAdvanced.gsp
  30. 0 quoddyConfig.properties
View
@@ -7,6 +7,8 @@
<classpathentry kind="src" path="grails-app/services"/>
<classpathentry kind="src" path="grails-app/ldap"/>
<classpathentry kind="src" path="grails-app/shindig"/>
+ <classpathentry kind="src" path="grails-app/src"/>
+ <classpathentry kind="src" path="grails-app/listeners"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry exported="true" kind="con" path="GROOVY_SUPPORT"/>
<classpathentry kind="con" path="com.springsource.sts.grails.core.CLASSPATH_CONTAINER"/>
@@ -31,6 +31,10 @@ else
println "No external configuration file defined."
}
+friends.backingStore="ldap";
+groups.backingStore="ldap";
+enable.self.registration=true;
+
grails.project.groupId = appName // change this to alter the default package name and Maven publishing destination
grails.mime.file.extensions = true // enables the parsing of file extensions from URLs into the request format
@@ -1,5 +1,6 @@
import org.springframework.ldap.core.support.LdapContextSource;
import org.springframework.ldap.core.LdapTemplate;
+import org.codehaus.groovy.grails.commons.ConfigurationHolder as CH;
// Place your Spring DSL code here
beans = {
@@ -12,5 +13,39 @@ beans = {
}
ldapTemplate(org.springframework.ldap.core.LdapTemplate, ref("contextSource"))
+
+ switch( CH.config.friends.backingStore )
+ {
+ case "ldap":
+ friendService(org.fogbeam.quoddy.LdapFriendService) {
+ ldapTemplate = ref("ldapTemplate")
+ }
+ break;
+
+ case "localdb":
+ friendService(org.fogbeam.quoddy.LocalFriendService)
+ break;
+
+ default:
+ // ???
+ break;
+ }
+
+ switch( CH.config.groups.backingStore )
+ {
+ case "ldap":
+ groupService(org.fogbeam.quoddy.LdapGroupService){
+ ldapTemplate = ref("ldapTemplate")
+ }
+ break;
+
+ case "localdb":
+ groupService(org.fogbeam.quoddy.LocalGroupService)
+ break;
+
+ default:
+ // ???
+ break;
+ }
}
@@ -19,7 +19,7 @@ class HomeController {
if( session.user != null )
{
user = userService.findUserByUserId( session.user.userId );
- activities = activityStreamService.getRecentFriendActivitiesForUser( user );
+ // activities = activityStreamService.getRecentFriendActivitiesForUser( user );
}
}
@@ -2,5 +2,8 @@ package org.fogbeam.quoddy;
public class InstallerController
{
-
+ def index =
+ {
+ []
+ }
}
@@ -16,7 +16,7 @@ import sun.misc.BASE64Encoder;
class LoginController {
- def userService;
+ def loginService;
def index = { }
@@ -27,36 +27,23 @@ class LoginController {
User user = null;
- try {
+
- user = userService.findUserByUserId( userId );
- }
- catch( NameNotFoundException e )
- {
- e.printStackTrace();
- }
+ // do login through login service, which might ultimately be authenticating
+ // against an LDAP backend, a local DB backend, or something else.
+ // NOTE: if we want to allow flexibility in configuring authentication
+ // backends, using JAAS or whatever, how do we manage acquiring the
+ // proper credentials when we don't know all the steps in the auth
+ // process in advance? We'd need to hand in a Handler that can return
+ // results to the browser (kinda ugly) or get a list of required
+ // credentials in advance, drive the user through any multi-step stuff
+ // then submit the credentials.
- boolean loginSucceeded = false;
+ user = loginService.doUserLogin( userId, password );
+
+
if( user )
{
- println "found user: ${userId} in LDAP";
- String md5HashSubmitted = LoginController.digestMd5( password );
- println "md5HashSubmitted: ${md5HashSubmitted}";
- if( md5HashSubmitted.equals( user.password ))
- {
- loginSucceeded = true;
- }
- else
- {
- println "login failed on password match. "
- }
- }
- else
- {
- }
-
- if( loginSucceeded )
- {
session.user = user;
redirect( controller:'home', action:'index')
}
@@ -71,20 +58,4 @@ class LoginController {
session.user = null;
redirect( uri:'/');
}
-
- private static String digestMd5(final String password)
- {
- String base64;
- try
- {
- MessageDigest digest = MessageDigest.getInstance("MD5");
- digest.update(password.getBytes());
- base64 = new BASE64Encoder().encode(digest.digest());
- }
- catch (NoSuchAlgorithmException e) {
- throw new RuntimeException(e);
- }
-
- return "{MD5}" + base64;
- }
}
@@ -20,12 +20,16 @@ import org.apache.lucene.store.NIOFSDirectory
import org.apache.lucene.util.Version
import org.fogbeam.quoddy.User;
-class SearchController {
+class SearchController
+{
def userService;
- def index = {
-
+ def index =
+ {
+ println "WTF?";
+
+ []
}
@@ -34,7 +38,8 @@ class SearchController {
[]
}
- def searchUsers = {
+ def searchUsers =
+ {
// search users using supplied parameters and return the
// model for rendering...
@@ -68,11 +73,54 @@ class SearchController {
render( view:'userSearchResults', model:[allUsers:users]);
}
- def searchIFollow = {
+ def searchIFollow =
+ {
+
+ }
+
+ def doPeopleSearch =
+ {
+
+ // search users using supplied parameters and return the
+ // model for rendering...
+ String queryString = params.queryString;
+ println "searching People, queryString: ${queryString}";
+
+
+ File indexDir = new File( "/development/lucene_indexes/quoddy/person_index" );
+ Directory fsDir = FSDirectory.open( indexDir );
+
+ IndexSearcher searcher = new IndexSearcher( fsDir );
+
+ BooleanQuery outerQuery = new BooleanQuery();
+
+ QueryParser queryParser = new QueryParser(Version.LUCENE_30, "fullName", new StandardAnalyzer(Version.LUCENE_30));
+ Query userQuery = queryParser.parse(queryString);
+
+ TopDocs hits = searcher.search( userQuery, 20);
+
+ def users = new ArrayList<User>();
+ ScoreDoc[] docs = hits.scoreDocs;
+ for( ScoreDoc doc : docs )
+ {
+ Document result = searcher.doc( doc.doc );
+ String userId = result.get("userId")
+ println( userId + " " + result.get("fullName"));
+
+ users.add( userService.findUserByUserId(userId));
+
+ }
+
+ println "found some users: ${users.size()}";
+
+
+ println "done"
+ render( view:'peopleSearchResults', model:[allUsers:users]);
}
- def doIFollowSearch = {
+ def doIFollowSearch =
+ {
println "Searching IFollow";
@@ -141,7 +189,11 @@ class SearchController {
def searchFriends = {
}
+
+ def searchPeople = {
+ }
+
def doFriendSearch = {
println "Searching Friends";
@@ -212,7 +264,7 @@ class SearchController {
// build the search index using Lucene
List<User> users = userService.findAllUsers();
-
+ println "reindexing ${users.size()} users";
Directory indexDir = new NIOFSDirectory( new java.io.File( "/development/lucene_indexes/quoddy/person_index" ) );
IndexWriter writer = new IndexWriter( indexDir, new StandardAnalyzer(Version.LUCENE_30), true, MaxFieldLength.LIMITED);
writer.setUseCompoundFile(false);
@@ -254,5 +306,8 @@ class SearchController {
writer.optimize();
writer.close();
+ println "done";
+ render( "<html><head><title>Index Rebuilt</head><body><h1>Index Rebuilt</h1></body></html>" );
+
}
}
@@ -1,5 +1,7 @@
package org.fogbeam.quoddy
+import org.codehaus.groovy.grails.commons.ConfigurationHolder as CH;
+
class UserController {
def userService;
@@ -27,10 +29,16 @@ class UserController {
def registerUser =
{ UserRegistrationCommand urc ->
+ if( CH.config.enable.self.registration != true )
+ {
+ redirect( controller:'home', action:'index')
+ return;
+ }
+
if( urc.hasErrors() )
{
flash.user = urc;
- redirect( action:"register2" );
+ redirect( action:"create" );
}
else
{
@@ -175,9 +183,20 @@ class UserController {
}
def create =
- {
+ {
+ println "enable self reg? "
+ println CH.config.enable.self.registration;
- []
+ if( CH.config.enable.self.registration != true )
+ {
+ println "self registration is disabled";
+ // if self registration isn't turned on, just bounce to the front-page here
+ redirect( controller:'home', action:'index')
+ }
+ else
+ {
+ render(view:'create' );
+ }
}
def list =
@@ -5,5 +5,12 @@ public class LocalAccount
// we'll just need username/password for now. And a uuid or whatever
// hangs it all together.
+ public LocalAccount()
+ {
+ this.uuid = java.util.UUID.randomUUID().toString();
+ }
+ String uuid;
+ String username;
+ String password;
}
@@ -17,7 +17,8 @@ class User {
}
profile( nullable: true )
currentStatus(nullable:true)
- dateCreated()
+ email(nullable:true)
+ dateCreated()
}
@@ -37,7 +38,7 @@ class User {
// String fullName;
String bio;
String email;
- static transients = [ "password", "homepage", "firstName", "lastName", "displayName", "bio", "email", "fullName" ]
+ static transients = [ "password", "homepage", "displayName", "bio" ]
static mapping = {
@@ -0,0 +1,32 @@
+package org.fogbeam.quoddy.listeners
+
+import javax.servlet.http.HttpSession
+import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionListener;
+import org.codehaus.groovy.grails.commons.ConfigurationHolder as CH;
+
+class QuoddySessionListener implements HttpSessionListener
+{
+ public void sessionCreated( HttpSessionEvent event )
+ {
+ println "sessionCreated, putting config options in session";
+
+ HttpSession newSession = event.getSession();
+ def enableSelfReg = CH.config.enable.self.registration;
+
+ if( enableSelfReg )
+ {
+ newSession.setAttribute( "enable_self_registration", true );
+ }
+ else
+ {
+ newSession.setAttribute( "enable_self_registration", false );
+ }
+ }
+
+ public void sessionDestroyed(HttpSessionEvent arg0)
+ {
+ //
+ }
+
+}
Oops, something went wrong.

0 comments on commit 10eac6c

Please sign in to comment.