net.kut3.http.SimpleCredential Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of servlet-util Show documentation
Show all versions of servlet-util Show documentation
A bundle of servlet ultilies
The newest version!
/*
* Copyright 2019 NetKut3.
*
* 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 net.kut3.http;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
/**
*
*/
public class SimpleCredential implements Credential {
private final String id;
private final String allRoles;
private final Set roles = new HashSet<>();
/**
*
* @param id Id of this credential
* @param allRoles Roles of this credential
*/
public SimpleCredential(String id, String allRoles) {
this.id = id;
this.allRoles = allRoles;
this.roles.addAll(Arrays.asList(this.allRoles.split(",")));
}
@Override
public String id() {
return this.id;
}
/**
*
* @return Get roles of this credential
*/
@Override
public String roles() {
return this.allRoles;
}
@Override
public boolean hasRole(String role) {
return this.roles.contains(role);
}
}