File tree Expand file tree Collapse file tree 12 files changed +79
-35
lines changed
webapp/WEB-INF/spring/appServlet Expand file tree Collapse file tree 12 files changed +79
-35
lines changed Original file line number Diff line number Diff line change 56
56
<artifactId >joda-time-hibernate</artifactId >
57
57
<version >1.4</version >
58
58
</dependency >
59
+ <dependency >
60
+ <groupId >com.google.guava</groupId >
61
+ <artifactId >guava</artifactId >
62
+ <version >19.0</version >
63
+ </dependency >
59
64
<!-- SMTP -->
60
65
<dependency >
61
66
<groupId >com.sun.mail</groupId >
120
125
<artifactId >spring-security-web</artifactId >
121
126
<version >4.2.1.RELEASE</version >
122
127
</dependency >
128
+ <dependency >
129
+ <groupId >org.springframework.security</groupId >
130
+ <artifactId >spring-security-taglibs</artifactId >
131
+ <version >4.2.1.RELEASE</version >
132
+ </dependency >
123
133
<dependency >
124
134
<groupId >org.springframework.security</groupId >
125
135
<artifactId >spring-security-test</artifactId >
Original file line number Diff line number Diff line change 1
1
package ru .mrchebik .service ;
2
2
3
+ import org .springframework .security .access .prepost .PreAuthorize ;
3
4
import ru .mrchebik .model .Category ;
4
5
5
6
import java .util .List ;
8
9
* Created by mrchebik on 14.01.17.
9
10
*/
10
11
public interface CategoryService {
12
+ @ PreAuthorize ("hasRole('ROLE_USER')" )
11
13
void add (Category category );
14
+
15
+ @ PreAuthorize ("hasRole('ROLE_USER')" )
12
16
void edit (String name , long categoryId );
17
+
18
+ @ PreAuthorize ("hasRole('ROLE_USER')" )
13
19
Category findById (long id );
20
+
21
+ @ PreAuthorize ("hasRole('ROLE_USER')" )
14
22
Category findByParentIdThroughCategoryId (long parentId , long userId );
23
+
24
+ @ PreAuthorize ("hasRole('ROLE_USER')" )
15
25
List <Category > findByParentId (long parentId , long userId );
26
+
27
+ @ PreAuthorize ("hasRole('ROLE_USER')" )
16
28
List <Category > findAll (long userId );
17
- long findMaxLevel (long userId );
29
+
30
+ @ PreAuthorize ("hasRole('ROLE_USER')" )
18
31
void remove (long id );
19
32
}
Original file line number Diff line number Diff line change 1
1
package ru .mrchebik .service ;
2
2
3
+ import org .springframework .security .access .prepost .PreAuthorize ;
3
4
import ru .mrchebik .model .Comment ;
4
5
5
6
import java .util .List ;
8
9
* Created by mrchebik on 14.01.17.
9
10
*/
10
11
public interface CommentService {
12
+ @ PreAuthorize ("hasRole('ROLE_USER')" )
11
13
Comment addComment (Comment comment );
14
+
15
+ @ PreAuthorize ("hasRole('ROLE_USER')" )
12
16
void editComment (Comment comment );
17
+
18
+ @ PreAuthorize ("hasRole('ROLE_USER')" )
13
19
Comment findComment (long id );
20
+
21
+ @ PreAuthorize ("hasRole('ROLE_USER')" )
14
22
List <Comment > findComments (long id );
23
+
24
+ @ PreAuthorize ("hasRole('ROLE_USER')" )
15
25
void removeComment (long id );
16
26
}
Original file line number Diff line number Diff line change 1
1
package ru .mrchebik .service ;
2
2
3
+ import org .springframework .security .access .prepost .PreAuthorize ;
3
4
import ru .mrchebik .model .Post ;
4
5
5
6
import java .util .List ;
8
9
* Created by mrchebik on 14.01.17.
9
10
*/
10
11
public interface PostService {
12
+ @ PreAuthorize ("hasRole('ROLE_USER')" )
11
13
Post add (Post post );
14
+
15
+ @ PreAuthorize ("hasRole('ROLE_USER')" )
12
16
long findLastPostId (long userId );
17
+
18
+ @ PreAuthorize ("hasRole('ROLE_USER')" )
13
19
List <Post > findPosts (long userId );
20
+
21
+ @ PreAuthorize ("hasRole('ROLE_USER')" )
14
22
Post findPost (long postId );
23
+
24
+ @ PreAuthorize ("hasRole('ROLE_USER')" )
15
25
void remove (long id );
16
26
}
Original file line number Diff line number Diff line change 1
1
package ru .mrchebik .service ;
2
2
3
+ import org .springframework .security .access .prepost .PreAuthorize ;
3
4
import ru .mrchebik .model .Reader ;
4
5
5
6
import java .util .List ;
8
9
* Created by mrchebik on 03.02.17.
9
10
*/
10
11
public interface ReaderService {
12
+ @ PreAuthorize ("hasRole('ROLE_USER')" )
11
13
void add (Reader reader );
14
+
15
+ @ PreAuthorize ("hasRole('ROLE_USER')" )
12
16
Reader findOne (long userIdMain , long userIdFollower );
17
+
18
+ @ PreAuthorize ("hasRole('ROLE_USER')" )
13
19
List <Reader > findAllMain (long userIdMain );
20
+
21
+ @ PreAuthorize ("hasRole('ROLE_USER')" )
14
22
List <Reader > findAllFollower (long userIdMain );
23
+
24
+ @ PreAuthorize ("hasRole('ROLE_USER')" )
15
25
void delete (long id );
16
26
}
Original file line number Diff line number Diff line change 4
4
* Created by mrchebik on 15.01.17.
5
5
*/
6
6
public interface SecurityService {
7
- String findLoggedInUsername ();
8
7
void autologin (final String username , final String password );
9
8
}
Original file line number Diff line number Diff line change 1
1
package ru .mrchebik .service ;
2
2
3
+ import org .springframework .security .access .prepost .PreAuthorize ;
3
4
import ru .mrchebik .model .User ;
4
5
5
- import java .util .List ;
6
-
7
6
/**
8
7
* Created by mrchebik on 14.01.17.
9
8
*/
10
9
public interface UserService {
11
10
User add (User user );
11
+
12
+ @ PreAuthorize ("hasRole('ROLE_USER')" )
12
13
void changeUsername (String email , String username );
14
+
15
+ @ PreAuthorize ("hasRole('ROLE_USER')" )
13
16
void changePassword (String email , String password );
17
+
18
+ @ PreAuthorize ("hasRole('ROLE_USER')" )
14
19
void changeEmail (String email , String newEmail );
20
+
21
+ @ PreAuthorize ("hasRole('ROLE_USER')" )
15
22
User findOne (long userId );
23
+
24
+ @ PreAuthorize ("hasRole('ROLE_USER')" )
16
25
User findByEmail (String email );
26
+
27
+ @ PreAuthorize ("hasRole('ROLE_USER')" )
17
28
User findByUsername (String username );
18
- List <User > findUsers ();
29
+
30
+ @ PreAuthorize ("hasRole('ROLE_USER')" )
19
31
void remove (long id );
20
32
}
Original file line number Diff line number Diff line change @@ -50,11 +50,6 @@ public List<Category> findAll(long userId) {
50
50
return categoryRepository .findAll (userId );
51
51
}
52
52
53
- @ Override
54
- public long findMaxLevel (long userId ) {
55
- return (long ) categoryRepository .findMaxLevel (userId );
56
- }
57
-
58
53
@ Override
59
54
public void remove (long id ) {
60
55
categoryRepository .delete (id );
Original file line number Diff line number Diff line change 4
4
import org .springframework .security .authentication .UsernamePasswordAuthenticationToken ;
5
5
import org .springframework .security .core .Authentication ;
6
6
import org .springframework .security .core .context .SecurityContextHolder ;
7
- import org .springframework .security .core .userdetails .UserDetails ;
8
7
import org .springframework .stereotype .Service ;
9
8
import ru .mrchebik .service .SecurityService ;
10
9
@@ -18,16 +17,6 @@ public class SecurityServiceImpl implements SecurityService {
18
17
@ Resource
19
18
private AuthenticationManager authenticationManager ;
20
19
21
- @ Override
22
- public String findLoggedInUsername () {
23
- Object userDetails = SecurityContextHolder .getContext ().getAuthentication ().getDetails ();
24
- if (userDetails instanceof UserDetails ) {
25
- return ((UserDetails )userDetails ).getUsername ();
26
- }
27
-
28
- return null ;
29
- }
30
-
31
20
@ Override
32
21
public void autologin (final String username , final String password ) {
33
22
UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = new UsernamePasswordAuthenticationToken (username , password );
Original file line number Diff line number Diff line change 1
1
package ru .mrchebik .service .impl ;
2
2
3
- import org . springframework . security . access . prepost . PreAuthorize ;
3
+ import com . google . common . collect . Sets ;
4
4
import org .springframework .security .crypto .bcrypt .BCryptPasswordEncoder ;
5
5
import org .springframework .stereotype .Repository ;
6
6
import org .springframework .stereotype .Service ;
11
11
import ru .mrchebik .service .UserService ;
12
12
13
13
import javax .annotation .Resource ;
14
- import java .util .HashSet ;
15
- import java .util .List ;
16
14
17
15
/**
18
16
* Created by mrchebik on 14.01.17.
@@ -31,7 +29,7 @@ public class UserServiceImpl implements UserService {
31
29
@ Override
32
30
public User add (User user ) {
33
31
user .setPassword (bCryptPasswordEncoder .encode (user .getPassword ()));
34
- user .setRoles (new HashSet <> (roleRepository .findAll ( )));
32
+ user .setRoles (Sets . newHashSet (roleRepository .findOne ( 1L )));
35
33
return userRepository .saveAndFlush (user );
36
34
}
37
35
@@ -68,12 +66,6 @@ public User findByEmail(String email) {
68
66
}
69
67
70
68
@ Override
71
- public List <User > findUsers () {
72
- return userRepository .findAll ();
73
- }
74
-
75
- @ Override
76
- @ PreAuthorize ("hasRole('ROLE_ADMIN')" )
77
69
public void remove (long id ) {
78
70
userRepository .delete (id );
79
71
}
You can’t perform that action at this time.
0 commit comments