提交 dcf9fed7 编写于 作者: Z zhourui

restore login

上级 db7c2460
......@@ -38,7 +38,7 @@ class ActionCaptchaLogin extends BaseAction {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
Wo wo = null;
String password = password(wi);
String password = password(wi.getPassword());
if (BooleanUtils.isTrue(Config.person().getCaptchaLogin()) && (BooleanUtils
.isFalse(business.instrument().captcha().validate(wi.getCaptcha(), wi.getCaptchaAnswer())))) {
throw new ExceptionInvalidCaptcha();
......
//package com.x.organization.assemble.authentication.jaxrs.authentication;
//
//import java.util.List;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
//import org.apache.commons.lang3.StringUtils;
//
//import com.google.gson.JsonElement;
//import com.x.base.core.container.EntityManagerContainer;
//import com.x.base.core.container.factory.EntityManagerContainerFactory;
//import com.x.base.core.project.annotation.FieldDescribe;
//import com.x.base.core.project.config.Config;
//import com.x.base.core.project.gson.GsonPropertyObject;
//import com.x.base.core.project.http.ActionResult;
//import com.x.base.core.project.http.EffectivePerson;
//import com.x.base.core.project.logger.Logger;
//import com.x.base.core.project.logger.LoggerFactory;
//import com.x.organization.assemble.authentication.Business;
//import com.x.organization.core.entity.Person;
//
//@Deprecated(forRemoval = true)
//class ActionLogin extends BaseAction {
//
// private static final Logger LOGGER = LoggerFactory.getLogger(ActionLogin.class);
//
// ActionResult<Wo> execute(HttpServletRequest request, HttpServletResponse response, EffectivePerson effectivePerson,
// JsonElement jsonElement) throws Exception {
// try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
// ActionResult<Wo> result = new ActionResult<>();
// Business business = new Business(emc);
// Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
// Wo wo = new Wo();
// check(wi);
// LOGGER.debug("user:{}, try to login.", wi.getCredential());
// String password = wi.getPassword();
// if (Config.token().isInitialManager(wi.getCredential())) {
// if (!Config.token().verifyPassword(wi.getCredential(), password)) {
// throw new ExceptionPersonNotExistOrInvalidPassword();
// }
// wo = this.manager(request, response, wi.getCredential(), Wo.class);
// } else {
// // 普通用户登录,也有可能拥有管理员角色.增加相同标识(name允许重复)的认证
// List<String> people = this.listWithCredential(business, wi.getCredential());
// Person person = null;
// if (people.isEmpty()) {
// throw new ExceptionPersonNotExistOrInvalidPassword();
// } else if (people.size() == 1) {
// person = this.personLogin(business, people.get(0), password);
// } else {
// person = this.peopleLogin(business, people, password);
// }
// if (null == person) {
// throw new ExceptionPersonNotExistOrInvalidPassword();
// } else {
// wo = this.user(request, response, business, person, Wo.class);
// }
// }
// result.setData(wo);
// return result;
// }
// }
//
// private void check(Wi wi) throws ExceptionCredentialEmpty, ExceptionPasswordEmpty {
// if (StringUtils.isEmpty(wi.getCredential())) {
// throw new ExceptionCredentialEmpty();
// }
// if (StringUtils.isEmpty(wi.getPassword())) {
// throw new ExceptionPasswordEmpty();
// }
// }
//
// public static class Wi extends GsonPropertyObject {
//
// private static final long serialVersionUID = -6099815091986193292L;
//
// @FieldDescribe("凭证")
// private String credential;
//
// @FieldDescribe("密码")
// private String password;
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public String getCredential() {
// return credential;
// }
//
// public void setCredential(String credential) {
// this.credential = credential;
// }
//
// }
//
// public static class Wo extends AbstractWoAuthentication {
//
// private static final long serialVersionUID = -5397186305200946501L;
//
// }
//}
package com.x.organization.assemble.authentication.jaxrs.authentication;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import com.google.gson.JsonElement;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.organization.assemble.authentication.Business;
import com.x.organization.core.entity.Person;
import com.x.organization.core.express.assemble.authentication.jaxrs.authentication.ActionLoginWi;
import io.swagger.v3.oas.annotations.media.Schema;
class ActionLogin extends BaseAction {
private static final Logger LOGGER = LoggerFactory.getLogger(ActionLogin.class);
ActionResult<Wo> execute(HttpServletRequest request, HttpServletResponse response, EffectivePerson effectivePerson,
JsonElement jsonElement) throws Exception {
LOGGER.debug("execute:{}.", effectivePerson::getDistinguishedName);
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<Wo> result = new ActionResult<>();
Business business = new Business(emc);
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
Wo wo = new Wo();
check(wi);
String password = this.password(wi.getPassword());
if (Config.token().isInitialManager(wi.getCredential())) {
if (!Config.token().verifyPassword(wi.getCredential(), password)) {
throw new ExceptionPersonNotExistOrInvalidPassword();
}
wo = this.manager(request, response, wi.getCredential(), Wo.class);
} else {
// 普通用户登录,也有可能拥有管理员角色.增加相同标识(name允许重复)的认证
List<String> people = this.listWithCredential(business, wi.getCredential());
Person person = null;
if (people.isEmpty()) {
throw new ExceptionPersonNotExistOrInvalidPassword();
} else if (people.size() == 1) {
person = this.personLogin(business, people.get(0), password);
} else {
person = this.peopleLogin(business, people, password);
}
if (null == person) {
throw new ExceptionPersonNotExistOrInvalidPassword();
} else {
wo = this.user(request, response, business, person, Wo.class);
}
}
result.setData(wo);
return result;
}
}
private void check(Wi wi) throws ExceptionCredentialEmpty, ExceptionPasswordEmpty {
if (StringUtils.isEmpty(wi.getCredential())) {
throw new ExceptionCredentialEmpty();
}
if (StringUtils.isEmpty(wi.getPassword())) {
throw new ExceptionPasswordEmpty();
}
}
@Schema(name = "com.x.organization.assemble.authentication.jaxrs.authentication.ActionLogin$Wi")
public static class Wi extends ActionLoginWi {
private static final long serialVersionUID = -3566349910283010822L;
}
public static class Wo extends AbstractWoAuthentication {
private static final long serialVersionUID = -5397186305200946501L;
}
}
......@@ -72,24 +72,24 @@ public class AuthenticationAction extends StandardJaxrsAction {
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
// @JaxrsMethodDescribe(value = "用户登录.credential=xxxx,password=xxxx", action = ActionLogin.class)
// @POST
// @Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
// @Consumes(MediaType.APPLICATION_JSON)
// public void login(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
// @Context HttpServletResponse response, JsonElement jsonElement) {
// ActionResult<ActionLogin.Wo> result = new ActionResult<>();
// EffectivePerson effectivePerson = this.effectivePerson(request);
// try {
// result = new ActionLogin().execute(request, response, effectivePerson, jsonElement);
// } catch (Exception e) {
// logger.error(e, effectivePerson, request, null);
// result.error(e);
// }
// // 擦除密码
// erasePassword(jsonElement);
// asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result, jsonElement));
// }
@JaxrsMethodDescribe(value = "用户登录.credential=xxxx,password=xxxx", action = ActionLogin.class)
@POST
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void login(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@Context HttpServletResponse response, JsonElement jsonElement) {
ActionResult<ActionLogin.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionLogin().execute(request, response, effectivePerson, jsonElement);
} catch (Exception e) {
LOGGER.error(e, effectivePerson, request, null);
result.error(e);
}
// 擦除密码
erasePassword(jsonElement);
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result, jsonElement));
}
@JaxrsMethodDescribe(value = "用户注销.", action = ActionLogout.class)
@DELETE
......
......@@ -159,10 +159,9 @@ abstract class BaseAction extends StandardJaxrsAction {
return em.createQuery(cq).getResultList().stream().distinct().collect(Collectors.toList());
}
protected String password(Wi wi) throws Exception {
return BooleanUtils.isTrue(Config.token().getRsaEnable())
? Crypto.rsaDecrypt(wi.getPassword(), Config.privateKey())
: wi.getPassword();
protected String password(String password) throws Exception {
return BooleanUtils.isTrue(Config.token().getRsaEnable()) ? Crypto.rsaDecrypt(password, Config.privateKey())
: password;
}
protected Person personLogin(Business business, String id, String password) throws Exception {
......
package com.x.organization.core.express.assemble.authentication.jaxrs.authentication;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.gson.GsonPropertyObject;
import io.swagger.v3.oas.annotations.media.Schema;
public class ActionLoginWi extends GsonPropertyObject {
private static final long serialVersionUID = 633273224231633398L;
@FieldDescribe("用户标识.")
@Schema(description = "用户标识.")
private String credential;
@FieldDescribe("密码.")
@Schema(description = "密码.")
private String password;
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getCredential() {
return credential;
}
public void setCredential(String credential) {
this.credential = credential;
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册