728x90

UserDetails 클래스

public interface UserDetails extends Serializable {

    /**
     * Returns the authorities granted to the user. Cannot return <code>null</code>.
     * @return the authorities, sorted by natural key (never <code>null</code>)
     */
    Collection<? extends GrantedAuthority> getAuthorities();

    /**
     * Returns the password used to authenticate the user.
     * @return the password
     */
    String getPassword();

    /**
     * Returns the username used to authenticate the user. Cannot return
     * <code>null</code>.
     * @return the username (never <code>null</code>)
     */
    String getUsername();

    /**
     * Indicates whether the user's account has expired. An expired account cannot be
     * authenticated.
     * @return <code>true</code> if the user's account is valid (ie non-expired),
     * <code>false</code> if no longer valid (ie expired)
     */
    boolean isAccountNonExpired();

    /**
     * Indicates whether the user is locked or unlocked. A locked user cannot be
     * authenticated.
     * @return <code>true</code> if the user is not locked, <code>false</code> otherwise
     */
    boolean isAccountNonLocked();

    /**
     * Indicates whether the user's credentials (password) has expired. Expired
     * credentials prevent authentication.
     * @return <code>true</code> if the user's credentials are valid (ie non-expired),
     * <code>false</code> if no longer valid (ie expired)
     */
    boolean isCredentialsNonExpired();

    /**
     * Indicates whether the user is enabled or disabled. A disabled user cannot be
     * authenticated.
     * @return <code>true</code> if the user is enabled, <code>false</code> otherwise
     */
    boolean isEnabled();

}

getAuthorities : 유저의 권한 또는 역할 목록 보유, 이를 사용하여 권한 부여 또는 역할 기반 액세스 메커니즘 구현 가능
getPassword, getUsername : 유저의 비밀번호와 유저 이름 반환
isAccountNonExpired : 유저 계정이 만료되었는지 확인
isAccountNonLocked : 유저 계정이 잠겨있는지 확인
isCredentialsNonExpired : 유저 자격 증명이 만료되었는지 확인
isEnabled : 유저 계정이 활성 / 비활성화되었는지 확인


package org.springframework.security.core.userdetails.User
위 패키지를 참조하면, User를 기본 제공하며 필요한 경우 해당 클래스를 참고하여 본인만의 User Class를 구현할 수 있음.


UserDetails 인터페이스의 구성을 보면 Get 관련 메서드만 존재하고 있는데, 이는 보안과 관련이 있어 생성자를 사용하여 객체를 만든 이후에는 setter를 사용하여 값을 수정할 수 없도록 설계되어 있음.

반응형
코드플리