← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8646: WIp automatic login

 

------------------------------------------------------------
revno: 8646
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-10-22 20:02:46 +0200
message:
  WIp automatic login
modified:
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AccountController.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java	2012-10-22 16:28:40 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java	2012-10-22 18:02:46 +0000
@@ -113,8 +113,6 @@
         {
             return false;
         }
-        System.out.println("digit " + DIGIT_PATTERN.matcher( password ).matches());
-        System.out.println("upper " + UPPERCASE_PATTERN.matcher( password ).matches());
         
         return DIGIT_PATTERN.matcher( password ).matches() && UPPERCASE_PATTERN.matcher( password ).matches();
     }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AccountController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AccountController.java	2012-10-22 16:28:40 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AccountController.java	2012-10-22 18:02:46 +0000
@@ -39,6 +39,11 @@
 import org.hisp.dhis.user.UserCredentials;
 import org.hisp.dhis.user.UserService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.authentication.AuthenticationManager;
+import org.springframework.security.authentication.BadCredentialsException;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.stereotype.Controller;
 import org.springframework.util.LinkedMultiValueMap;
 import org.springframework.util.MultiValueMap;
@@ -70,6 +75,9 @@
     @Autowired
     private UserService userService;
     
+    @Autowired
+    private AuthenticationManager authenticationManager;
+    
     @RequestMapping( method = RequestMethod.POST, produces = ContextUtils.CONTENT_TYPE_TEXT )
     public @ResponseBody String createAccount( 
         @RequestParam String username,
@@ -238,4 +246,18 @@
         
         return result != null ? result.split( SPLIT ) : null;
     }
+    
+    @SuppressWarnings("unused")
+    private void authenticate( User user )
+    {
+        String uname = user.getUserCredentials().getUsername();
+        String passwd = user.getUserCredentials().getPassword();
+        
+        UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken( uname, passwd );
+        token.setDetails( user );
+        
+        Authentication auth = authenticationManager.authenticate( token );
+        
+        SecurityContextHolder.getContext().setAuthentication( auth );
+    }
 }