Search in sources :

Example 1 with User

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

the class LoginLogService method doAfter.

@AfterReturning("loginMethod()")
public void doAfter(JoinPoint pjp) throws Exception {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    String contextPath = request.getContextPath();
    User user = SubjectUtil.getCurrentUser(request);
    LoginLog loginLog = new LoginLog();
    loginLog.setUserId(user.getId());
    loginLog.setUsername(user.getUsername());
    loginLog.setHost(request.getRemoteHost());
    if (StringUtils.isNotBlank(contextPath) && contextPath.length() > 0) {
        loginLog.setSysName(contextPath.substring(1));
    }
    loginLogManager.save(loginLog);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) LoginLog(com.topcom.cms.domain.LoginLog) User(com.topcom.cms.domain.User) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) AfterReturning(org.aspectj.lang.annotation.AfterReturning)

Example 2 with User

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

the class OperationLogService method doBasicProfiling.

@AfterReturning("anyMethod()")
public void doBasicProfiling(JoinPoint pjp) throws Throwable {
    HttpServletRequest request = SubjectUtil.getRequest();
    Object[] args = pjp.getArgs();
    OperationLog ol = new OperationLog();
    Object obj = args[0];
    // 拦截的实体类 Object target = pjp.getTarget();
    Class<?> entityClazz = (Class<?>) ((ParameterizedType) pjp.getTarget().getClass().getGenericSuperclass()).getActualTypeArguments()[0];
    ol.setEntity(entityClazz.getName());
    if (obj instanceof Long) {
        ol.setOperation(OperationLog.Operation.DELETE);
    } else if (obj instanceof BaseEntityModel) {
        BaseEntityModel objModel = (BaseEntityModel) obj;
        if (objModel.getId() == null || objModel.getId() == 0) {
            ol.setOperation(OperationLog.Operation.CREATE);
        } else {
            ol.setOperation(OperationLog.Operation.MODIFY);
        }
        ol.setEntity(objModel.getEntityName());
    } else {
        return;
    }
    // 拦截的方法名称
    String methodName = pjp.getSignature().getName();
    /**
     * request是null,说明是系统调用save,否则是用户调用
     */
    if (request == null) {
        ol.setUsername("系统操作");
    } else {
        User user = SubjectUtil.getCurrentUser();
        ol.setHost(request.getRemoteHost());
        if (user != null) {
            ol.setUserId(user.getId());
            ol.setUsername(user.getUsername());
        }
    }
    ol.setMethod(methodName);
    /**
     * 不使用save方法,更改了操作日志的保存方法,否则会造成无限循环调用
     */
    // TODO:写一个注解,在方法名上标注不被拦截的方法
    operationLogManager.persist(ol);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ParameterizedType(java.lang.reflect.ParameterizedType) User(com.topcom.cms.domain.User) OperationLog(com.topcom.cms.domain.OperationLog) BaseEntityModel(com.topcom.cms.base.model.BaseEntityModel) AfterReturning(org.aspectj.lang.annotation.AfterReturning)

Example 3 with User

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

the class TokenManagerImpl method main.

public static void main(String[] args) {
    TokenManager tokenManager = new TokenManagerImpl();
    String token = tokenManager.createToken("102");
    User user = new User(102L);
    user.setUsername("sdmj");
    tokenManager.saveToken(token, user);
    System.out.println(token);
    String token2 = tokenManager.createToken("1");
    System.out.println(token2);
}
Also used : User(com.topcom.cms.domain.User)

Example 4 with User

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

the class SearchWordController method findByType.

/**
 * 热词查询 查询排名前 limit 的word
 * @return
 */
@RequestMapping(method = RequestMethod.GET, value = "/findByType", produces = "application/json")
@ResponseBody
public List<SearchWord> findByType(@CurrentUser User user, @ApiParam("limit") @RequestParam(required = true) Integer limit, @ApiParam("type") @RequestParam(required = true) Integer type) {
    Sort sort = new Sort(new Sort.Order(Sort.Direction.DESC, "wordCount"));
    Pageable page = new PageRequest(0, limit, sort);
    User user1 = this.userManager.findById(user.getId());
    Set<Group> groups = user1.getGroups();
    String groupId = SearchWord.groupIdBySet(groups);
    List<String> groupIdList = new ArrayList<>();
    groupIdList.add(groupId);
    if (groupId.indexOf(",") != -1) {
        String[] split = groupId.split(",");
        for (String s : split) {
            groupIdList.add(s);
        }
    }
    Page<SearchWord> searchWords = this.searchWordManager.findByTypeAndGroupIdIn(page, type, groupIdList);
    return filterNull(searchWords);
}
Also used : Group(com.topcom.cms.domain.Group) CurrentUser(com.topcom.cms.web.bind.annotation.CurrentUser) User(com.topcom.cms.domain.User) SearchWord(com.topcom.cms.domain.SearchWord) PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with User

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

the class UserController method update.

/**
 * 重写父类put方法 更改了父类的保存方法
 */
@Override
@RequestMapping(value = { "/{id}" }, method = { RequestMethod.PUT }, produces = { "application/json" }, consumes = { "application/json" })
@ResponseBody
public User update(@PathVariable Long id, @RequestBody User model) {
    User user = this.manager.findById(id);
    if (!StringUtils.equals(model.getPassword(), user.getPassword())) {
        // 如果更改了密码,新密码加密
        // model.encodePassword();
        PasswordHelper.encryptPassword(model);
    } else {
        // 保存之前的salt
        model.setSalt(user.getSalt());
    }
    model.setId(Long.valueOf(id.toString()));
    model.setDateModified(new Date());
    model = this.manager.save(model);
    if (!StringUtils.equals(model.getPassword(), user.getPassword())) {
        tokenManager.deleteToken(model.getId());
    }
    return model;
}
Also used : CurrentUser(com.topcom.cms.web.bind.annotation.CurrentUser) User(com.topcom.cms.domain.User)

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