Search in sources :

Example 1 with User

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();
}
Also used : User(com.vip.saturn.job.console.mybatis.entity.User) UserRole(com.vip.saturn.job.console.mybatis.entity.UserRole) SuccessResponseEntity(com.vip.saturn.job.console.controller.SuccessResponseEntity) Date(java.util.Date) Audit(com.vip.saturn.job.console.aop.annotation.Audit) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with User

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();
}
Also used : User(com.vip.saturn.job.console.mybatis.entity.User) SuccessResponseEntity(com.vip.saturn.job.console.controller.SuccessResponseEntity) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with User

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;
}
Also used : User(com.vip.saturn.job.console.mybatis.entity.User) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with 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"));
}
Also used : User(com.vip.saturn.job.console.mybatis.entity.User) Test(org.junit.Test)

Example 5 with User

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;
}
Also used : User(com.vip.saturn.job.console.mybatis.entity.User)

Aggregations

User (com.vip.saturn.job.console.mybatis.entity.User)7 SuccessResponseEntity (com.vip.saturn.job.console.controller.SuccessResponseEntity)3 ApiResponses (io.swagger.annotations.ApiResponses)3 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)2 Audit (com.vip.saturn.job.console.aop.annotation.Audit)1 UserRole (com.vip.saturn.job.console.mybatis.entity.UserRole)1 Date (java.util.Date)1 Test (org.junit.Test)1 Transactional (org.springframework.transaction.annotation.Transactional)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1