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;
}
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;
}
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;
}
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);
}
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);
}
Aggregations