📄 securityaction.java
字号:
* @throws IOException IOException
* @throws ServletException ServletException
*/
public final ActionForward noRight(final ActionMapping mapping,
final ActionForm form, final HttpServletRequest request,
final HttpServletResponse response)
throws IOException, ServletException {
ActionErrors errors = new ActionErrors();
errors.add("no right", new ActionError("errors.NoRight"));
// Remove the obsolete form bean
removeAttribute(mapping, request);
if (!errors.isEmpty()) {
saveErrors(request, errors);
}
return mapping.findForward("success");
}
/**
* DOCUMENT ME!
*
* @param mapping actionMapping
* @param form actionForm
* @param request http request
* @param response http response
*
* @return actionforward
*
* @throws IOException IO error
* @throws ServletException any error
*/
public final ActionForward register(final ActionMapping mapping,
final ActionForm form, final HttpServletRequest request,
final HttpServletResponse response)
throws IOException, ServletException {
ActionErrors errors = new ActionErrors();
Account account = (Account) ((DynaActionForm) form).get("account");
try {
securityService.register(account);
} catch (BusinessException e) {
log.error("register account error: " + e);
errors.add("register account", new ActionError("errors.UnKnowError"));
} catch (AccountAlreadyExistException e) {
errors.add("register account",
new ActionError("errors.AccountExist"));
}
if (!errors.isEmpty()) {
saveErrors(request, errors);
return mapping.findForward("faile");
} else {
return (mapping.findForward("success"));
}
}
/**
* DOCUMENT ME!
*
* @param mapping actionMapping
* @param form actionForm
* @param request http request
* @param response http response
*
* @return actionforward
*
* @throws IOException IO error
* @throws ServletException any error
*/
public final ActionForward removeAccount(final ActionMapping mapping,
final ActionForm form, final HttpServletRequest request,
final HttpServletResponse response)
throws IOException, ServletException {
ActionErrors errors = new ActionErrors();
String[] ids = request.getParameterValues("id");
try {
securityService.removeAccount(ids);
} catch (BusinessException e) {
log.error("remove account error: ", e);
errors.add("remove account", new ActionError("errors.UnKnowError"));
}
if (!errors.isEmpty()) {
saveErrors(request, errors);
return mapping.findForward("faile");
}
return (mapping.findForward("success"));
}
/**
* DOCUMENT ME!
*
* @param mapping actionMapping
* @param form actionForm
* @param request http request
* @param response http response
*
* @return actionforward
*
* @throws IOException IO error
* @throws ServletException any error
*/
public final ActionForward removeRight(final ActionMapping mapping,
final ActionForm form, final HttpServletRequest request,
final HttpServletResponse response)
throws IOException, ServletException {
ActionErrors errors = new ActionErrors();
String[] index = request.getParameterValues("index");
String[] ids = request.getParameterValues("id");
String[] rights = new String[index.length];
int j = 0;
for (int i = 0, n = index.length; i < n; i++) {
j = Integer.parseInt(index[i]);
rights[i] = ids[j];
}
try {
securityService.removeRight(rights);
} catch (BusinessException e) {
log.error("remove right error: ", e);
errors.add("remove right", new ActionError("errors.UnKnowError"));
}
if (!errors.isEmpty()) {
saveErrors(request, errors);
return mapping.findForward("faile");
}
return (mapping.findForward("success"));
}
/**
* remove group
*
* @param mapping actionMapping
* @param form actionForm
* @param request http request
* @param response http response
*
* @return actionforward
*
* @throws IOException IO error
* @throws ServletException any error
*/
public final ActionForward removeRole(final ActionMapping mapping,
final ActionForm form, final HttpServletRequest request,
final HttpServletResponse response)
throws IOException, ServletException {
ActionErrors errors = new ActionErrors();
String[] ids = request.getParameterValues("id");
try {
securityService.removeRole(ids);
} catch (BusinessException e) {
log.error("remove group error: ", e);
errors.add("remove group", new ActionError("errors.UnKnowError"));
}
if (!errors.isEmpty()) {
saveErrors(request, errors);
return mapping.findForward("faile");
}
return (mapping.findForward("success"));
}
/**
* update account info
*
* @param mapping action mapping
* @param form action form
* @param request http request
* @param response http response
*
* @return action forward
*
* @throws IOException io exception
* @throws ServletException servlet exception
*/
public final ActionForward updateAccountInfo(final ActionMapping mapping,
final ActionForm form, final HttpServletRequest request,
final HttpServletResponse response)
throws IOException, ServletException {
ActionErrors errors = new ActionErrors();
Account account = (Account) ((DynaActionForm) form).get("account");
try {
securityService.updateAccount(account);
} catch (BusinessException e) {
log.error("updateAccountInfo error: " + e);
errors.add("updateAccountInfo",
new ActionError("errors.UnKnowError"));
} catch (AccountAlreadyExistException e) {
errors.add("register account",
new ActionError("errors.AccountExist"));
}
if (!errors.isEmpty()) {
saveErrors(request, errors);
return mapping.findForward("faile");
} else {
removeAttribute(mapping, request);
return (mapping.findForward("success"));
}
}
/**
* update right
*
* @param mapping actionMapping
* @param form actionForm
* @param request http request
* @param response http response
*
* @return actionforward
*
* @throws IOException IO error
* @throws ServletException any error
*/
public final ActionForward updateRight(final ActionMapping mapping,
final ActionForm form, final HttpServletRequest request,
final HttpServletResponse response)
throws IOException, ServletException {
ActionErrors errors = new ActionErrors();
String[] index = request.getParameterValues("index");
String[] ids = request.getParameterValues("id");
String[] boxs = request.getParameterValues("box");
String[] descs = request.getParameterValues("desc");
String[] urls = request.getParameterValues("url");
Right[] rights = new Right[index.length];
int j = 0;
for (int i = 0, n = index.length; i < n; i++) {
j = Integer.parseInt(index[i]);
rights[i] = new Right();
rights[i].setId(ids[j]);
rights[i].setBox(boxs[j]);
rights[i].setDesc(descs[j]);
rights[i].setUrl(urls[j]);
}
try {
securityService.updateRight(rights);
} catch (BusinessException e) {
log.error("update right error: ", e);
errors.add("update right", new ActionError("errors.UnKnowError"));
} catch (RightExistException e) {
errors.add("update right", new ActionError("errors.RightExist"));
}
if (!errors.isEmpty()) {
saveErrors(request, errors);
return mapping.findForward("faile");
}
removeAttribute(mapping, request);
return (mapping.findForward("success"));
}
/**
* update group desc or rights
*
* @param mapping actionMapping
* @param form actionForm
* @param request http request
* @param response http response
*
* @return actionforward
*
* @throws IOException IO error
* @throws ServletException any error
*/
public final ActionForward updateRole(final ActionMapping mapping,
final ActionForm form, final HttpServletRequest request,
final HttpServletResponse response)
throws IOException, ServletException {
ActionErrors errors = new ActionErrors();
String[] removeRight = request.getParameterValues("removeRight");
String[] addRight = request.getParameterValues("addRight");
Role group = (Role) ((DynaActionForm) form).get("group");
try {
securityService.updateRole(group, removeRight, addRight);
} catch (BusinessException e) {
log.error("update group error: ", e);
errors.add("update group", new ActionError("errors.UnKnowError"));
} catch (GroupExistException e) {
errors.add("create right", new ActionError("errors.GroupExist"));
}
if (!errors.isEmpty()) {
saveErrors(request, errors);
return mapping.findForward("faile");
}
removeAttribute(mapping, request);
return (mapping.findForward("success"));
}
/**
* view account info
*
* @param mapping action mapping
* @param form action form
* @param request http request
* @param response http response
*
* @return action forward
*
* @throws IOException io exception
* @throws ServletException servlet exception
*/
public final ActionForward viewAccount(final ActionMapping mapping,
final ActionForm form, final HttpServletRequest request,
final HttpServletResponse response)
throws IOException, ServletException {
ActionErrors errors = new ActionErrors();
Account account = null;
String accountId = (String) request.getSession(false)
.getAttribute("account");
account = securityService.findAccountById(accountId);
if (account == null) {
errors.add("register account", new ActionError("errors.UnKnowError"));
} else {
DynaValidatorForm aform = (DynaValidatorForm) form;
aform.set("account", account);
}
if (!errors.isEmpty()) {
saveErrors(request, errors);
return mapping.findForward("faile");
}
return (mapping.findForward("success"));
}
/**
* view group
*
* @param mapping actionMapping
* @param form actionForm
* @param request http request
* @param response http response
*
* @return actionforward
*
* @throws IOException IO error
* @throws ServletException any error
*/
public final ActionForward viewRole(final ActionMapping mapping,
final ActionForm form, final HttpServletRequest request,
final HttpServletResponse response)
throws IOException, ServletException {
ActionErrors errors = new ActionErrors();
Role group = null;
Right[] rights = null;
String groupId = request.getParameter("id");
try {
group = securityService.findRoleById(groupId);
rights = securityService.findAllRight();
} catch (BusinessException e) {
log.error("viewAccountInfo error: " + e.getMessage());
errors.add("register account", new ActionError("errors.UnKnowError"));
}
if (group == null) {
errors.add("view group", new ActionError("errors.UnKnowError"));
} else {
Map rightlist = new HashMap();
for (int i = 0, n = rights.length; i < n; i++) {
rightlist.put(rights[i].getId(), rights[i]);
}
for (Iterator i = group.getRights()
.iterator(); i.hasNext();) {
rightlist.remove(((Right) i.next()).getId());
}
((DynaActionForm) form).set("group", group);
request.getSession(false)
.setAttribute("rights", rightlist.values());
request.getSession(false)
.setAttribute("removerights", group.getRights());
}
if (!errors.isEmpty()) {
saveErrors(request, errors);
return mapping.findForward("faile");
}
return (mapping.findForward("success"));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -