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.List;
018import java.util.Objects;
019
020import javax.validation.constraints.NotNull;
021
022import org.springframework.security.core.GrantedAuthority;
023import org.springframework.security.core.userdetails.UserDetails;
024
025/**
026 * @see org.gbif.api.model.common.AppPrincipal
027 */
028public class AppPrincipal implements UserDetails {
029
030  @NotNull private final String appKey;
031
032  private List<? extends GrantedAuthority> authorities;
033
034  public AppPrincipal(String appKey, List<? extends GrantedAuthority> authorities) {
035    Objects.requireNonNull(appKey, "appKey shall be provided");
036    this.appKey = appKey;
037    this.authorities = authorities;
038  }
039
040  @Override
041  public Collection<? extends GrantedAuthority> getAuthorities() {
042    return authorities;
043  }
044
045  @Override
046  public String getPassword() {
047    throw new UnsupportedOperationException("There is no password for the AppPrincipal");
048  }
049
050  @Override
051  public String getUsername() {
052    return appKey;
053  }
054
055  @Override
056  public boolean isAccountNonExpired() {
057    return true;
058  }
059
060  @Override
061  public boolean isAccountNonLocked() {
062    return true;
063  }
064
065  @Override
066  public boolean isCredentialsNonExpired() {
067    return true;
068  }
069
070  @Override
071  public boolean isEnabled() {
072    return true;
073  }
074}