com.quincy.auth.service.impl.AuthorizationAbstract Maven / Gradle / Ivy
package com.quincy.auth.service.impl;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.Map.Entry;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import com.quincy.auth.entity.Menu;
import com.quincy.auth.entity.Permission;
import com.quincy.auth.entity.Role;
import com.quincy.auth.mapper.AuthMapper;
import com.quincy.auth.o.DSession;
import com.quincy.auth.o.User;
import com.quincy.auth.service.AuthorizationService;
public abstract class AuthorizationAbstract implements AuthorizationService {
protected abstract Object getUserObject(HttpServletRequest request) throws Exception;
protected abstract void saveVcode(HttpServletRequest request, String vcode) throws Exception;
public DSession getSession(HttpServletRequest request) throws Exception {
Object obj = this.getUserObject(request);
return obj==null?null:(DSession)obj;
}
private final static int width = 88;
private final static int height = 40;
private final static int lines = 5;
private final static String VCODE_COMBINATION_FROM = "23456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ";
public void vcode(HttpServletRequest request, HttpServletResponse response, int length) throws Exception {
Random random = new Random();
StringBuilder sb = new StringBuilder(length);
for(int i=0;i roleList = authMapper.findRolesByUserId(userId);
Map roleMap = new HashMap(roleList.size());
for(Role role:roleList) {//去重
roleMap.put(role.getId(), role.getName());
}
List roles = new ArrayList(roleMap.size());
roles.addAll(roleMap.values());
session.setRoles(roles);
//权限
List permissionList = authMapper.findPermissionsByUserId(userId);
Map permissionMap = new HashMap(permissionList.size());
for(Permission permission:permissionList) {//去重
permissionMap.put(permission.getId(), permission.getName());
}
List permissions = new ArrayList(permissionMap.size());
permissions.addAll(permissionMap.values());
session.setPermissions(permissions);
//菜单
List