Search in sources :

Example 6 with User

use of com.topcom.cms.domain.User in project topcom-cloud by 545314690.

the class UserController method appResource.

/**
 * 返回登录用户指定app的resource
 */
@ApiOperation("获取指定app的resource")
@RequestMapping(value = { "appResource" }, method = { RequestMethod.GET })
@ResponseBody
public Set<Resource> appResource(@CurrentUser User user, @RequestParam(required = false) Long appId, @RequestParam(required = false) String appName) throws Exception {
    if (appId == null && StringUtils.isBlank(appName)) {
        throw new BusinessException("appId 和 appName 不能同时为空!");
    }
    if (appId == null) {
        Application app = applicationManager.findByName(appName);
        appId = app.getId();
    }
    // 缓存user懒加载,没有resource,需要在数据库查询
    User user1 = this.manager.findById(user.getId());
    Set<Resource> resourceSet = user1.getResource();
    if (resourceSet == null || resourceSet.size() == 0) {
        return null;
    }
    Set<Resource> filteredResourceSet = new LinkedHashSet<>();
    for (Resource resource : resourceSet) {
        if (appId.equals(resource.getAppId())) {
            filteredResourceSet.add(resource);
        }
    }
    for (Resource resource : filteredResourceSet) {
        resource.sortByChildId();
    }
    return filteredResourceSet;
}
Also used : BusinessException(com.topcom.cms.exception.BusinessException) CurrentUser(com.topcom.cms.web.bind.annotation.CurrentUser) User(com.topcom.cms.domain.User) PublicResource(com.topcom.cms.perm.annotation.PublicResource) Resource(com.topcom.cms.domain.Resource) Application(com.topcom.cms.domain.Application) ApiOperation(io.swagger.annotations.ApiOperation)

Example 7 with User

use of com.topcom.cms.domain.User in project topcom-cloud by 545314690.

the class SubjectUtil method login.

public static boolean login(UsernamePasswordToken token) throws AuthenticationException {
    String username = token.getUsername();
    User user = userManager.findByUsername(username);
    if (user == null) {
        // 没找到帐号
        throw new UnknownAccountException();
    }
    if (User.State.UNAVAILABLE.equals(user.getState())) {
        // 帐号不可用
        throw new AccountUnavailableException();
    }
    if (User.State.LOCKED.equals(user.getState())) {
        // 帐号锁定
        throw new LockedAccountException();
    }
    if (token.getAdmin() != null && token.getAdmin() == true) {
        Boolean admin = user.isAdmin();
        if (admin == null || admin != true) {
            // 不是管理员帐号
            throw new UnknownAccountException("不是管理员帐号,不能登录");
        }
    }
    boolean matched = true;
    String loginPassword = token.getPassword();
    String credentialsSalt = user.getCredentialsSalt();
    String password = user.getPassword();
    String encodedPassword = PasswordHelper.getEncodedPassword(loginPassword, credentialsSalt);
    if (!StringUtils.equals(encodedPassword, password)) {
        matched = false;
        throw new IncorrectCredentialsException();
    } else {
        tokenManager.createAndSaveToken(user);
    // resetRetryTimes(username);
    }
    return matched;
}
Also used : User(com.topcom.cms.domain.User)

Example 8 with User

use of com.topcom.cms.domain.User in project topcom-cloud by 545314690.

the class CurrentUserMethodArgumentResolver method resolveArgument.

@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
    CurrentUser currentUserAnnotation = parameter.getParameterAnnotation(CurrentUser.class);
    // 从Session 获取用户
    Object object = webRequest.getAttribute(currentUserAnnotation.value(), NativeWebRequest.SCOPE_SESSION);
    // 如果用户未登陆,抛出异常
    if (object == null) {
        // throw new UnLoginException();
        // return new User(100L);
        String token = webRequest.getHeader("Authorization");
        if (token == null) {
            token = webRequest.getParameter("accessToken");
        }
        if (token == null) {
            throw new UnLoginException();
        } else {
            User obj = SubjectUtil.getCurrentUser(token);
            if (obj == null) {
                throw new UnLoginException();
            } else {
                return obj;
            }
        }
    }
    return object;
}
Also used : CurrentUser(com.topcom.cms.web.bind.annotation.CurrentUser) User(com.topcom.cms.domain.User) CurrentUser(com.topcom.cms.web.bind.annotation.CurrentUser) UnLoginException(com.topcom.cms.perm.exception.UnLoginException)

Example 9 with User

use of com.topcom.cms.domain.User in project topcom-cloud by 545314690.

the class UserControllerTest method test.

@Test
public void test() throws Exception {
    User model = new User();
    this.userController.create(model);
}
Also used : User(com.topcom.cms.domain.User) Test(org.junit.Test)

Example 10 with User

use of com.topcom.cms.domain.User in project topcom-cloud by 545314690.

the class UserControllerTest method login.

@Test
public void login() throws Exception {
    User model = new User();
    this.userController.create(model);
}
Also used : User(com.topcom.cms.domain.User) Test(org.junit.Test)

Aggregations

User (com.topcom.cms.domain.User)24 CurrentUser (com.topcom.cms.web.bind.annotation.CurrentUser)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)5 PageRequest (org.springframework.data.domain.PageRequest)4 Pageable (org.springframework.data.domain.Pageable)4 Group (com.topcom.cms.domain.Group)3 Resource (com.topcom.cms.domain.Resource)3 ApiOperation (io.swagger.annotations.ApiOperation)3 JSONObject (net.sf.json.JSONObject)3 WeChat (com.topcom.cms.data.domain.WeChat)2 BusinessException (com.topcom.cms.exception.BusinessException)2 AuthenticationException (com.topcom.cms.perm.exception.AuthenticationException)2 UsernamePasswordToken (com.topcom.cms.perm.token.UsernamePasswordToken)2 UserManager (com.topcom.cms.service.UserManager)2 com.topcom.cms.yuqing.domain (com.topcom.cms.yuqing.domain)2 CustomSubjectManager (com.topcom.cms.yuqing.service.CustomSubjectManager)2 SubscriptionFollowerManager (com.topcom.cms.yuqing.service.SubscriptionFollowerManager)2 WarningLogManager (com.topcom.cms.yuqing.service.WarningLogManager)2 WarningManager (com.topcom.cms.yuqing.service.WarningManager)2