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

com.bazaarvoice.emodb.auth.shiro.AnonymousToken Maven / Gradle / Ivy

There is a newer version: 6.5.190
Show newest version
package com.bazaarvoice.emodb.auth.shiro;

import org.apache.shiro.authc.AuthenticationToken;

/**
 * Special authentication token assigned to anonymous requests.
 */
public class AnonymousToken implements AuthenticationToken {

    final private static AnonymousToken _instance = new AnonymousToken();
    final private static String ANONYMOUS = "anonymous";

    public static AnonymousToken getInstance() {
        return _instance;
    }

    /**
     * Efficient check for whether a token is anonymous by performing instance comparison with the singleton.
     */
    public static boolean isAnonymous(AuthenticationToken token) {
        return token == _instance;
    }

    /**
     * Efficient check for whether a principal is anonymous by performing instance comparison with the singleton.
     */
    public static boolean isAnonymousPrincipal(Object principal) {
        return principal == ANONYMOUS;
    }

    private AnonymousToken() {
        // empty
    }

    @Override
    public Object getPrincipal() {
        return ANONYMOUS;
    }

    @Override
    public Object getCredentials() {
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy