use of com.vip.saturn.job.console.mybatis.entity.User in project Saturn by vipshop.
the class AuthorizationController method addUserRoles.
@ApiResponses(value = { @ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class) })
@Audit
@PostMapping("/addUserRoles")
public SuccessResponseEntity addUserRoles(@AuditParam("userName") @RequestParam String userName, @AuditParam("roleKey") @RequestParam String roleKey, @AuditParam("namespace") @RequestParam String namespace, @AuditParam("needApproval") @RequestParam Boolean needApproval, HttpSession httpSession) throws SaturnJobConsoleException {
assertIsSystemAdmin();
String currentLoginUserName = getCurrentLoginUserName();
Date now = new Date();
UserRole userRole = new UserRole();
userRole.setUserName(userName);
userRole.setRoleKey(roleKey);
userRole.setNamespace(namespace);
userRole.setNeedApproval(needApproval);
userRole.setIsDeleted(false);
userRole.setCreatedBy(currentLoginUserName);
userRole.setCreateTime(now);
userRole.setLastUpdatedBy(currentLoginUserName);
userRole.setLastUpdateTime(now);
User user = new User();
user.setUserName(userName);
user.setPassword("");
user.setRealName("");
user.setEmployeeId("");
user.setEmail("");
user.setCreatedBy(currentLoginUserName);
user.setCreateTime(now);
user.setLastUpdatedBy(currentLoginUserName);
user.setLastUpdateTime(now);
user.setIsDeleted(false);
userRole.setUser(user);
authorizationService.addUserRole(userRole);
return new SuccessResponseEntity();
}
use of com.vip.saturn.job.console.mybatis.entity.User in project Saturn by vipshop.
the class AuthenticationController method login.
@ApiResponses(value = { @ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class) })
@RequestMapping(value = "/login", method = { RequestMethod.POST })
public SuccessResponseEntity login(@RequestParam String username, @RequestParam String password, HttpServletRequest request) throws SaturnJobConsoleException {
User user = authenticationService.authenticate(username, password);
request.getSession().setAttribute(SessionAttributeKeys.LOGIN_USER_NAME, user.getUserName());
request.getSession().setAttribute(SessionAttributeKeys.LOGIN_USER_REAL_NAME, user.getRealName());
AUDIT_LOGGER.info("{}({}) was login where ip={} ", user.getUserName(), user.getRealName(), request.getRemoteAddr());
return new SuccessResponseEntity();
}
use of com.vip.saturn.job.console.mybatis.entity.User in project Saturn by vipshop.
the class AuthenticationServiceImpl method authenticate.
@Transactional(readOnly = true)
@Override
public User authenticate(String username, String password) throws SaturnJobConsoleException {
if (StringUtils.isEmpty(password)) {
throw new SaturnJobConsoleException(SaturnJobConsoleException.ERROR_CODE_AUTHN_FAIL, "密码不能为空");
}
User user = userRepository.select(username);
if (user == null) {
throw new SaturnJobConsoleException(SaturnJobConsoleException.ERROR_CODE_AUTHN_FAIL, "用户名不存在");
}
PasswordUtils.validate(password, user.getPassword(), hashMethod);
return user;
}
use of com.vip.saturn.job.console.mybatis.entity.User in project Saturn by vipshop.
the class AuthenticationServiceImplTest method testAuthenticateSuccessfully.
@Test
public void testAuthenticateSuccessfully() throws SaturnJobConsoleException {
authnService.setHashMethod("plaintext");
User user = createUser("jeff", "password");
when(userRepository.select("jeff")).thenReturn(user);
assertEquals(user, authnService.authenticate("jeff", "password"));
}
use of com.vip.saturn.job.console.mybatis.entity.User in project Saturn by vipshop.
the class AuthenticationServiceImplTest method createUser.
private User createUser(String username, String password) {
User user = new User();
user.setUserName(username);
user.setPassword(password);
return user;
}
Aggregations