Skip to content

Commit 48a2dc8

Browse files
author
eugenp
committed
cleanup work
1 parent fcc0dee commit 48a2dc8

3 files changed

Lines changed: 12 additions & 30 deletions

File tree

‎src/main/java/org/rest/sec/dto/User.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ public class User implements IEntity{
3333
public User(){
3434
super();
3535
}
36-
public User( final String nameToSet, final String passwordToSet ){
36+
public User( final String nameToSet, final String passwordToSet, final Set< Role > rolesToSet ){
3737
super();
3838

3939
name = nameToSet;
4040
password = passwordToSet;
41+
roles = rolesToSet;
4142
}
4243
public User( final Principal principal ){
4344
super();
Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
package org.rest.sec.web.controller;
22

3-
import java.util.Collection;
4-
53
import org.rest.sec.dto.User;
6-
import org.rest.sec.model.Privilege;
4+
import org.rest.sec.model.Role;
75
import org.springframework.http.HttpStatus;
86
import org.springframework.security.core.Authentication;
9-
import org.springframework.security.core.GrantedAuthority;
107
import org.springframework.security.core.context.SecurityContextHolder;
118
import org.springframework.stereotype.Controller;
129
import org.springframework.web.bind.annotation.RequestMapping;
1310
import org.springframework.web.bind.annotation.RequestMethod;
1411
import org.springframework.web.bind.annotation.ResponseBody;
1512
import org.springframework.web.bind.annotation.ResponseStatus;
1613

17-
import com.google.common.base.Function;
18-
import com.google.common.collect.Collections2;
14+
import com.google.common.collect.Sets;
1915

2016
/**
2117
* - note: this controller will start working with the User model and, if necessary, will move to a Authentication resource (which is the way it should work)
@@ -29,25 +25,16 @@ public AuthenticationController(){
2925

3026
// API
3127

32-
@RequestMapping( value = "authentication",method = RequestMethod.GET )
33-
@ResponseStatus( HttpStatus.CREATED )
28+
@RequestMapping( method = RequestMethod.POST,value = "/authentication" )
29+
@ResponseStatus( value = HttpStatus.CREATED )
3430
@ResponseBody
35-
public User getAuthentication(){
36-
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
37-
38-
final User authenticationResource = new User( authentication.getName(), null );
31+
public User createAuthentication(){
32+
final Authentication authenticationInSpring = SecurityContextHolder.getContext().getAuthentication();
3933

40-
final Function< GrantedAuthority, Privilege > springAuthorityToPrivilegeFunction = new Function< GrantedAuthority, Privilege >(){
41-
@Override
42-
public final Privilege apply( final GrantedAuthority springAuthority ){
43-
return new Privilege( springAuthority.getAuthority() );
44-
}
45-
};
46-
final Collection< Privilege > auths = Collections2.transform( authentication.getAuthorities(), springAuthorityToPrivilegeFunction );
47-
// TODO: implement this
48-
// authenticationResource.setRoles( Sets.<Role> newHashSet( auths ) );
34+
// - note: no need to publish the roles at this point
4935

36+
final User authenticationResource = new User( authenticationInSpring.getName(), (String) authenticationInSpring.getCredentials(), Sets.<Role> newHashSet() );
5037
return authenticationResource;
5138
}
52-
39+
5340
}

‎src/test/java/org/rest/sec/testing/template/UserRESTTemplateImpl.java‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public final String getURI(){
3737

3838
@Override
3939
public final User createNewEntity(){
40-
return this.createNewEntity( randomAlphabetic( 8 ), randomAlphabetic( 8 ) );
40+
return new User( randomAlphabetic( 8 ), randomAlphabetic( 8 ), Sets.<Role> newHashSet() );
4141
}
4242

4343
@Override
@@ -52,10 +52,4 @@ public final RequestSpecification givenAuthenticated(){
5252

5353
// util
5454

55-
public final User createNewEntity( final String username, final String password ){
56-
final User user = new User( username, password );
57-
user.setRoles( Sets.<Role> newHashSet() );
58-
return user;
59-
}
60-
6155
}

0 commit comments

Comments
 (0)