diff --git a/examples/quickstart/src/main/java/org/springside/examples/quickstart/service/account/ShiroDbRealm.java b/examples/quickstart/src/main/java/org/springside/examples/quickstart/service/account/ShiroDbRealm.java index 7a94f0a5..fd817259 100644 --- a/examples/quickstart/src/main/java/org/springside/examples/quickstart/service/account/ShiroDbRealm.java +++ b/examples/quickstart/src/main/java/org/springside/examples/quickstart/service/account/ShiroDbRealm.java @@ -22,8 +22,6 @@ import java.io.Serializable; import javax.annotation.PostConstruct; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.shiro.authc.AuthenticationException; import org.apache.shiro.authc.AuthenticationInfo; import org.apache.shiro.authc.AuthenticationToken; @@ -39,6 +37,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springside.examples.quickstart.entity.User; import org.springside.modules.utils.Encodes; +import com.google.common.base.Objects; + public class ShiroDbRealm extends AuthorizingRealm { protected AccountService accountService; @@ -115,19 +115,31 @@ public class ShiroDbRealm extends AuthorizingRealm { } /** - * 重载equals,只计算loginName; + * 重载hashCode,只计算loginName; */ @Override public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this, "loginName"); + return Objects.hashCode(loginName); } /** - * 重载equals,只比较loginName + * 重载equals,只计算loginName; */ @Override public boolean equals(Object obj) { - return EqualsBuilder.reflectionEquals(this, obj, "loginName"); + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ShiroUser other = (ShiroUser) obj; + if (loginName == null) { + if (other.loginName != null) + return false; + } else if (!loginName.equals(other.loginName)) + return false; + return true; } } } diff --git a/examples/showcase/src/main/java/org/springside/examples/showcase/service/ShiroDbRealm.java b/examples/showcase/src/main/java/org/springside/examples/showcase/service/ShiroDbRealm.java index 90c7b488..93339f36 100644 --- a/examples/showcase/src/main/java/org/springside/examples/showcase/service/ShiroDbRealm.java +++ b/examples/showcase/src/main/java/org/springside/examples/showcase/service/ShiroDbRealm.java @@ -22,8 +22,6 @@ import java.io.Serializable; import javax.annotation.PostConstruct; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.shiro.authc.AuthenticationException; import org.apache.shiro.authc.AuthenticationInfo; import org.apache.shiro.authc.AuthenticationToken; @@ -41,6 +39,8 @@ import org.springside.examples.showcase.entity.Role; import org.springside.examples.showcase.entity.User; import org.springside.modules.utils.Encodes; +import com.google.common.base.Objects; + public class ShiroDbRealm extends AuthorizingRealm { protected AccountService accountService; @@ -125,19 +125,31 @@ public class ShiroDbRealm extends AuthorizingRealm { } /** - * 重载equals,只计算loginName; + * 重载hashCode,只计算loginName; */ @Override public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this, "loginName"); + return Objects.hashCode(loginName); } /** - * 重载equals,只比较loginName + * 重载equals,只计算loginName; */ @Override public boolean equals(Object obj) { - return EqualsBuilder.reflectionEquals(this, obj, "loginName"); + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ShiroUser other = (ShiroUser) obj; + if (loginName == null) { + if (other.loginName != null) + return false; + } else if (!loginName.equals(other.loginName)) + return false; + return true; } } }