Search in sources :

Example 6 with RestfulResult

use of cn.opencil.vo.RestfulResult in project CILManagement-Server by LiuinStein.

the class MyAuthenticationSuccessHandle method onAuthenticationSuccess.

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
    // run to here when log in success
    Map<String, Object> authorization = new HashMap<>();
    authorization.put("auth", authentication.getAuthorities().toString());
    RestfulResult result = new RestfulResult(0, "log in success", authorization);
    SecurityRestfulResponsePrinter responseHandle = new SecurityRestfulResponsePrinter();
    responseHandle.print(request, response, result);
    response.setStatus(HttpServletResponse.SC_CREATED);
}
Also used : HashMap(java.util.HashMap) RestfulResult(cn.opencil.vo.RestfulResult)

Example 7 with RestfulResult

use of cn.opencil.vo.RestfulResult in project CILManagement-Server by LiuinStein.

the class MyLogoutSuccessHandle method onLogoutSuccess.

@Override
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
    if (messageReturning) {
        RestfulResult result = new RestfulResult(0, "logout succeeded", new HashMap<>());
        SecurityRestfulResponsePrinter printer = new SecurityRestfulResponsePrinter();
        printer.print(request, response, result);
    }
    response.setStatus(httpStatusToReturn.value());
}
Also used : RestfulResult(cn.opencil.vo.RestfulResult)

Example 8 with RestfulResult

use of cn.opencil.vo.RestfulResult in project CILManagement-Server by LiuinStein.

the class UserController method queryMemberInfo.

/**
 * Query someone's information by given condition
 */
@RequestMapping(value = "/info", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ResponseStatus(HttpStatus.OK)
public RestfulResult queryMemberInfo(@RequestParam("mode") String mode, @RequestParam("condition") String condition, @RequestParam("value") String value) throws SimpleHttpException, ValidationException {
    UserInfo info = new UserInfo();
    switch(condition.toLowerCase()) {
        case "id":
            info.setId(Long.parseLong(value));
            break;
        case "name":
            info.setName(value);
            break;
        case "department":
            info.setDepartment(Integer.parseInt(value));
            break;
        default:
            throw new SimpleHttpException(2, "condition is not supported", HttpStatus.BAD_REQUEST);
    }
    info = ValidationUtils.validate(info);
    List<UserInfo> result;
    switch(mode.toLowerCase()) {
        case "summary":
            result = infoService.querySummaryUserInfo(info);
            break;
        case "all":
            result = infoService.queryAllUserInfo(info);
            break;
        default:
            result = null;
    }
    if (result == null || result.size() == 0) {
        throw new SimpleHttpException(404, "user not found", HttpStatus.NOT_FOUND);
    }
    HashMap<String, Object> data = new HashMap<>();
    data.put("users", result);
    return new RestfulResult(0, "", data);
}
Also used : SimpleHttpException(cn.opencil.exception.SimpleHttpException) HashMap(java.util.HashMap) RestfulResult(cn.opencil.vo.RestfulResult) UserInfo(cn.opencil.po.UserInfo) JSONObject(com.alibaba.fastjson.JSONObject)

Example 9 with RestfulResult

use of cn.opencil.vo.RestfulResult in project CILManagement-Server by LiuinStein.

the class UserController method register.

/**
 * Sign up a new member
 */
@RequestMapping(value = "/", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ResponseStatus(HttpStatus.CREATED)
public RestfulResult register(@RequestBody JSONObject input) throws SimpleHttpException, ValidationException {
    RBACUser user = ValidationUtils.validate(input.toJavaObject(RBACUser.class), RegisterValidation.class);
    UserInfo info = ValidationUtils.validate(input.toJavaObject(UserInfo.class), RegisterValidation.class);
    RBACUserRole role = ValidationUtils.validate(input.toJavaObject(RBACUserRole.class), RegisterValidation.class);
    if (!userService.addMember(user, info, role)) {
        throw new SimpleHttpException(500, "database access error", HttpStatus.INTERNAL_SERVER_ERROR);
    }
    return new RestfulResult(0, "new member created", new HashMap<>());
}
Also used : RBACUserRole(cn.opencil.po.RBACUserRole) RBACUser(cn.opencil.po.RBACUser) SimpleHttpException(cn.opencil.exception.SimpleHttpException) RestfulResult(cn.opencil.vo.RestfulResult) UserInfo(cn.opencil.po.UserInfo)

Aggregations

RestfulResult (cn.opencil.vo.RestfulResult)9 SimpleHttpException (cn.opencil.exception.SimpleHttpException)5 RBACUser (cn.opencil.po.RBACUser)4 UserInfo (cn.opencil.po.UserInfo)3 HashMap (java.util.HashMap)2 RBACUserRole (cn.opencil.po.RBACUserRole)1 JSONObject (com.alibaba.fastjson.JSONObject)1 ValidationException (com.shaoqunliu.validation.ValidationException)1 IOException (java.io.IOException)1 NotNull (org.jetbrains.annotations.NotNull)1 DataAccessException (org.springframework.dao.DataAccessException)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1 SecurityContextLogoutHandler (org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler)1 HttpRequestMethodNotSupportedException (org.springframework.web.HttpRequestMethodNotSupportedException)1 ServletRequestBindingException (org.springframework.web.bind.ServletRequestBindingException)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1