Java tutorial
/** * Copyright © 2012-2013 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); */ package com.test.edusys.common.utils; import java.util.List; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.SecurityUtils; import org.apache.shiro.subject.Subject; import com.test.edusys.common.service.MonitorRealm.Principal; import com.test.edusys.system.model.User; import com.test.edusys.system.model.UserRole; /** * */ public class UserUtils { /** * ?? * @return */ public static boolean isAdmin() { Subject currentUser = SecurityUtils.getSubject(); User user = (User) currentUser.getSession().getAttribute("currentUser"); if (user == null) { throw new RuntimeException(""); } List<UserRole> list = user.getUserRoles(); for (UserRole userRole : list) { if (userRole.getRoleid() == 3) { return true; } } return false; } public static User getUser() { Subject currentUser = SecurityUtils.getSubject(); User user = (User) currentUser.getSession().getAttribute("currentUser"); if (user == null) { throw new RuntimeException(""); } return user; } public static Principal getPrincipal() { Subject subject = SecurityUtils.getSubject(); Principal principal = (Principal) subject.getPrincipal(); return principal; } public static String hiddenTelephone(String yddh) { if (StringUtils.isNotBlank(yddh)) { int len = yddh.length(); if (len >= 4) { String lastFour = yddh.substring(len - 4, len - 1); return yddh.replace(lastFour, "****"); } } return ""; } }