Search in sources :

Example 11 with User

use of com.ganster.cms.core.pojo.User in project Ganster-CMS by Gangster-trio.

the class PrivilegeController method judgeSite.

@GetMapping("/site")
public Message judgeSite(@RequestParam Integer siteId) {
    Integer userId = (Integer) SecurityUtils.getSubject().getSession().getAttribute("id");
    User user = userService.selectByPrimaryKey(userId);
    if (!"admin".equals(user.getUserName())) {
        if (PermissionUtil.permittedSite(userId, siteId)) {
            return super.buildMessage(0, "success", "yes");
        } else {
            return super.buildMessage(2, "no privilege", null);
        }
    } else {
        return super.buildMessage(0, "success", "yes");
    }
}
Also used : User(com.ganster.cms.core.pojo.User) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 12 with User

use of com.ganster.cms.core.pojo.User in project Ganster-CMS by Gangster-trio.

the class SystemSettingController method list.

// id代表站点id
@GetMapping("/list/{id}")
public List<SettingEntry> list(@PathVariable Integer id) {
    Integer userId = (Integer) SecurityUtils.getSubject().getSession().getAttribute("id");
    User user = userService.selectByPrimaryKey(userId);
    if (userId == null) {
        return null;
    } else {
        SettingEntryExample settingEntryExample = new SettingEntryExample();
        if (!user.getUserName().equals("admin")) {
            if (PermissionUtil.permittedModule(userId, id, 9, CmsConst.PERMISSION_READ)) {
                return settingService.selectByExample(settingEntryExample);
            } else {
                return null;
            }
        }
        return settingService.selectByExample(settingEntryExample);
    }
}
Also used : User(com.ganster.cms.core.pojo.User) SettingEntryExample(com.ganster.cms.core.pojo.SettingEntryExample)

Example 13 with User

use of com.ganster.cms.core.pojo.User in project Ganster-CMS by Gangster-trio.

the class InformationController method findInformation.

@GetMapping("/{UserId}")
public Message findInformation(@PathVariable("UserId") Integer userId) {
    Message message = new Message();
    InformationObject informationObject = new InformationObject();
    User user = userService.selectByPrimaryKey(userId);
    informationObject.setUserName(user.getUserName());
    informationObject.setUserPhone(user.getUserPhone());
    informationObject.setUserEmail(user.getUserEmail());
    informationObject.setUserStatus(user.getUserStatus());
    informationObject.setUserCreateTime(user.getUserCreateTime());
    informationObject.setUserOrg(user.getUserOrg());
    List<String> groupName = groupService.selectByUserId(userId).stream().map(group -> "<input type='text' disabled='disabled' value='" + group.getGroupName() + "'" + "class='layui-input'" + "/>").collect(Collectors.toList());
    informationObject.setUserGroup(groupName);
    message.setData(informationObject);
    return message;
}
Also used : Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Message(com.ganster.cms.admin.dto.Message) Collectors(java.util.stream.Collectors) UserService(com.ganster.cms.core.service.UserService) ArrayList(java.util.ArrayList) List(java.util.List) InformationObject(com.ganster.cms.admin.dto.InformationObject) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) User(com.ganster.cms.core.pojo.User) Group(com.ganster.cms.core.pojo.Group) GroupService(com.ganster.cms.core.service.GroupService) SecurityUtils(org.apache.shiro.SecurityUtils) User(com.ganster.cms.core.pojo.User) Message(com.ganster.cms.admin.dto.Message) InformationObject(com.ganster.cms.admin.dto.InformationObject)

Example 14 with User

use of com.ganster.cms.core.pojo.User in project Ganster-CMS by Gangster-trio.

the class UserShiroRealm method doGetAuthenticationInfo.

/**
 * 认证信息.(身份验证)
 * Authentication 是用来验证用户身份
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    String username = (String) token.getPrincipal();
    String password = new String((char[]) token.getCredentials());
    logger.debug("用户登录:{}  凭证:{}", username, password);
    UserExample userExample = new UserExample();
    userExample.createCriteria().andUserNameEqualTo(username);
    List<User> users = userService.selectByExample(userExample);
    if (users.isEmpty()) {
        throw new UnknownAccountException();
    }
    User user = users.get(0);
    if (!user.getUserPassword().equals(password)) {
        throw new IncorrectCredentialsException();
    }
    // 此方法废弃
    SecurityUtils.getSubject().getSession().setAttribute("id", user.getUserId());
    return new SimpleAuthenticationInfo(user, password, getName());
}
Also used : User(com.ganster.cms.core.pojo.User) UserExample(com.ganster.cms.core.pojo.UserExample)

Aggregations

User (com.ganster.cms.core.pojo.User)14 UserExample (com.ganster.cms.core.pojo.UserExample)7 Group (com.ganster.cms.core.pojo.Group)4 List (java.util.List)3 GetMapping (org.springframework.web.bind.annotation.GetMapping)3 Message (com.ganster.cms.admin.dto.Message)2 GroupNotFountException (com.ganster.cms.core.exception.GroupNotFountException)2 UserNotFoundException (com.ganster.cms.core.exception.UserNotFoundException)2 Permission (com.ganster.cms.core.pojo.Permission)2 GroupService (com.ganster.cms.core.service.GroupService)2 UserService (com.ganster.cms.core.service.UserService)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Collectors (java.util.stream.Collectors)2 SecurityUtils (org.apache.shiro.SecurityUtils)2 SimpleAuthorizationInfo (org.apache.shiro.authz.SimpleAuthorizationInfo)2 Subject (org.apache.shiro.subject.Subject)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 InformationObject (com.ganster.cms.admin.dto.InformationObject)1