pigx-common-security
This commit is contained in:
parent
eb85bcc8c2
commit
f4f312cecd
|
|
@ -1,8 +1,8 @@
|
|||
package com.pig4cloud.pigx.common.security.service;
|
||||
|
||||
import java.io.Serializable;
|
||||
import lombok.Generated;
|
||||
|
||||
public class PigxUser implements Serializable {
|
||||
public class PigxUser {
|
||||
private Long id;
|
||||
private Long merchantId;
|
||||
private Long canteenEffId;
|
||||
|
|
@ -11,39 +11,212 @@ public class PigxUser implements Serializable {
|
|||
private String roleCode;
|
||||
private String username;
|
||||
|
||||
@Generated
|
||||
public static PigxUserBuilder builder() {
|
||||
return new PigxUserBuilder();
|
||||
}
|
||||
|
||||
@Generated
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Generated
|
||||
public Long getMerchantId() {
|
||||
return this.merchantId;
|
||||
}
|
||||
|
||||
@Generated
|
||||
public Long getCanteenEffId() {
|
||||
return this.canteenEffId;
|
||||
}
|
||||
|
||||
@Generated
|
||||
public Long getCustEffId() {
|
||||
return this.custEffId;
|
||||
}
|
||||
|
||||
@Generated
|
||||
public Long getDishesEffId() {
|
||||
return this.dishesEffId;
|
||||
}
|
||||
|
||||
@Generated
|
||||
public String getRoleCode() {
|
||||
return this.roleCode;
|
||||
}
|
||||
|
||||
@Generated
|
||||
public String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
@Generated
|
||||
public void setId(final Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Generated
|
||||
public void setMerchantId(final Long merchantId) {
|
||||
this.merchantId = merchantId;
|
||||
}
|
||||
|
||||
@Generated
|
||||
public void setCanteenEffId(final Long canteenEffId) {
|
||||
this.canteenEffId = canteenEffId;
|
||||
}
|
||||
|
||||
@Generated
|
||||
public void setCustEffId(final Long custEffId) {
|
||||
this.custEffId = custEffId;
|
||||
}
|
||||
|
||||
@Generated
|
||||
public void setDishesEffId(final Long dishesEffId) {
|
||||
this.dishesEffId = dishesEffId;
|
||||
}
|
||||
|
||||
@Generated
|
||||
public void setRoleCode(final String roleCode) {
|
||||
this.roleCode = roleCode;
|
||||
}
|
||||
|
||||
@Generated
|
||||
public void setUsername(final String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
@Generated
|
||||
public boolean equals(final Object o) {
|
||||
if (o == this) {
|
||||
return true;
|
||||
} else if (!(o instanceof PigxUser)) {
|
||||
return false;
|
||||
} else {
|
||||
PigxUser other = (PigxUser)o;
|
||||
if (!other.canEqual(this)) {
|
||||
return false;
|
||||
} else {
|
||||
label95: {
|
||||
Object this$id = this.getId();
|
||||
Object other$id = other.getId();
|
||||
if (this$id == null) {
|
||||
if (other$id == null) {
|
||||
break label95;
|
||||
}
|
||||
} else if (this$id.equals(other$id)) {
|
||||
break label95;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Object this$merchantId = this.getMerchantId();
|
||||
Object other$merchantId = other.getMerchantId();
|
||||
if (this$merchantId == null) {
|
||||
if (other$merchantId != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!this$merchantId.equals(other$merchantId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Object this$canteenEffId = this.getCanteenEffId();
|
||||
Object other$canteenEffId = other.getCanteenEffId();
|
||||
if (this$canteenEffId == null) {
|
||||
if (other$canteenEffId != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!this$canteenEffId.equals(other$canteenEffId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
label74: {
|
||||
Object this$custEffId = this.getCustEffId();
|
||||
Object other$custEffId = other.getCustEffId();
|
||||
if (this$custEffId == null) {
|
||||
if (other$custEffId == null) {
|
||||
break label74;
|
||||
}
|
||||
} else if (this$custEffId.equals(other$custEffId)) {
|
||||
break label74;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
label67: {
|
||||
Object this$dishesEffId = this.getDishesEffId();
|
||||
Object other$dishesEffId = other.getDishesEffId();
|
||||
if (this$dishesEffId == null) {
|
||||
if (other$dishesEffId == null) {
|
||||
break label67;
|
||||
}
|
||||
} else if (this$dishesEffId.equals(other$dishesEffId)) {
|
||||
break label67;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Object this$roleCode = this.getRoleCode();
|
||||
Object other$roleCode = other.getRoleCode();
|
||||
if (this$roleCode == null) {
|
||||
if (other$roleCode != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!this$roleCode.equals(other$roleCode)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Object this$username = this.getUsername();
|
||||
Object other$username = other.getUsername();
|
||||
if (this$username == null) {
|
||||
if (other$username != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!this$username.equals(other$username)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Generated
|
||||
protected boolean canEqual(final Object other) {
|
||||
return other instanceof PigxUser;
|
||||
}
|
||||
|
||||
@Generated
|
||||
public int hashCode() {
|
||||
int PRIME = true;
|
||||
int result = 1;
|
||||
Object $id = this.getId();
|
||||
result = result * 59 + ($id == null ? 43 : $id.hashCode());
|
||||
Object $merchantId = this.getMerchantId();
|
||||
result = result * 59 + ($merchantId == null ? 43 : $merchantId.hashCode());
|
||||
Object $canteenEffId = this.getCanteenEffId();
|
||||
result = result * 59 + ($canteenEffId == null ? 43 : $canteenEffId.hashCode());
|
||||
Object $custEffId = this.getCustEffId();
|
||||
result = result * 59 + ($custEffId == null ? 43 : $custEffId.hashCode());
|
||||
Object $dishesEffId = this.getDishesEffId();
|
||||
result = result * 59 + ($dishesEffId == null ? 43 : $dishesEffId.hashCode());
|
||||
Object $roleCode = this.getRoleCode();
|
||||
result = result * 59 + ($roleCode == null ? 43 : $roleCode.hashCode());
|
||||
Object $username = this.getUsername();
|
||||
result = result * 59 + ($username == null ? 43 : $username.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Generated
|
||||
public String toString() {
|
||||
Long var10000 = this.getId();
|
||||
return "PigxUser(id=" + var10000 + ", merchantId=" + this.getMerchantId() + ", canteenEffId=" + this.getCanteenEffId() + ", custEffId=" + this.getCustEffId() + ", dishesEffId=" + this.getDishesEffId() + ", roleCode=" + this.getRoleCode() + ", username=" + this.getUsername() + ")";
|
||||
}
|
||||
|
||||
@Generated
|
||||
public PigxUser(final Long id, final Long merchantId, final Long canteenEffId, final Long custEffId, final Long dishesEffId, final String roleCode, final String username) {
|
||||
this.id = id;
|
||||
this.merchantId = merchantId;
|
||||
|
|
@ -54,88 +227,79 @@ public class PigxUser implements Serializable {
|
|||
this.username = username;
|
||||
}
|
||||
|
||||
@Generated
|
||||
public PigxUser() {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public Long getMerchantId() {
|
||||
return this.merchantId;
|
||||
}
|
||||
|
||||
public Long getCanteenEffId() {
|
||||
return this.canteenEffId;
|
||||
}
|
||||
|
||||
public Long getCustEffId() {
|
||||
return this.custEffId;
|
||||
}
|
||||
|
||||
public Long getDishesEffId() {
|
||||
return this.dishesEffId;
|
||||
}
|
||||
|
||||
public String getRoleCode() {
|
||||
return this.roleCode;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
@Generated
|
||||
public static class PigxUserBuilder {
|
||||
@Generated
|
||||
private Long id;
|
||||
@Generated
|
||||
private Long merchantId;
|
||||
@Generated
|
||||
private Long canteenEffId;
|
||||
@Generated
|
||||
private Long custEffId;
|
||||
@Generated
|
||||
private Long dishesEffId;
|
||||
@Generated
|
||||
private String roleCode;
|
||||
@Generated
|
||||
private String username;
|
||||
|
||||
@Generated
|
||||
PigxUserBuilder() {
|
||||
}
|
||||
|
||||
@Generated
|
||||
public PigxUserBuilder id(final Long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Generated
|
||||
public PigxUserBuilder merchantId(final Long merchantId) {
|
||||
this.merchantId = merchantId;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Generated
|
||||
public PigxUserBuilder canteenEffId(final Long canteenEffId) {
|
||||
this.canteenEffId = canteenEffId;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Generated
|
||||
public PigxUserBuilder custEffId(final Long custEffId) {
|
||||
this.custEffId = custEffId;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Generated
|
||||
public PigxUserBuilder dishesEffId(final Long dishesEffId) {
|
||||
this.dishesEffId = dishesEffId;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Generated
|
||||
public PigxUserBuilder roleCode(final String roleCode) {
|
||||
this.roleCode = roleCode;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Generated
|
||||
public PigxUserBuilder username(final String username) {
|
||||
this.username = username;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Generated
|
||||
public PigxUser build() {
|
||||
return new PigxUser(this.id, this.merchantId, this.canteenEffId, this.custEffId, this.dishesEffId, this.roleCode, this.username);
|
||||
}
|
||||
|
||||
@Generated
|
||||
public String toString() {
|
||||
return "PigxUser.PigxUserBuilder(id=" + this.id + ", merchantId=" + this.merchantId + ", canteenEffId=" + this.canteenEffId + ", custEffId=" + this.custEffId + ", dishesEffId=" + this.dishesEffId + ", roleCode=" + this.roleCode + ", username=" + this.username + ")";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,19 +4,21 @@ import cn.hutool.core.collection.CollUtil;
|
|||
import com.pig4cloud.pigx.common.security.service.PigxUser;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.xnzn.framework.secure.SecureManager;
|
||||
import lombok.Generated;
|
||||
import net.xnzn.framework.secure.token.TokenManager;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public final class SecurityUtils {
|
||||
public static PigxUser getUser() {
|
||||
Map<String, String> subjectData = SecureManager.getSubjectData();
|
||||
return new PigxUser((Long)SecureManager.getSubjectId().orElse((Long) null), StringUtils.isBlank((CharSequence)subjectData.get("merchantId")) ? null : Long.parseLong((String)subjectData.get("merchantId")), StringUtils.isBlank((CharSequence)subjectData.get("canteenEffId")) ? null : Long.parseLong((String)subjectData.get("canteenEffId")), StringUtils.isBlank((CharSequence)subjectData.get("custEffId")) ? null : Long.parseLong((String)subjectData.get("custEffId")), StringUtils.isBlank((CharSequence)subjectData.get("dishesEffId")) ? null : Long.parseLong((String)subjectData.get("dishesEffId")), CollUtil.isEmpty(SecureManager.getRole()) ? null : (String)SecureManager.getRole().stream().findFirst().get(), (String)subjectData.getOrDefault("username", ""));
|
||||
Map<String, String> subjectData = TokenManager.getSubjectData();
|
||||
return new PigxUser((Long)TokenManager.getSubjectId().orElse((Object)null), StringUtils.isBlank((CharSequence)subjectData.get("merchantId")) ? null : Long.parseLong((String)subjectData.get("merchantId")), StringUtils.isBlank((CharSequence)subjectData.get("canteenEffId")) ? null : Long.parseLong((String)subjectData.get("canteenEffId")), StringUtils.isBlank((CharSequence)subjectData.get("custEffId")) ? null : Long.parseLong((String)subjectData.get("custEffId")), StringUtils.isBlank((CharSequence)subjectData.get("dishesEffId")) ? null : Long.parseLong((String)subjectData.get("dishesEffId")), CollUtil.isEmpty(TokenManager.getRole()) ? null : (String)TokenManager.getRole().stream().findFirst().get(), (String)subjectData.getOrDefault("username", ""));
|
||||
}
|
||||
|
||||
public static List<Integer> getRoles() {
|
||||
return SecureManager.getRole().stream().map(Integer::parseInt).toList();
|
||||
return TokenManager.getRole().stream().map(Integer::parseInt).toList();
|
||||
}
|
||||
|
||||
@Generated
|
||||
private SecurityUtils() {
|
||||
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue