本文整理了Java中org.apache.nifi.authorization.Group.getName()
方法的一些代码示例,展示了Group.getName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Group.getName()
方法的具体详情如下:
包路径:org.apache.nifi.authorization.Group
类名称:Group
方法名:getName
暂无
代码示例来源:origin: apache/nifi
@Override
public String toString() {
return String.format("identifier[%s], name[%s], users[%s]", getIdentifier(), getName(), String.join(", ", users));
}
代码示例来源:origin: apache/nifi
private void writeGroup(final XMLStreamWriter writer, final Group group) throws XMLStreamException {
List<String> users = new ArrayList<>(group.getUsers());
Collections.sort(users);
writer.writeStartElement(GROUP_ELEMENT);
writer.writeAttribute(IDENTIFIER_ATTR, group.getIdentifier());
writer.writeAttribute(NAME_ATTR, group.getName());
for (String user : users) {
writer.writeStartElement(GROUP_USER_ELEMENT);
writer.writeAttribute(IDENTIFIER_ATTR, user);
writer.writeEndElement();
}
writer.writeEndElement();
}
代码示例来源:origin: apache/nifi
private void writeGroup(final XMLStreamWriter writer, final Group group) throws XMLStreamException {
List<String> users = new ArrayList<>(group.getUsers());
Collections.sort(users);
writer.writeStartElement(GROUP_ELEMENT);
writer.writeAttribute(IDENTIFIER_ATTR, group.getIdentifier());
writer.writeAttribute(NAME_ATTR, group.getName());
for (String user : users) {
writer.writeStartElement(GROUP_USER_ELEMENT);
writer.writeAttribute(IDENTIFIER_ATTR, user);
writer.writeEndElement();
}
writer.writeEndElement();
}
代码示例来源:origin: apache/nifi
/**
* Extracts the values for the configured properties from the specified user group.
*/
private Map<String, String> extractConfiguredPropertyValues(Group group, UserGroupDTO userGroupDTO) {
Map<String, String> values = new HashMap<>();
if (userGroupDTO.getIdentity() != null) {
values.put(NAME, group.getName());
}
if (userGroupDTO.getUsers() != null) {
// get each of the auto terminated relationship names
final List<String> currentUsers = new ArrayList<>(group.getUsers());
// sort them and include in the configuration
Collections.sort(currentUsers, Collator.getInstance(Locale.US));
values.put(USERS, StringUtils.join(currentUsers, ", "));
}
return values;
}
代码示例来源:origin: apache/nifi
/**
* Initializes the builder with the state of the provided group. When using this constructor
* the identifier field of the builder can not be changed and will result in an IllegalStateException
* if attempting to do so.
*
* @param other the existing access policy to initialize from
*/
public Builder(final Group other) {
if (other == null) {
throw new IllegalArgumentException("Provided group can not be null");
}
this.identifier = other.getIdentifier();
this.name = other.getName();
this.users.clear();
this.users.addAll(other.getUsers());
this.fromGroup = true;
}
代码示例来源:origin: apache/nifi
private Group getGroup(final String name) {
if (userGroupProvider == null) {
// generate the group deterministically when running outside of the ManagedRangerAuthorizer
return new Group.Builder().identifierGenerateFromSeed(name).name(name).build();
} else {
// find the group in question
final Group group = userGroupProvider.getGroups().stream().filter(g -> g.getName().equals(name)).findFirst().orElse(null);
if (group == null) {
logger.warn(String.format("Cannot find group '%s' in the configured User Group Provider. Skipping group for viewing purposes. Will still be used for access decisions.", name));
}
return group;
}
}
代码示例来源:origin: apache/nifi
/**
* Gets the groups for the user with the specified identity. Returns null if the authorizer is not able to load user groups.
*
* @param authorizer the authorizer to load the groups from
* @param userIdentity the user identity
* @return the listing of groups for the user
*/
public static Set<String> getUserGroups(final Authorizer authorizer, final String userIdentity) {
if (authorizer instanceof ManagedAuthorizer) {
final ManagedAuthorizer managedAuthorizer = (ManagedAuthorizer) authorizer;
final UserGroupProvider userGroupProvider = managedAuthorizer.getAccessPolicyProvider().getUserGroupProvider();
final UserAndGroups userAndGroups = userGroupProvider.getUserAndGroups(userIdentity);
final Set<Group> userGroups = userAndGroups.getGroups();
if (userGroups == null || userGroups.isEmpty()) {
return Collections.EMPTY_SET;
} else {
return userAndGroups.getGroups().stream().map(group -> group.getName()).collect(Collectors.toSet());
}
} else {
return null;
}
}
}
代码示例来源:origin: apache/nifi
/**
* Checks if another tenant (user or group) exists with the same identity.
*
* @param userGroupProvider the userGroupProvider to use to lookup the tenant
* @param identifier identity of the tenant
* @param identity identity of the tenant
* @return true if another tenant exists with the same identity, false otherwise
*/
private static boolean tenantExists(final UserGroupProvider userGroupProvider, final String identifier, final String identity) {
for (User user : userGroupProvider.getUsers()) {
if (!user.getIdentifier().equals(identifier)
&& user.getIdentity().equals(identity)) {
return true;
}
}
for (Group group : userGroupProvider.getGroups()) {
if (!group.getIdentifier().equals(identifier)
&& group.getName().equals(identity)) {
return true;
}
}
return false;
}
代码示例来源:origin: apache/nifi
@Override
public synchronized Group addGroup(Group group) throws AuthorizationAccessException {
if (group == null) {
throw new IllegalArgumentException("Group cannot be null");
}
final UserGroupHolder holder = userGroupHolder.get();
final Tenants tenants = holder.getTenants();
// create a new JAXB Group based on the incoming Group
final org.apache.nifi.authorization.file.tenants.generated.Group jaxbGroup = new org.apache.nifi.authorization.file.tenants.generated.Group();
jaxbGroup.setIdentifier(group.getIdentifier());
jaxbGroup.setName(group.getName());
// add each user to the group
for (String groupUser : group.getUsers()) {
org.apache.nifi.authorization.file.tenants.generated.Group.User jaxbGroupUser = new org.apache.nifi.authorization.file.tenants.generated.Group.User();
jaxbGroupUser.setIdentifier(groupUser);
jaxbGroup.getUser().add(jaxbGroupUser);
}
tenants.getGroups().getGroup().add(jaxbGroup);
saveAndRefreshHolder(tenants);
return userGroupHolder.get().getGroupsById().get(group.getIdentifier());
}
代码示例来源:origin: apache/nifi
@Override
public synchronized Group updateGroup(Group group) throws AuthorizationAccessException {
if (group == null) {
throw new IllegalArgumentException("Group cannot be null");
}
final UserGroupHolder holder = userGroupHolder.get();
final Tenants tenants = holder.getTenants();
// find the group that needs to be update
org.apache.nifi.authorization.file.tenants.generated.Group updateGroup = null;
for (org.apache.nifi.authorization.file.tenants.generated.Group jaxbGroup : tenants.getGroups().getGroup()) {
if (jaxbGroup.getIdentifier().equals(group.getIdentifier())) {
updateGroup = jaxbGroup;
break;
}
}
// if the group wasn't found return null, otherwise update the group and save changes
if (updateGroup == null) {
return null;
}
// reset the list of users and add each user to the group
updateGroup.getUser().clear();
for (String groupUser : group.getUsers()) {
org.apache.nifi.authorization.file.tenants.generated.Group.User jaxbGroupUser = new org.apache.nifi.authorization.file.tenants.generated.Group.User();
jaxbGroupUser.setIdentifier(groupUser);
updateGroup.getUser().add(jaxbGroupUser);
}
updateGroup.setName(group.getName());
saveAndRefreshHolder(tenants);
return userGroupHolder.get().getGroupsById().get(group.getIdentifier());
}
代码示例来源:origin: apache/nifi
logger.debug("Trying to load node group '{}' from the underlying userGroupProvider", nodeGroupName);
for (Group group : userGroupProvider.getGroups()) {
if (group.getName().equals(nodeGroupName)) {
nodeGroupIdentifier = group.getIdentifier();
break;
代码示例来源:origin: apache/nifi
@Override
public void onConfigured(AuthorizerConfigurationContext configurationContext) throws AuthorizerCreationException {
baseManagedAuthorizer.onConfigured(configurationContext);
final AccessPolicyProvider accessPolicyProvider = baseManagedAuthorizer.getAccessPolicyProvider();
final UserGroupProvider userGroupProvider = accessPolicyProvider.getUserGroupProvider();
// ensure that only one policy per resource-action exists
for (AccessPolicy accessPolicy : accessPolicyProvider.getAccessPolicies()) {
if (policyExists(accessPolicyProvider, accessPolicy)) {
throw new AuthorizerCreationException(String.format("Found multiple policies for '%s' with '%s'.", accessPolicy.getResource(), accessPolicy.getAction()));
}
}
// ensure that only one group exists per identity
for (User user : userGroupProvider.getUsers()) {
if (tenantExists(userGroupProvider, user.getIdentifier(), user.getIdentity())) {
throw new AuthorizerCreationException(String.format("Found multiple users/user groups with identity '%s'.", user.getIdentity()));
}
}
// ensure that only one group exists per identity
for (Group group : userGroupProvider.getGroups()) {
if (tenantExists(userGroupProvider, group.getIdentifier(), group.getName())) {
throw new AuthorizerCreationException(String.format("Found multiple users/user groups with name '%s'.", group.getName()));
}
}
}
代码示例来源:origin: apache/nifi
/**
* Creates a {@link TenantDTO} from the specified {@link User}.
*
* @param userGroup user
* @return dto
*/
public TenantDTO createTenantDTO(Group userGroup) {
if (userGroup == null) {
return null;
}
final TenantDTO dto = new TenantDTO();
dto.setId(userGroup.getIdentifier());
dto.setIdentity(userGroup.getName());
dto.setConfigurable(AuthorizerCapabilityDetection.isGroupConfigurable(authorizer, userGroup));
return dto;
}
代码示例来源:origin: apache/nifi
configurationAction.setTimestamp(actionTimestamp);
configurationAction.setSourceId(user.getIdentifier());
configurationAction.setSourceName(user.getName());
configurationAction.setSourceType(Component.UserGroup);
configurationAction.setActionDetails(actionDetails);
代码示例来源:origin: apache/nifi
/**
* Generates an audit record for the creation of a user group.
*
* @param userGroup userGroup
* @param operation operation
* @param actionDetails details
* @return action
*/
public Action generateAuditRecord(Group userGroup, Operation operation, ActionDetails actionDetails) {
FlowChangeAction action = null;
// get the current user
NiFiUser niFiUser = NiFiUserUtils.getNiFiUser();
// ensure the user was found
if (niFiUser != null) {
// create the user action for adding this user
action = new FlowChangeAction();
action.setUserIdentity(niFiUser.getIdentity());
action.setOperation(operation);
action.setTimestamp(new Date());
action.setSourceId(userGroup.getIdentifier());
action.setSourceName(userGroup.getName());
action.setSourceType(Component.UserGroup);
if (actionDetails != null) {
action.setActionDetails(actionDetails);
}
}
return action;
}
代码示例来源:origin: apache/nifi
if (group.getName().equals(legacyGroupName)) {
foundGroup = group;
break;
代码示例来源:origin: apache/nifi
dto.setId(userGroup.getIdentifier());
dto.setUsers(users);
dto.setIdentity(userGroup.getName());
dto.setConfigurable(AuthorizerCapabilityDetection.isGroupConfigurable(authorizer, userGroup));
dto.setAccessPolicies(policies);
代码示例来源:origin: apache/nifi
logger.debug("Populating default authorizations for group '{}' ({})", userGroupProvider.getGroup(nodeGroupIdentifier).getName(), nodeGroupIdentifier);
addGroupToAccessPolicy(authorizations, ResourceType.Proxy.getValue(), nodeGroupIdentifier, WRITE_CODE);
代码示例来源:origin: org.apache.nifi/nifi-ranger-plugin
private Group getGroup(final String name) {
if (userGroupProvider == null) {
// generate the group deterministically when running outside of the ManagedRangerAuthorizer
return new Group.Builder().identifierGenerateFromSeed(name).name(name).build();
} else {
// find the group in question
final Group group = userGroupProvider.getGroups().stream().filter(g -> g.getName().equals(name)).findFirst().orElse(null);
if (group == null) {
logger.warn(String.format("Cannot find group '%s' in the configured User Group Provider. Skipping group for viewing purposes. Will still be used for access decisions.", name));
}
return group;
}
}
内容来源于网络,如有侵权,请联系作者删除!