();
67 |
68 | for (String role : roles) {
69 | authorities.add(new SimpleGrantedAuthority(role));
70 | }
71 | return authorities;
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/src/main/java/com/sprsec/service/RoleService.java:
--------------------------------------------------------------------------------
1 | package com.sprsec.service;
2 |
3 | import com.sprsec.model.Role;
4 |
5 | public interface RoleService {
6 |
7 | public Role getRole(int id);
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/com/sprsec/service/RoleServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.sprsec.service;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.stereotype.Service;
5 | import org.springframework.transaction.annotation.Transactional;
6 |
7 | import com.sprsec.dao.RoleDAO;
8 | import com.sprsec.model.Role;
9 |
10 | @Service
11 | @Transactional
12 | public class RoleServiceImpl implements RoleService {
13 |
14 | @Autowired
15 | private RoleDAO roleDAO;
16 |
17 | public Role getRole(int id) {
18 | return roleDAO.getRole(id);
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/com/sprsec/service/UserService.java:
--------------------------------------------------------------------------------
1 | package com.sprsec.service;
2 |
3 | import com.sprsec.model.User;
4 |
5 | public interface UserService {
6 |
7 | public User getUser(String login);
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/com/sprsec/service/UserServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.sprsec.service;
2 |
3 | import org.springframework.transaction.annotation.Transactional;
4 |
5 |
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.stereotype.Service;
8 |
9 | import com.sprsec.dao.UserDAO;
10 | import com.sprsec.model.User;
11 |
12 | @Service
13 | @Transactional
14 | public class UserServiceImpl implements UserService {
15 |
16 | @Autowired
17 | private UserDAO userDAO;
18 |
19 | public User getUser(String login) {
20 | return userDAO.getUser(login);
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | #DB properties:
2 | db.driver=com.mysql.jdbc.Driver
3 | db.url=jdbc:mysql://localhost:3306/hibnatedb
4 | db.username=hibuser
5 | db.password=root
6 |
7 | #Hibernate Configuration:
8 | hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
9 | hibernate.show_sql=true
10 | entitymanager.packages.to.scan=com.sprsec.model
--------------------------------------------------------------------------------
/src/main/webapp/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Built-By: Fruzenshtein
3 | Build-Jdk: 1.7.0_09
4 | Created-By: Maven Integration for Eclipse
5 |
6 |
--------------------------------------------------------------------------------
/src/main/webapp/META-INF/maven/com/security-spr/pom.properties:
--------------------------------------------------------------------------------
1 | #Generated by Maven Integration for Eclipse
2 | #Tue Apr 30 17:02:56 EEST 2013
3 | version=0.0.1-SNAPSHOT
4 | groupId=com
5 | m2e.projectName=security-spr
6 | m2e.projectLocation=E\:\\spring_progs\\security-spr
7 | artifactId=security-spr
8 |
--------------------------------------------------------------------------------
/src/main/webapp/META-INF/maven/com/security-spr/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | com
5 | security-spr
6 |
7 | war
8 | 0.0.1-SNAPSHOT
9 |
10 | security-spr Maven Webapp
11 |
12 |
13 | 4.1.7.Final
14 | 5.1.21
15 | 1.6.6
16 | 3.1.3.RELEASE
17 | UTF-8
18 |
19 |
20 |
21 |
22 |
23 | org.hibernate
24 | hibernate-core
25 | ${hibernate.version}
26 |
27 |
28 | org.hibernate
29 | hibernate-entitymanager
30 | ${hibernate.version}
31 |
32 |
33 |
34 | mysql
35 | mysql-connector-java
36 | ${mysql.connector.version}
37 |
38 |
39 | commons-dbcp
40 | commons-dbcp
41 | 1.4
42 |
43 |
44 | javassist
45 | javassist
46 | 3.12.1.GA
47 |
48 |
49 |
50 |
51 | org.springframework
52 | spring-webmvc
53 | ${spring.version}
54 |
55 |
56 | org.springframework
57 | spring-tx
58 | ${spring.version}
59 |
60 |
61 | org.springframework
62 | spring-jdbc
63 | ${spring.version}
64 |
65 |
66 | org.springframework
67 | spring-orm
68 | ${spring.version}
69 |
70 |
71 |
72 | cglib
73 | cglib
74 | 2.2.2
75 |
76 |
77 |
78 | org.springframework.security
79 | spring-security-core
80 | ${spring.version}
81 |
82 |
83 | org.springframework.security
84 | spring-security-web
85 | ${spring.version}
86 |
87 |
88 | org.springframework.security
89 | spring-security-config
90 | ${spring.version}
91 |
92 |
93 |
94 | javax.servlet
95 | javax.servlet-api
96 | 3.0.1
97 | provided
98 |
99 |
100 | jstl
101 | jstl
102 | 1.2
103 |
104 |
105 |
106 |
107 | junit
108 | junit
109 | 4.7
110 | test
111 |
112 |
113 |
114 |
115 | security-spr
116 |
117 |
118 |
119 |
--------------------------------------------------------------------------------
/src/main/webapp/WEB-INF/pages/admin-first.jsp:
--------------------------------------------------------------------------------
1 |
2 |
3 | <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
4 |
5 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
6 | pageEncoding="ISO-8859-1"%>
7 |
8 |
9 |
10 |
11 | First Admin page
12 |
13 |
14 | First Admin page
15 |
16 | " >Logout
17 | Home page
18 |
19 |
20 |
--------------------------------------------------------------------------------
/src/main/webapp/WEB-INF/pages/admin-second.jsp:
--------------------------------------------------------------------------------
1 |
2 |
3 | <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
4 |
5 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
6 | pageEncoding="ISO-8859-1"%>
7 |
8 |
9 |
10 |
11 | Second Admin page
12 |
13 |
14 | Second Admin page
15 |
16 | " >Logout
17 | Home page
18 |
19 |
20 |
--------------------------------------------------------------------------------
/src/main/webapp/WEB-INF/pages/home.jsp:
--------------------------------------------------------------------------------
1 |
2 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
3 | pageEncoding="ISO-8859-1"%>
4 |
5 |
6 |
7 |
8 | Home page
9 |
10 |
11 | Home page
12 | This is Home page. It's available for all users.
13 | Moderation page
14 | First Admin page
15 | Second Admin page
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/main/webapp/WEB-INF/pages/login-form.jsp:
--------------------------------------------------------------------------------
1 |
2 |
3 | <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
4 |
5 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
6 | pageEncoding="ISO-8859-1"%>
7 |
8 |
9 |
10 |
11 |
12 | Login page
13 |
18 |
19 |
20 | Login page
21 |
22 |
23 |
24 | Invalid login or password.
25 |
26 |
27 |
28 |
46 |
47 |
48 | Home page
49 |
50 |
51 |
--------------------------------------------------------------------------------
/src/main/webapp/WEB-INF/pages/moderation.jsp:
--------------------------------------------------------------------------------
1 |
2 |
3 | <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
4 |
5 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
6 | pageEncoding="ISO-8859-1"%>
7 |
8 |
9 |
10 |
11 | Moderation page
12 |
13 |
14 | Moderation page
15 | This is Moderation page. It's available for moderators.
16 | " >Logout
17 | Home page
18 |
19 |
--------------------------------------------------------------------------------
/src/main/webapp/WEB-INF/pages/success-login.jsp:
--------------------------------------------------------------------------------
1 |
2 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
3 | pageEncoding="ISO-8859-1"%>
4 |
5 |
6 |
7 |
8 | Welcome page
9 |
10 |
11 | Welcome page
12 | You have successfully logged in.
13 | Home page
14 |
15 |
--------------------------------------------------------------------------------
/src/main/webapp/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------