Skip to content

Commit

Permalink
session time out update
Browse files Browse the repository at this point in the history
  • Loading branch information
i0712326 committed Apr 26, 2015
1 parent 448a3e5 commit 1715201
Show file tree
Hide file tree
Showing 22 changed files with 198 additions and 130 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
package com.bcnx.web.app.exception;

import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

import org.jboss.resteasy.spi.ApplicationException;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import com.bcnx.web.app.service.entity.ErrMsg;

@Provider
public class ApplicationExceptionHandler implements
ExceptionMapper<ApplicationException> {
@Component
public class ApplicationExceptionHandler implements ExceptionMapper<Exception> {
private static final Logger logger = Logger.getLogger(ApplicationExceptionHandler.class);
@Produces("application/json")
@Override
public Response toResponse(ApplicationException ex) {
public Response toResponse(Exception ex) {
logger.debug("Exception occured while process request",ex);
logger.debug("Exception message :"+ex.getMessage());
ErrMsg errMsg = new ErrMsg();
errMsg.setCode("510");
errMsg.setMessage("Internal Message Error");
return Response.status(500).entity(errMsg).build();
return Response.serverError().entity(errMsg).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.bcnx.web.app.exception;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.apache.log4j.Logger;

import com.bcnx.web.app.service.UserService;
import com.bcnx.web.app.service.entity.User;

public class SessionTimeOutHandler implements HttpSessionListener {
private static Logger logger = Logger.getLogger(SessionTimeOutHandler.class);
private UserService userService;
public void setUserService(UserService userService){
this.userService = userService;
}
@Override
public void sessionCreated(HttpSessionEvent event) {
logger.debug("session is created");
return;
}

@Override
public void sessionDestroyed(HttpSessionEvent event) {
logger.debug("session is destroyed");
HttpSession session = event.getSession();
User user = (User) session.getAttribute("user");
user = userService.getUser(user);
user.setState(0);
userService.update(user);
return;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

public class UserServiceImp implements UserService {
private static final Logger logger = Logger.getLogger(UserServiceImp.class);
private static final String REGEX = "^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=])(?=\\S+$).{8,}$";
private UserDao userDao;
public void setUserDao(UserDao userDao){
this.userDao = userDao;
Expand Down Expand Up @@ -40,11 +41,10 @@ public void updatePasswd(User user) {
logger.debug("Exception occured while try to updat user",e);
}
}
private static final String REGEX = "^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=])(?=\\S+$).{8,}$";
private Pattern pattern = Pattern.compile(REGEX);
private Matcher matcher;
@Override
public boolean checkComplex(String passwd) {
public boolean checkComplex(final String passwd) {
matcher = pattern.matcher(passwd);
return matcher.find();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ public class MemberController {
@Path("/save")
@Produces("application/json")
@Consumes("application/json")
public Response save(Member member){
public Response save(Member member) throws Exception{
MemberService service = (MemberService) BcnxApplicationContext.getBean("memberService");
service.save(member);
return Response.status(200).entity(member).build();
}
@RolesAllowed("ADM")
@GET
@Path("/get/{first}/{max}")
public Response getMembes(@PathParam("first") String first, @PathParam("max") String max){
MemberService service = (MemberService) BcnxApplicationContext.getBean("memberService");
List<Member> members = service.getMembers(Integer.parseInt(first), Integer.parseInt(max));
public Response getMembes(@PathParam("first") int first,
@PathParam("max") int max) throws Exception {
MemberService service = (MemberService) BcnxApplicationContext
.getBean("memberService");
List<Member> members = service.getMembers(first, max);
return Response.status(200).entity(members).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import java.util.List;

import javax.annotation.security.RolesAllowed;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;

import com.bcnx.web.app.context.BcnxApplicationContext;
Expand All @@ -17,22 +15,26 @@

@Path("/role")
public class RoleController {
@RolesAllowed("ADM")
@POST
@Path("/save")
@Produces("application/json")
@Consumes("application/json")
public Response save(Role role){
RoleService service = (RoleService) BcnxApplicationContext.getBean("roleService");
public Response save(@QueryParam("roleId") String roleId,
@QueryParam("roleName") String roleName) throws Exception {
RoleService service = (RoleService) BcnxApplicationContext
.getBean("roleService");
Role role = new Role();
role.setRoleId(roleId);
role.setRoleName(roleName);
service.save(role);
return Response.status(200).entity(role).build();
}
@RolesAllowed("ADM")
@GET
@Path("/get/{first}/{max}")
public Response getRoles(@PathParam("first")String first, @PathParam("max")String max){
RoleService service = (RoleService) BcnxApplicationContext.getBean("roleService");
List<Role> roles = service.getRoles(Integer.parseInt(first), Integer.parseInt(max));
@Path("/get")
public Response getRoles(@QueryParam("first") int first,
@QueryParam("max") int max) throws Exception {
RoleService service = (RoleService) BcnxApplicationContext
.getBean("roleService");
List<Role> roles = service.getRoles(first, max);
return Response.status(200).entity(roles).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
Expand All @@ -10,6 +12,7 @@
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;

import com.bcnx.web.app.context.BcnxApplicationContext;
Expand All @@ -29,7 +32,8 @@ public class UserController {
@Path("/save")
public Response save(@FormParam("userId") String userId,
@FormParam("name") String name, @FormParam("email") String email,
@FormParam("memId") String memId, @FormParam("roleId") String roleId) {
@FormParam("memId") String memId, @FormParam("roleId") String roleId)
throws Exception {
UserService userService = (UserService) BcnxApplicationContext
.getBean("userService");
MemberService memberService = (MemberService) BcnxApplicationContext
Expand All @@ -50,7 +54,7 @@ public Response save(@FormParam("userId") String userId,
role.setRoleId(roleId);
role = roleService.getRole(role);
String passwd = PasswdGenerator.generate();
sendMailService.sendMail(user.getEmail(),passwd);
sendMailService.sendMail(user.getEmail(), passwd);
user.setPasswd(Encryptography.encrypt(passwd));
user.setMember(member);
user.setRole(role);
Expand All @@ -60,8 +64,10 @@ public Response save(@FormParam("userId") String userId,
@GET
@Path("/get")
@Produces("application/json")
public Response getUser(@QueryParam("userId") String userId){
UserService service = (UserService) BcnxApplicationContext.getBean("userService");
public Response getUser(@QueryParam("userId") String userId)
throws Exception {
UserService service = (UserService) BcnxApplicationContext
.getBean("userService");
User user = new User();
user.setUserId(userId);
user = service.getUser(user);
Expand All @@ -71,7 +77,7 @@ public Response getUser(@QueryParam("userId") String userId){
@Path("/get/{first}/{max}")
@Produces("application/json")
public Response getUsers(@PathParam("first") int first,
@PathParam("max") int max) {
@PathParam("max") int max) throws Exception {
UserService service = (UserService) BcnxApplicationContext
.getBean("userService");
List<User> users = service.getUsers(first,max);
Expand All @@ -81,12 +87,14 @@ public Response getUsers(@PathParam("first") int first,
@Path("/get/{userId}/{first}/{max}")
@Produces("application/json")
public Response getUsers(@PathParam("userId") String userId,
@PathParam("first") String first, @PathParam("max") String max) {
@PathParam("first") String first, @PathParam("max") String max)
throws Exception {
UserService service = (UserService) BcnxApplicationContext
.getBean("userService");
User user = new User();
user.setUserId(userId);
List<User> users = service.getUsers(user, Integer.parseInt(first), Integer.parseInt(max));
List<User> users = service.getUsers(user, Integer.parseInt(first),
Integer.parseInt(max));
return Response.status(200).entity(users).build();
}
@PUT
Expand All @@ -95,16 +103,19 @@ public Response getUsers(@PathParam("userId") String userId,
public Response updatePasswd(@FormParam("userId") String userId,
@FormParam("passwd") String passwd,
@FormParam("nPasswd") String nPasswd,
@FormParam("cPasswd") String cPasswd) {
UserService userService = (UserService) BcnxApplicationContext.getBean("userService");
@FormParam("cPasswd") String cPasswd) throws Exception {
UserService userService = (UserService) BcnxApplicationContext
.getBean("userService");
User user = new User();
user.setUserId(userId);
user = userService.getUser(user);
int count = user.getCount()+1;
int count = user.getCount() + 1;
user.setCount(count);
boolean check = Encryptography.checkPasswd(passwd, user.getPasswd());
if(!check){
return Response.status(401).entity(new ErrMsg("407","invalid current password")).build();
if (!check) {
return Response.status(401)
.entity(new ErrMsg("407", "invalid current password"))
.build();
}
check = userService.checkComplex(nPasswd);
if (!check)
Expand All @@ -130,51 +141,63 @@ public Response updatePasswd(@FormParam("userId") String userId,
@POST
@Path("/login")
@Produces("application/json")
public Response logon(@FormParam("userId") String userId, @FormParam("passwd") String passwd){
UserService service = (UserService) BcnxApplicationContext.getBean("userService");
public Response logon(@FormParam("userId") String userId,
@FormParam("passwd") String passwd, @Context HttpServletRequest request) throws Exception {
UserService service = (UserService) BcnxApplicationContext
.getBean("userService");
User user = new User();
user.setUserId(userId);
user = service.getUser(user);
boolean check = Encryptography.checkPasswd(passwd, user.getPasswd());
String status = user.getStatus();
int state = user.getState();
int count = user.getCount();

if(!check){
return Response.status(401).entity(new ErrMsg("400","invalid userId/password")).build();

if (!check) {
return Response.status(401)
.entity(new ErrMsg("400", "invalid userId/password"))
.build();
}
if(!status.equals("A"))
{
return Response.status(401).entity(new ErrMsg("401","inactive user")).build();
if (!status.equals("A")) {
return Response.status(401)
.entity(new ErrMsg("401", "inactive user")).build();
}
if(state!=0){
return Response.status(401).entity(new ErrMsg("402","current user is loggin in")).build();
if (state != 0) {
return Response.status(401)
.entity(new ErrMsg("402", "current user is loggin in"))
.build();
}
if(count ==0 ||(count%31 == 0)){
return Response.status(200).entity(new ErrMsg("403","required user change password")).build();
if (count == 0 || (count % 31 == 0)) {
return Response.status(200)
.entity(new ErrMsg("403", "required user change password"))
.build();
}
count = count+1;
count = count + 1;
user.setCount(count);
user.setState(1);
service.update(user);
return Response.ok(new ErrMsg("200","logging in successful")).build();
HttpSession session = request.getSession();
session.setAttribute("user", user);
return Response.ok(new ErrMsg("200", "logging in successful")).build();
}
@PUT
@Path("/active")
@Produces("application/json")
public Response getUpdateStatus(@FormParam("userId")String userId,@FormParam("status")String status){
UserService service = (UserService) BcnxApplicationContext.getBean("userService");
public Response getUpdateStatus(@FormParam("userId") String userId,
@FormParam("status") String status) throws Exception {
UserService service = (UserService) BcnxApplicationContext
.getBean("userService");
User user = new User();
user.setUserId(userId);
user = service.getUser(user);
user.setStatus(status);
service.update(user);
return Response.ok(new ErrMsg("200","active user successful")).build();
return Response.ok(new ErrMsg("200", "active user successful")).build();
}
@PUT
@Path("/logout")
@Produces("application/json")
public Response logout(@FormParam("userId")String userId){
public Response logout(@FormParam("userId")String userId) throws Exception{
UserService service = (UserService) BcnxApplicationContext.getBean("userService");
User user = new User();
user.setUserId(userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;

import org.jboss.resteasy.spi.ApplicationException;

import com.bcnx.web.app.context.BcnxApplicationContext;
import com.bcnx.web.app.service.AdjustmentService;
import com.bcnx.web.app.service.entity.BcnxSettle;
Expand All @@ -28,8 +26,7 @@ public Response save(@FormParam("mti") String mti,
@FormParam("rea") String rea, @FormParam("remark") String remark,
@FormParam("part") String part, @FormParam("amount") double amount,
@FormParam("fee") double fee, @FormParam("iss") String iss,
@FormParam("acq") String acq, @FormParam("usrId") String userId)
throws ApplicationException {
@FormParam("acq") String acq, @FormParam("usrId") String userId) throws Exception {
DisputeTxn disputeTxn = new DisputeTxn();
disputeTxn.setProcc(proc);
disputeTxn.setRemark(remark);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;

import org.jboss.resteasy.spi.ApplicationException;

import com.bcnx.web.app.context.BcnxApplicationContext;
import com.bcnx.web.app.service.BcnxSettleService;
import com.bcnx.web.app.service.entity.BcnxSettle;
Expand All @@ -25,7 +23,7 @@ public Response getBcnxSettles(@QueryParam("card") String card,
@QueryParam("rrn") String rrn, @QueryParam("stan") String stan,
@QueryParam("from") String from, @QueryParam("to") String to,
@QueryParam("page") int page, @QueryParam("rows") int rows)
throws ApplicationException {
throws Exception {
BcnxSettle bs = new BcnxSettle();
bs.setCard(card);
bs.setRrn(rrn);
Expand Down
Loading

0 comments on commit 1715201

Please sign in to comment.