jiapeng 8 years ago
parent
commit
caaa966b08

+ 73 - 0
src/main/java/com/ekexiu/console/servlet/AuthCssServlet.java

@ -0,0 +1,73 @@
1
package com.ekexiu.console.servlet;
2

3
import java.io.IOException;
4
import java.io.OutputStream;
5

6
import javax.servlet.ServletException;
7
import javax.servlet.http.HttpServlet;
8
import javax.servlet.http.HttpServletRequest;
9
import javax.servlet.http.HttpServletResponse;
10

11
import org.jfw.util.ConstData;
12
import org.jfw.util.auth.AuthUtil;
13
import org.jfw.util.context.JfwAppContext;
14

15
import com.ekexiu.console.system.po.SysRight;
16
import com.ekexiu.console.system.service.RightService;
17
import com.ekexiu.console.system.vo.ConsoleAuthUser;
18

19
public class AuthCssServlet extends HttpServlet {
20

21
	private static final long serialVersionUID = -2443799398873114107L;
22

23
	private static final int[] EMPTY_RIGHT = new int[] {};
24

25
	private RightService rightService;
26

27
	@Override
28
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
29
		StringBuilder sb = new StringBuilder();
30
		int[] rights = EMPTY_RIGHT;
31
		ConsoleAuthUser cau = (ConsoleAuthUser) req.getSession().getAttribute(org.jfw.util.auth.AuthUser.LOGIN_USER_FLAG_IN_SESSION);
32
		if (cau != null) {
33
			rights = AuthUtil.unCompress(cau.getAuths());
34
		}
35
		sb.append("@charset \"UTF-8\";").append("\n");
36
		for (SysRight r : this.rightService.query()) {
37
			boolean found = false;
38
			for (int rc : rights) {
39
				if (rc == r.getId()) {
40
					found = true;
41
					break;
42
				}
43
			}
44
			if (!found) {
45
				sb.append("auth-").append(r.getId()).append(",");
46
			}
47
		}
48

49
		sb.append("auth-FFFFFFF{display:none;}");
50

51
		byte[] bs = sb.toString().getBytes(ConstData.UTF8);
52
		resp.setDateHeader("Expires", 0);
53
		resp.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
54
		resp.addHeader("Cache-Control", "post-check=0, pre-check=0");
55
		resp.setHeader("Pragma", "no-cache");
56
		resp.setContentType("text/css");
57
		resp.setContentLength(bs.length);
58
		OutputStream os = resp.getOutputStream();
59
		try {
60
			os.write(bs);
61
			os.flush();
62
		} finally {
63
			os.close();
64
		}
65
	}
66

67
	@Override
68
	public void init() throws ServletException {
69
		super.init();
70
		this.rightService = JfwAppContext.getBeanFactory().getBean("com_ekexiu_console_system_service_RightService", RightService.class);
71
	}
72

73
}

+ 1 - 1
src/main/java/com/ekexiu/console/system/service/RightService.java

@ -43,7 +43,7 @@ public class RightService {
43 43

44 44
	@Get
45 45
	@Path("/all")
46
	public Collection<SysRight> query() throws SQLException {
46
	public Collection<SysRight> query()  {
47 47
		return this.rights.get().values();
48 48
	}
49 49


+ 0 - 56
src/main/java/com/ekexiu/console/system/service/TestService.java

@ -1,56 +0,0 @@
1
package com.ekexiu.console.system.service;
2

3
import java.sql.Connection;
4
import java.sql.PreparedStatement;
5
import java.sql.ResultSet;
6
import java.sql.SQLException;
7
import java.util.ArrayList;
8
import java.util.List;
9

10
import javax.sql.DataSource;
11

12
import org.jfw.apt.annotation.Autowrie;
13
import org.jfw.apt.web.annotation.Path;
14
import org.jfw.apt.web.annotation.operate.Get;
15

16
@Path("/test")
17
public class TestService {
18

19
	@Autowrie("dataSource2")
20
	private DataSource ds;
21

22
	public DataSource getDs() {
23
		return ds;
24
	}
25

26
	public void setDs(DataSource ds) {
27
		this.ds = ds;
28
	}
29

30
	@Get
31
	@Path
32
	public Object get() throws SQLException {
33
		Connection con = ds.getConnection();
34
		try {
35

36
			PreparedStatement ps = con.prepareStatement("SELECT ARTICLE_TITLE FROM ARTICLE");
37
			try {
38
				ResultSet rs = ps.executeQuery();
39
				try {
40
					List<String> list = new ArrayList<String>();
41
					while (rs.next()) {
42
						list.add(rs.getString(1));
43
					}
44
					return list;
45
				} finally {
46
					rs.close();
47
				}
48
			} finally {
49
				ps.close();
50
			}
51

52
		} finally {
53
			con.close();
54
		}
55
	}
56
}

+ 28 - 11
src/main/java/com/ekexiu/console/system/service/UserService.java

@ -17,6 +17,7 @@ import org.jfw.apt.web.annotation.operate.Post;
17 17
import org.jfw.apt.web.annotation.operate.Put;
18 18
import org.jfw.apt.web.annotation.param.FieldParam;
19 19
import org.jfw.apt.web.annotation.param.JdbcConn;
20
import org.jfw.apt.web.annotation.param.PathVar;
20 21
import org.jfw.apt.web.annotation.param.RequestBody;
21 22
import org.jfw.apt.web.annotation.param.RequestParam;
22 23
import org.jfw.util.PageQueryResult;
@ -34,15 +35,14 @@ import com.ekexiu.console.system.vo.ConsoleAuthUser;
34 35

35 36
@Path("/sys/user")
36 37
public class UserService extends Upload {
37
	public static final String DEFAULT_AUTH_STR=AuthUtil.serialAuth(new int[]{0});
38
	public static final String DEFAULT_PW_STR=StringUtil.md5("12345678");
38
	public static final String DEFAULT_AUTH_STR = AuthUtil.serialAuth(new int[] { 0 });
39
	public static final String DEFAULT_PW_STR = StringUtil.md5("12345678");
39 40

40 41
	@Autowrie
41 42
	private UserDao userDao;
42 43
	@Autowrie
43 44
	RoleDao roleDao;
44 45

45

46 46
	public RoleDao getRoleDao() {
47 47
		return roleDao;
48 48
	}
@ -81,9 +81,10 @@ public class UserService extends Upload {
81 81
		}
82 82
		return null;
83 83
	}
84

84 85
	@Get
85 86
	@Path
86
	public ConsoleAuthUser get(@LoginUser ConsoleAuthUser user){
87
	public ConsoleAuthUser get(@LoginUser ConsoleAuthUser user) {
87 88
		return user;
88 89
	}
89 90

@ -121,7 +122,7 @@ public class UserService extends Upload {
121 122
					@FieldParam(value = "email", valueClass = String.class, required = true),
122 123
					@FieldParam(value = "mobile", valueClass = String.class, required = false),
123 124
					@FieldParam(value = "descp", valueClass = String.class, required = false),
124
					@FieldParam(value="head",valueClass=String.class,required=false)}) User user)
125
					@FieldParam(value = "head", valueClass = String.class, required = false) }) User user)
