Search in sources :

Example 1 with UserDetailsImpl

use of mingzuozhibi.security.UserDetailsImpl in project mzzb-server by mingzuozhibi.

the class SessionController method sessionLogin.

@PostMapping(value = "/api/session", produces = MEDIA_TYPE)
public String sessionLogin(@JsonArg("$.username") String username, @JsonArg("$.password") String password) {
    User user = dao.lookup(User.class, "username", username);
    if (user == null) {
        if (LOGGER.isInfoEnabled()) {
            infoRequest("[用户名称不存在: username={}]", username);
        }
        return errorMessage("用户名称不存在");
    }
    UserDetails userDetails = new UserDetailsImpl(user);
    if (!userDetails.getPassword().equals(password)) {
        if (LOGGER.isInfoEnabled()) {
            infoRequest("[用户密码错误: username={}]", username);
        }
        return errorMessage("用户密码错误");
    }
    if (!userDetails.isEnabled()) {
        if (LOGGER.isWarnEnabled()) {
            warnRequest("[用户已被停用: username={}]", username);
        }
        return errorMessage("用户已被停用");
    }
    doLoginSuccess(userDetails);
    onLoginSuccess(username, true);
    JSONObject session = buildSession();
    if (LOGGER.isInfoEnabled()) {
        infoRequest("[用户成功登入: session={}]", session);
    }
    return objectResult(session);
}
Also used : UserDetailsImpl(mingzuozhibi.security.UserDetailsImpl) User(mingzuozhibi.persist.core.User) UserDetails(org.springframework.security.core.userdetails.UserDetails) JSONObject(org.json.JSONObject) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

User (mingzuozhibi.persist.core.User)1 UserDetailsImpl (mingzuozhibi.security.UserDetailsImpl)1 JSONObject (org.json.JSONObject)1 UserDetails (org.springframework.security.core.userdetails.UserDetails)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1