This commit is contained in:
shimingxy
2019-06-28 07:33:01 +08:00
parent 94806a2fc4
commit b2d376f960
1488 changed files with 85167 additions and 129897 deletions

View File

@@ -69,7 +69,7 @@ public class RealmAuthenticationProvider extends AbstractAuthenticationProvider
UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken =new UsernamePasswordAuthenticationToken(
auth,
"PASSWORD",
authenticationRealm.grantAuthorityAndNavs(userInfo));
authenticationRealm.grantAuthority(userInfo));
usernamePasswordAuthenticationToken.setDetails(new WebAuthenticationDetails(WebContext.getRequest()));
return usernamePasswordAuthenticationToken;

View File

@@ -16,9 +16,8 @@ import org.maxkey.authn.support.rememberme.AbstractRemeberMeService;
import org.maxkey.constants.LOGINTYPE;
import org.maxkey.constants.PASSWORDSETTYPE;
import org.maxkey.constants.STATUS;
import org.maxkey.domain.Navigations;
import org.maxkey.domain.Groups;
import org.maxkey.domain.PasswordPolicy;
import org.maxkey.domain.Roles;
import org.maxkey.domain.UserInfo;
import org.maxkey.persistence.db.PasswordPolicyRowMapper;
import org.maxkey.persistence.db.UserInfoRowMapper;
@@ -60,9 +59,7 @@ public abstract class AbstractAuthenticationRealm{
private static final String HISTORY_LOGOUT_UPDATE_STATEMENT = "UPDATE LOGIN_HISTORY SET LOGOUTTIME = ? WHERE SESSIONID = ?";
private static final String NAVIGATIONS_SELECT_STATEMENT = "SELECT DISTINCT N.* FROM ROLE_NAV RN, NAVIGATIONS N WHERE RN.ROLEID IN(SELECT R.ID FROM ROLES R WHERE ( R.ID='ORDINARY_USER' OR R.ID IN(SELECT ROLEID FROM USERINFO U, ROLE_USER RU WHERE U.ID = ? AND U.ID = RU.UID AND U.STATUS = 1)) AND R.STATUS = 1) AND RN.NAVID=N.ID AND N.STATUS = 1 ORDER BY PID, SORTORDER";
private static final String ROLES_SELECT_STATEMENT = "SELECT DISTINCT R.ID,R.NAME FROM USERINFO U,ROLES R,ROLE_USER RU WHERE U.ID = ? AND U.ID=RU.UID AND RU.ROLEID=R.ID AND R.STATUS<>'2'";
private static final String GROUPS_SELECT_STATEMENT = "SELECT DISTINCT G.ID,G.NAME FROM USERINFO U,GROUPS G,GROUP_MEMBER GM WHERE U.ID = ? AND U.ID=GM.MEMBERID AND GM.GROUPID=G.ID ";
private static final String DEFAULT_USERINFO_SELECT_STATEMENT = "SELECT * FROM USERINFO WHERE USERNAME = ?";
@@ -249,59 +246,18 @@ public abstract class AbstractAuthenticationRealm{
}
}
public List<Navigations> queryNavs(UserInfo userInfo){
List<Navigations> listNavigations=jdbcTemplate.query(NAVIGATIONS_SELECT_STATEMENT, new RowMapper<Navigations>() {
public Navigations mapRow(ResultSet rs, int rowNum) throws SQLException {
Navigations navigation=new Navigations();
navigation.setId(rs.getString("ID"));
navigation.setName(rs.getString("NAME"));
navigation.setUrl(rs.getString("URL"));
navigation.setType(rs.getString("TYPE"));
navigation.setTarget(rs.getString("TARGET"));
navigation.setpId(rs.getString("PID"));
navigation.setpName(rs.getString("PNAME"));
navigation.setxPath(rs.getString("XPATH"));
navigation.setHasChild(rs.getString("HASCHILD"));
navigation.setVisible(rs.getInt("VISIBLE"));
return navigation;
public List<Groups> queryGroups(UserInfo userInfo) {
List<Groups> listGroups=jdbcTemplate.query(GROUPS_SELECT_STATEMENT, new RowMapper<Groups>() {
public Groups mapRow(ResultSet rs, int rowNum) throws SQLException {
Groups group=new Groups(rs.getString("ID"),rs.getString("NAME"),0);
return group;
}
},userInfo.getId());
_logger.debug("list Navigations "+listNavigations);
return listNavigations;
_logger.debug("list Groups "+listGroups);
return listGroups;
}
public List<Roles> queryRoles(UserInfo userInfo) {
List<Roles> listRoles=jdbcTemplate.query(ROLES_SELECT_STATEMENT, new RowMapper<Roles>() {
public Roles mapRow(ResultSet rs, int rowNum) throws SQLException {
Roles role=new Roles();
role.setId(rs.getString("ID"));
role.setName(rs.getString("NAME"));
return role;
}
},userInfo.getId());
_logger.debug("list Roles "+listRoles);
return listRoles;
}
/**
* Granted Authority And Navs by userInfo
* @param userInfo
* @return ArrayList<GrantedAuthority>
*/
public ArrayList<GrantedAuthority> grantAuthorityAndNavs(UserInfo userInfo){
//call grantAuthority
ArrayList<GrantedAuthority> grantedAuthority = grantAuthority(userInfo);
//call grantNavs
grantNavs(userInfo);
return grantedAuthority;
}
/**
* grant Authority by userinfo
@@ -310,35 +266,19 @@ public abstract class AbstractAuthenticationRealm{
*/
public ArrayList<GrantedAuthority> grantAuthority(UserInfo userInfo){
//query roles for user
List<Roles> listRoles=queryRoles(userInfo);
List<Groups> listGroups=queryGroups(userInfo);
//set role for spring security
ArrayList<GrantedAuthority> grantedAuthority = new ArrayList<GrantedAuthority>();
grantedAuthority.add(new SimpleGrantedAuthority("ROLE_USER"));
grantedAuthority.add(new SimpleGrantedAuthority("ORDINARY_USER"));
for(Roles role :listRoles){
grantedAuthority.add(new SimpleGrantedAuthority(role.getId()));
for(Groups group :listGroups){
grantedAuthority.add(new SimpleGrantedAuthority(group.getId()));
}
_logger.debug("Authority : "+grantedAuthority);
WebContext.setRoles(listRoles);
return grantedAuthority;
}
/**
* grant Navs by userinfo
* @param userInfo
* @return List<Menus>
*/
public List<Navigations> grantNavs(UserInfo userInfo){
//query menus for user
List<Navigations> listNavs =queryNavs(userInfo);
WebContext.setNavigations(listNavs);
return listNavs;
}
/**
* login log write to log db
* @param uid

View File

@@ -26,6 +26,13 @@ public class Groups extends JpaBaseDomain implements Serializable{
this.id = id;
}
public Groups(String id, String name, int isdefault) {
super();
this.id = id;
this.name = name;
this.isdefault = isdefault;
}
public String getName(){
return name;
}
@@ -35,6 +42,14 @@ public class Groups extends JpaBaseDomain implements Serializable{
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public int getIsdefault(){
return isdefault;
}

View File

@@ -1,5 +1,10 @@
package org.maxkey.domain;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import org.apache.mybatis.jpa.persistence.JpaBaseDomain;
@@ -11,66 +16,79 @@ import org.maxkey.exception.PasswordPolicyException;
*
*/
@Table(name = "PASSWORD_POLICY")
public class PasswordPolicy extends JpaBaseDomain implements java.io.Serializable {
private static final long serialVersionUID = -4797776994287829182L;
@Id
@Column
@GeneratedValue(strategy=GenerationType.AUTO,generator="uuid")
String id;
/**
* minimum password lengths
*/
@NotNull
@Column
private int minLength;
/**
* maximum password lengths
*/
@NotNull
@Column
private int maxLength;
/**
* least lowercase letter
*/
@NotNull
@Column
private int lowerCase;
/**
* least uppercase letter
*/
@NotNull
@Column
private int upperCase;
/**
* inclusion of numerical digits
*/
@NotNull
@Column
private int digits;
/**
* inclusion of special characters
*/
@NotNull
@Column
private int specialChar;
/**
* correct password attempts
*/
@NotNull
@Column
private int attempts;
/**
* attempts lock Duration
*/
@NotNull
@Column
private int duration;
/**
* require users to change passwords periodically
*/
@Column
private int expiration;
/**
* 0 no
* 1 yes
*/
@Column
private int username;
/**
* not include password list
*/
@Column
private String simplePasswords;

View File

@@ -1,77 +0,0 @@
package org.maxkey.domain;
import java.io.Serializable;
import org.apache.mybatis.jpa.persistence.JpaBaseDomain;
import org.hibernate.validator.constraints.NotEmpty;
/*
ID varchar(40) not null,
ROLEID varchar(40) null,
MENUID varchar(40) null
constraint PK_ROLES primary key clustered (ID)
*/
/**
* @author Crystal.Sea
*
*/
public class RoleNav extends JpaBaseDomain implements Serializable{
/**
*
*/
private static final long serialVersionUID = 3461258339474457017L;
String id;
@NotEmpty
private String roleId;
@NotEmpty
private String navId;
public RoleNav(){
super();
}
public RoleNav(String roleId, String navId) {
super();
this.roleId = roleId;
this.navId = navId;
}
public String getRoleId() {
return roleId;
}
public void setRoleId(String roleId) {
this.roleId = roleId;
}
public String getNavId() {
return navId;
}
public void setNavId(String navId) {
this.navId = navId;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "RoleNav [roleId=" + roleId + ", navId=" + navId + "]";
}
}

View File

@@ -1,76 +0,0 @@
package org.maxkey.domain;
import java.io.Serializable;
import org.hibernate.validator.constraints.NotEmpty;
/*
ID varchar(40) not null,
ROLEID varchar(40) null,
UID varchar(40) null
constraint PK_ROLES primary key clustered (ID)
*/
/**
* @author Crystal.Sea
*
*/
public class RoleUser extends UserInfo implements Serializable{
/**
*
*/
private static final long serialVersionUID = 3840528281795495533L;
/**
*
*/
@NotEmpty
private String roleId;
@NotEmpty
private String uid;
public RoleUser(){
super();
}
public RoleUser(String roleId, String uid) {
super();
this.roleId = roleId;
this.uid = uid;
}
public String getRoleId() {
return roleId;
}
public void setRoleId(String roleId) {
this.roleId = roleId;
}
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "RoleUser [roleId=" + roleId + ", uid=" + uid + "]";
}
}

View File

@@ -1,104 +0,0 @@
package org.maxkey.domain;
import java.io.Serializable;
import org.apache.mybatis.jpa.persistence.JpaBaseDomain;
/*
ID varchar(40) not null,
NAME varchar(60) not null,
STATUS char(1) null,
CREATEBY varchar(40) null,
CREATEDATE date null,
UPDATEBY varchar(40) null,
UPDATEDATE date null,
constraint PK_ROLES primary key clustered (ID)
*/
/**
* @author Crystal.Sea
*
*/
public class Roles extends JpaBaseDomain implements Serializable{
/**
*
*/
private static final long serialVersionUID = -6928570405840778151L;
String id;
private String name;
private String navsId;
int status;
public Roles() {
super();
}
public Roles(String name, String navsId) {
super();
this.name = name;
this.navsId = navsId;
}
/**
* @return the status
*/
public int getStatus() {
return status;
}
/**
* @param status the status to set
*/
public void setStatus(int status) {
this.status = status;
}
/**
* @return the id
*/
public String getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNavsId() {
return navsId;
}
public void setNavsId(String navsId) {
this.navsId = navsId;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Roles [name=" + name + ", navsId=" + navsId + "]";
}
}

View File

@@ -1,7 +1,6 @@
package org.maxkey.web;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
@@ -10,8 +9,6 @@ import javax.servlet.http.HttpSession;
import org.apache.commons.logging.LogFactory;
import org.maxkey.authn.realm.AbstractAuthenticationRealm;
import org.maxkey.config.ApplicationConfig;
import org.maxkey.domain.Navigations;
import org.maxkey.domain.Roles;
import org.maxkey.domain.UserInfo;
import org.maxkey.util.DateUtils;
import org.maxkey.util.StringGenerator;
@@ -53,58 +50,6 @@ public final class WebContext {
public static UserInfo getUserInfo() {
return ((UserInfo)getAttribute(WebConstants.CURRENT_USER));
}
/**
* set current login user's can access menus list to session
* @see WebConstants.CURRENT_USER_MENUS
* @param listMenus
*/
public static void setNavigations(List<Navigations> listNavigations) {
setAttribute(WebConstants.CURRENT_USER_NAVIGATIONS,listNavigations);
}
/**
* get current login user's can access menus list from session
* @see WebConstants.CURRENT_USER_MENUS
* @return List<Menus>
*/
@SuppressWarnings("unchecked")
public static List<Navigations> getNavigations() {
List<Navigations> listNavigations=null;
if(getAttribute(WebConstants.CURRENT_USER_NAVIGATIONS)==null){
UserInfo userInfo =getUserInfo();
if(userInfo!=null){
//MenusService menusService = (MenusService)getBean("menusService");
//listMenus=menusService.getMenusByUserId(userInfo.getId());
setNavigations(listNavigations);
}
}else{
listNavigations = (List<Navigations>)getAttribute(WebConstants.CURRENT_USER_NAVIGATIONS);
}
return listNavigations;
}
/**
* set current login user's roles to session
* @see WebConstants.CURRENT_USER_SYSTEM_ROLES
* @param listRoles
*/
public static void setRoles(List<Roles> listRoles) {
setAttribute(WebConstants.CURRENT_USER_SYSTEM_ROLES,listRoles);
}
/**
* get current login user has Roles from session
* @see WebConstants.CURRENT_USER_SYSTEM_ROLES
* @return List<Roles>
*/
@SuppressWarnings("unchecked")
public static List<Roles> getRoles() {
List<Roles> list = (List<Roles>)getAttribute(WebConstants.CURRENT_USER_SYSTEM_ROLES);
return list;
}
/**
@@ -138,7 +83,7 @@ public final class WebContext {
UserInfo loadeduserInfo = authenticationRealm.loadUserInfo(username,"");
if (loadeduserInfo != null)
{
ArrayList<GrantedAuthority> grantedAuthority = authenticationRealm.grantAuthorityAndNavs(loadeduserInfo);
ArrayList<GrantedAuthority> grantedAuthority = authenticationRealm.grantAuthority(loadeduserInfo);
setUserInfo(loadeduserInfo);
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(loadeduserInfo.getUsername(), loadeduserInfo.getPassword(), grantedAuthority);