125 126
			throws SQLException {
126 127
		String id = StringUtil.buildUUID();
127 128
		user.setId(id);
@ -130,28 +131,44 @@ public class UserService extends Upload {
130 131
		user.setLoginPassword(DEFAULT_PW_STR);
131 132
		this.userDao.insert(con, user);
132 133
	}
134

133 135
	@Put
134 136
	@Path
135
	public void update(@JdbcConn(true) Connection con,@RequestBody User user)throws SQLException{
137
	public void update(@JdbcConn(true) Connection con, @RequestBody User user) throws SQLException {
136 138
		user.setLoginPassword(null);
137 139
		this.userDao.update(con, user);
138 140
	}
139
	
141

140 142
	@Get
141 143
	@Path("/info")
142
	public User editInfo(@JdbcConn Connection con,@LoginUser ConsoleAuthUser cau)throws SQLException{
144
	public User editInfo(@JdbcConn Connection con, @LoginUser ConsoleAuthUser cau) throws SQLException {
143 145
		User user = this.userDao.queryById(con, cau.getId());
144
		if(user!=null){
146
		if (user != null) {
145 147
			user.setLoginPassword(null);
146 148
		}
147 149
		return user;
148 150
	}
151

149 152
	@Post
150 153
	@Path("/resetpw")
151
	public void resetpw(@JdbcConn(true) Connection con,String[] ids)throws SQLException{
152
		this.userDao.resetPassword(con, ids,DEFAULT_PW_STR);
154
	public void resetpw(@JdbcConn(true) Connection con, String[] ids) throws SQLException {
155
		this.userDao.resetPassword(con, ids, DEFAULT_PW_STR);
153 156
	}
154 157

158
	@Get
159
	@Path("/right/{id}")
160
	public int[] getRights(@JdbcConn Connection con, @PathVar String id) throws SQLException {
161
		User user = this.userDao.queryById(con, id);
162
		if (user != null) {
163
			return AuthUtil.unCompress(AuthUtil.deSerialAuth(user.getAuthinfo()));
164
		}
165
		return null;
166
	}
167
	@Post
168
	@Path("/right")
169
	public void updateRights(@JdbcConn(true) Connection con, String userid,int[] right)throws SQLException{
170
		this.userDao.update(con, userid, AuthUtil.serialAuth(AuthUtil.compress(right)));
171
	}
155 172

156 173
	@Post
157 174
	@Path("/head")

+ 9 - 0
src/main/webapp/WEB-INF/web.xml

@ -21,10 +21,19 @@
21 21
    </init-param>
22 22
    <load-on-startup>1</load-on-startup>
23 23
  </servlet>
24
  <servlet>
25
  		<servlet-name>authcss</servlet-name>
26
  		<servlet-class>com.ekexiu.console.servlet.AuthCssServlet</servlet-class>
27
  		<load-on-startup>2</load-on-startup>
28
  </servlet>
24 29
  
25 30
  <servlet-mapping>
26 31
    <servlet-name>ajax</servlet-name>
27 32
    <url-pattern>/ajax/*</url-pattern>
28 33
  </servlet-mapping>
34
  <servlet-mapping>
35
  		<servlet-name>authcss</servlet-name>
36
  		<url-pattern>/ajax/dyn/auth.css</url-pattern>
37
  </servlet-mapping>
29 38
 
30 39
</web-app>