Java tutorial
/* * Copyright 2017 Les Hazlewood and the respective Juiser contributors * * 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 org.juiser.spring.security.core; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.util.Assert; import java.util.Collection; /** * @since 1.0.0 */ public class ForwardedUserAuthentication implements Authentication { private final UserDetails details; public ForwardedUserAuthentication(UserDetails details) { Assert.notNull(details, "details argument cannot be null."); this.details = details; } @SuppressWarnings("unchecked") @Override public Collection<? extends GrantedAuthority> getAuthorities() { return details.getAuthorities(); } @Override public Object getCredentials() { return null; } @Override public Object getDetails() { return details; } @Override public Object getPrincipal() { return details; } @Override public boolean isAuthenticated() { return true; } @Override public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException { throw new IllegalArgumentException(getClass().getName() + " instances are immutable."); } @Override public String getName() { return details.getUsername(); } }