001/* 002 * Licensed under the Apache License, Version 2.0 (the "License"); 003 * you may not use this file except in compliance with the License. 004 * You may obtain a copy of the License at 005 * 006 * http://www.apache.org/licenses/LICENSE-2.0 007 * 008 * Unless required by applicable law or agreed to in writing, software 009 * distributed under the License is distributed on an "AS IS" BASIS, 010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 011 * See the License for the specific language governing permissions and 012 * limitations under the License. 013 */ 014package org.gbif.ws.security; 015 016import java.util.Collection; 017import java.util.Collections; 018import java.util.Objects; 019 020import org.springframework.security.core.GrantedAuthority; 021import org.springframework.security.core.userdetails.UserDetails; 022 023public class BasicUserPrincipal implements UserDetails { 024 025 private final String name; 026 027 public BasicUserPrincipal(String name) { 028 Objects.requireNonNull(name); 029 this.name = name; 030 } 031 032 @Override 033 public Collection<? extends GrantedAuthority> getAuthorities() { 034 return Collections.emptyList(); 035 } 036 037 @Override 038 public String getPassword() { 039 throw new UnsupportedOperationException("No password for BasicUserPrincipal"); 040 } 041 042 @Override 043 public String getUsername() { 044 return name; 045 } 046 047 @Override 048 public boolean isAccountNonExpired() { 049 return true; 050 } 051 052 @Override 053 public boolean isAccountNonLocked() { 054 return true; 055 } 056 057 @Override 058 public boolean isCredentialsNonExpired() { 059 return true; 060 } 061 062 @Override 063 public boolean isEnabled() { 064 return true; 065 } 066}