blob: 3ea6cad2fd208b3165638ca333fc85f56b34ca59 [file]
// Copyright 2022 The casbin Authors. All Rights Reserved.
//
// 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.casbin.config;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public class AuthenticationImpl implements Authentication {
private final String name;
private final Collection<GrantedAuthorityImpl> grantedAuthorities;
private boolean isAuthenticated;
public AuthenticationImpl(String name, List<String> roles) {
this.name = name;
List<GrantedAuthorityImpl> authorities = new ArrayList<>();
roles.forEach(r -> authorities.add(new GrantedAuthorityImpl(r)));
this.grantedAuthorities = Collections.unmodifiableCollection(authorities);
this.isAuthenticated = true;
}
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return grantedAuthorities;
}
@Override
public Object getCredentials() {
return null;
}
@Override
public Object getDetails() {
return null;
}
@Override
public Object getPrincipal() {
return name;
}
@Override
public boolean isAuthenticated() {
return isAuthenticated;
}
@Override
public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
this.isAuthenticated = isAuthenticated;
}
@Override
public String getName() {
return name;
}
}