shiver.me.timbers.security.spring.AuthenticatedAuthentication.java Source code

Java tutorial

Introduction

Here is the source code for shiver.me.timbers.security.spring.AuthenticatedAuthentication.java

Source

/*
 * Copyright 2015 Karl Bennett
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package shiver.me.timbers.security.spring;

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

import javax.security.auth.Subject;
import java.util.Collection;

import static java.util.Collections.emptySet;

/**
 * This is a very simple authentication is authenticated by default and contains no
 * {@link org.springframework.security.core.userdetails.UserDetails} or {@link GrantedAuthority}s.
 *
 * @author Karl Bennett
 */
public class AuthenticatedAuthentication implements Authentication {

    private final String principal;
    private boolean authenticated;

    public AuthenticatedAuthentication(String principal) {
        this.principal = principal;
        this.authenticated = true;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return emptySet();
    }

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

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

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

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

    @Override
    public void setAuthenticated(boolean authenticated) throws IllegalArgumentException {
        this.authenticated = authenticated;
    }

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

    public boolean implies(Subject subject) {
        return false;
    }
}