All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xlrit.gears.engine.security.RoleAuthority Maven / Gradle / Ivy

package com.xlrit.gears.engine.security;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import org.springframework.security.core.GrantedAuthority;

public final class RoleAuthority implements GrantedAuthority {
	private final String roleName;

	public RoleAuthority(String roleName) {
		this.roleName = roleName;
	}

	public String getName() {
		return roleName;
	}

	@Override
	public String getAuthority() {
		return "ROLE_" + roleName;
	}

	public static Collection fromRoleNames(List roles) {
		if (roles == null || roles.isEmpty())
			return Collections.emptyList();

		return roles.stream()
			.map(RoleAuthority::new)
			.collect(Collectors.toList());
	}

	@Override
	public String toString() {
		return "RoleAuthority[" + roleName + "]";
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy