This commit is contained in:
fit2-zhao 2020-11-30 14:30:08 +08:00
commit b9fc0c8195
2 changed files with 16 additions and 16 deletions

View File

@ -552,7 +552,6 @@ public class UserService {
public ResultHolder login(LoginRequest request) { public ResultHolder login(LoginRequest request) {
String login = (String) SecurityUtils.getSubject().getSession().getAttribute("authenticate"); String login = (String) SecurityUtils.getSubject().getSession().getAttribute("authenticate");
String msg;
String username = StringUtils.trim(request.getUsername()); String username = StringUtils.trim(request.getUsername());
String password = ""; String password = "";
if (!StringUtils.equals(login, UserSource.LDAP.name())) { if (!StringUtils.equals(login, UserSource.LDAP.name())) {
@ -564,7 +563,6 @@ public class UserService {
UsernamePasswordToken token = new UsernamePasswordToken(username, password); UsernamePasswordToken token = new UsernamePasswordToken(username, password);
Subject subject = SecurityUtils.getSubject(); Subject subject = SecurityUtils.getSubject();
try { try {
subject.login(token); subject.login(token);
if (subject.isAuthenticated()) { if (subject.isAuthenticated()) {
@ -588,20 +586,18 @@ public class UserService {
return ResultHolder.error(Translator.get("login_fail")); return ResultHolder.error(Translator.get("login_fail"));
} }
} catch (ExcessiveAttemptsException e) { } catch (ExcessiveAttemptsException e) {
msg = Translator.get("excessive_attempts"); throw new ExcessiveAttemptsException(Translator.get("excessive_attempts"));
} catch (LockedAccountException e) { } catch (LockedAccountException e) {
msg = Translator.get("user_locked"); throw new LockedAccountException(Translator.get("user_locked"));
} catch (DisabledAccountException e) { } catch (DisabledAccountException e) {
msg = Translator.get("user_has_been_disabled"); throw new DisabledAccountException(Translator.get("user_has_been_disabled"));
} catch (ExpiredCredentialsException e) { } catch (ExpiredCredentialsException e) {
msg = Translator.get("user_expires"); throw new ExpiredCredentialsException(Translator.get("user_expires"));
} catch (AuthenticationException e) { } catch (AuthenticationException e) {
msg = e.getMessage(); throw new AuthenticationException(e.getMessage());
} catch (UnauthorizedException e) { } catch (UnauthorizedException e) {
msg = Translator.get("not_authorized") + e.getMessage(); throw new UnauthorizedException(Translator.get("not_authorized") + e.getMessage());
} }
MSException.throwException(msg);
return null;
} }
public List<User> searchUser(String condition) { public List<User> searchUser(String condition) {

View File

@ -5,6 +5,10 @@ import i18n from '../../i18n/i18n'
export default { export default {
install(Vue) { install(Vue) {
// 登入请求不重定向
let unRedirectUrls = new Set(['signin']);
if (!axios) { if (!axios) {
window.console.error('You have to install axios'); window.console.error('You have to install axios');
return return
@ -50,12 +54,12 @@ export default {
result.loading = false; result.loading = false;
} }
function exception(error, result) { function exception(error, result, url) {
if (error.response && error.response.status === 401) { if (error.response && error.response.status === 401 && !unRedirectUrls.has(url)) {
login(); login();
return; return;
} }
if (error.response && error.response.status === 403) { if (error.response && error.response.status === 403 && !unRedirectUrls.has(url)) {
window.location.href = "/"; window.location.href = "/";
return; return;
} }
@ -78,7 +82,7 @@ export default {
axios.get(url, {params: data}).then(response => { axios.get(url, {params: data}).then(response => {
then(success, response, result); then(success, response, result);
}).catch(error => { }).catch(error => {
exception(error, result); exception(error, result, url);
}); });
return result; return result;
} }
@ -92,7 +96,7 @@ export default {
axios.get(url).then(response => { axios.get(url).then(response => {
then(success, response, result); then(success, response, result);
}).catch(error => { }).catch(error => {
exception(error, result); exception(error, result, url);
}); });
return result; return result;
} }
@ -106,7 +110,7 @@ export default {
axios.post(url, data).then(response => { axios.post(url, data).then(response => {
then(success, response, result); then(success, response, result);
}).catch(error => { }).catch(error => {
exception(error, result); exception(error, result, url);
if (failure) { if (failure) {
then(failure, error, result); then(failure, error, result);
} }