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

com.github.yingzhuo.spring.security.jwt.JwtToken Maven / Gradle / Ivy

There is a newer version: 1.0.3
Show newest version
/*                 _                                            _ _                           _       _
 *  ___ _ __  _ __(_)_ __   __ _       ___  ___  ___ _   _ _ __(_) |_ _   _       _ __   __ _| |_ ___| |__
 * / __| '_ \| '__| | '_ \ / _` |_____/ __|/ _ \/ __| | | | '__| | __| | | |_____| '_ \ / _` | __/ __| '_ \
 * \__ \ |_) | |  | | | | | (_| |_____\__ \  __/ (__| |_| | |  | | |_| |_| |_____| |_) | (_| | || (__| | | |
 * |___/ .__/|_|  |_|_| |_|\__, |     |___/\___|\___|\__,_|_|  |_|\__|\__, |     | .__/ \__,_|\__\___|_| |_|
 *     |_|                 |___/                                      |___/      |_|
 *
 *  https://github.com/yingzhuo/spring-security-patch
 */
package com.github.yingzhuo.spring.security.jwt;

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

import java.util.Collection;
import java.util.Collections;

/**
 * @author 应卓
 * @since 1.0.0
 */
public final class JwtToken implements Authentication, java.io.Serializable {

    public static JwtToken of(String rawToken) {
        Assert.hasText(rawToken, () -> null);
        return new JwtToken(rawToken);
    }

    private final String rawToken;

    public String getRawToken() {
        return rawToken;
    }

    private JwtToken(String rawToken) {
        this.rawToken = rawToken;
    }

    @Override
    public Collection getAuthorities() {
        return Collections.emptySet();
    }

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

    @Override
    public boolean isAuthenticated() {
        return false;
    }

    @Override
    public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
        throw new UnsupportedOperationException();
    }

    @Override
    public Object getCredentials() {
        return this.rawToken;
    }

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

    @Override
    public String getName() {
        return null;
    }

    // -------------------------------------------------------------------------------------------------------------

    @Override
    public String toString() {
        return getRawToken();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy