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

org.apache.shiro.biz.authc.token.UsernameWithoutPwdToken Maven / Gradle / Ivy

There is a newer version: 2.0.0.RELEASE
Show newest version
package org.apache.shiro.biz.authc.token;

import org.apache.shiro.authc.HostAuthenticationToken;
import org.apache.shiro.authc.RememberMeAuthenticationToken;

@SuppressWarnings("serial")
public class UsernameWithoutPwdToken implements HostAuthenticationToken, RememberMeAuthenticationToken {

   /*--------------------------------------------
    |             C O N S T A N T S             |
    ============================================*/

   /*--------------------------------------------
    |    I N S T A N C E   V A R I A B L E S    |
    ============================================*/
    /**
     * The username
     */
    private String username;

    /**
     * Whether or not 'rememberMe' should be enabled for the corresponding login attempt;
     * default is false
     */
    private boolean rememberMe = false;

    /**
     * The location from where the login attempt occurs, or null if not known or explicitly
     * omitted.
     */
    private String host;

   /*--------------------------------------------
    |         C O N S T R U C T O R S           |
    ============================================*/

    public UsernameWithoutPwdToken() {
    }

    public UsernameWithoutPwdToken(final String username) {
        this(username, false, null);
    }

     
    public UsernameWithoutPwdToken(final String username, final boolean rememberMe) {
        this(username, rememberMe, null);
    }

    public UsernameWithoutPwdToken(final String username, final boolean rememberMe, final String host) {
        this.username = username;
        this.rememberMe = rememberMe;
        this.host = host;
    }

   /*--------------------------------------------
    |  A C C E S S O R S / M O D I F I E R S    |
    ============================================*/

    /**
     * Returns the username submitted during an authentication attempt.
     *
     * @return the username submitted during an authentication attempt.
     */
    public String getUsername() {
        return username;
    }

    /**
     * Sets the username for submission during an authentication attempt.
     *
     * @param username the username to be used for submission during an authentication attempt.
     */
    public void setUsername(String username) {
        this.username = username;
    }

    /**
     * Simply returns {@link #getUsername() getUsername()}.
     *
     * @return the {@link #getUsername() username}.
     * @see org.apache.shiro.authc.AuthenticationToken#getPrincipal()
     */
    @Override
    public Object getPrincipal() {
        return getUsername();
    }

    /**
     * Returns the password char array.
     * @return the password char array.
     * @see org.apache.shiro.authc.AuthenticationToken#getCredentials()
     */
    @Override
    public Object getCredentials() {
        return null;
    }

    /**
     * Returns the host name or IP string from where the authentication attempt occurs.  May be null if the
     * host name/IP is unknown or explicitly omitted.  It is up to the Authenticator implementation processing this
     * token if an authentication attempt without a host is valid or not.
     * 

(Shiro's default Authenticator allows null hosts to support localhost and proxy server environments).

* * @return the host from where the authentication attempt occurs, or null if it is unknown or * explicitly omitted. * @since 1.0 */ @Override public String getHost() { return host; } /** * Sets the host name or IP string from where the authentication attempt occurs. It is up to the Authenticator * implementation processing this token if an authentication attempt without a host is valid or not. *

(Shiro's default Authenticator * allows null hosts to allow localhost and proxy server environments).

* * @param host the host name or IP string from where the attempt is occurring * @since 1.0 */ public void setHost(String host) { this.host = host; } /** * Returns true if the submitting user wishes their identity (principal(s)) to be remembered * across sessions, false otherwise. Unless overridden, this value is false by default. * * @return true if the submitting user wishes their identity (principal(s)) to be remembered * across sessions, false otherwise (false by default). * @since 0.9 */ @Override public boolean isRememberMe() { return rememberMe; } /** * Sets if the submitting user wishes their identity (principal(s)) to be remembered across sessions. Unless * overridden, the default value is false, indicating not to be remembered across sessions. * * @param rememberMe value indicating if the user wishes their identity (principal(s)) to be remembered across * sessions. * @since 0.9 */ public void setRememberMe(boolean rememberMe) { this.rememberMe = rememberMe; } /*-------------------------------------------- | M E T H O D S | ============================================*/ /** * Clears out (nulls) the username, password, rememberMe, and inetAddress. The password bytes are explicitly set to * 0x00 before nulling to eliminate the possibility of memory access at a later time. */ public void clear() { this.username = null; this.host = null; this.rememberMe = false; } /** * Returns the String representation. It does not include the password in the resulting * string for security reasons to prevent accidentally printing out a password * that might be widely viewable). * * @return the String representation of the UsernamePasswordToken, omitting * the password. */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(getClass().getName()); sb.append(" - "); sb.append(username); sb.append(", rememberMe=").append(rememberMe); if (host != null) { sb.append(" (").append(host).append(")"); } return sb.toString(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy