dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #19643
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8659: Minor
------------------------------------------------------------
revno: 8659
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-10-23 13:27:59 +0200
message:
Minor
modified:
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/notification/Notification.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/notification/Notification.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/notification/Notification.java 2012-09-26 08:46:31 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/notification/Notification.java 2012-10-23 11:27:59 +0000
@@ -29,15 +29,13 @@
import java.util.Date;
+import org.hisp.dhis.common.CodeGenerator;
+import org.hisp.dhis.common.Dxf2Namespace;
+import org.hisp.dhis.scheduling.TaskCategory;
+
import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
-import org.hisp.dhis.common.CodeGenerator;
-import org.hisp.dhis.common.Dxf2Namespace;
-import org.hisp.dhis.common.view.DetailedView;
-import org.hisp.dhis.common.view.ExportView;
-import org.hisp.dhis.scheduling.TaskCategory;
/**
* @author Lars Helge Overland
=== 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-23 10:51:10 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AccountController.java 2012-10-23 11:27:59 +0000
@@ -27,6 +27,9 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.Collection;
+import java.util.HashSet;
+
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -44,6 +47,8 @@
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.util.LinkedMultiValueMap;
@@ -227,7 +232,7 @@
log.info( "Created user successfully with username: " + username );
- authenticate( user );
+ authenticate( user, userRole );
response.setStatus( HttpServletResponse.SC_CREATED );
return "Account created";
@@ -264,16 +269,28 @@
return result != null ? result.split( SPLIT ) : null;
}
- private void authenticate( User user )
+ private void authenticate( User user, UserAuthorityGroup userRole )
{
String uname = user.getUserCredentials().getUsername();
String passwd = user.getUserCredentials().getPassword();
- UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken( uname, passwd );
- token.setDetails( user );
+ UsernamePasswordAuthenticationToken token =
+ new UsernamePasswordAuthenticationToken( uname, passwd, getAuthorities( userRole ) );
Authentication auth = authenticationManager.authenticate( token );
SecurityContextHolder.getContext().setAuthentication( auth );
}
+
+ private Collection<GrantedAuthority> getAuthorities( UserAuthorityGroup userRole )
+ {
+ Collection<GrantedAuthority> auths = new HashSet<GrantedAuthority>();
+
+ for ( String auth : userRole.getAuthorities() )
+ {
+ auths.add( new SimpleGrantedAuthority( auth ) );
+ }
+
+ return auths;
+ }
}