All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.base4j.mvc.auth.UserAuthority Maven / Gradle / Ivy

There is a newer version: 1.3.0
Show newest version
package com.base4j.mvc.auth;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.util.Assert;

import java.io.Serializable;

public class UserAuthority implements GrantedAuthority, Serializable {

    private final String role;
    private final Long roleId;

    public UserAuthority(String role, Long roleId) {
        Assert.hasText(role, "A granted authority textual representation is required");
        Assert.notNull(roleId, "A granted authority roleId representation is required");
        this.role = role;
        this.roleId = roleId;
    }


    public Long getRoleId() {
        return roleId;
    }

    @Override
    public String getAuthority() {
        return role;
    }

    @Override
    public int hashCode() {
        return 31 ^ roleId.hashCode() ^ role.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof UserAuthority) {
            UserAuthority ua = (UserAuthority) obj;
            return this.role.equals(ua.role) && this.roleId.equals(ua.roleId);
        }
        return false;
    }

    @Override
    public String toString() {
        return "UserAuthority{" +
                "role='" + role + '\'' +
                ", roleId=" + roleId +
                '}';
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy