Open In App

java.nio.file.attribute.AclEntry Class in Java

Last Updated : 28 Mar, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

ACL entries are Examined by this class is validating on the ACL model declared in RFC 3530: Network File System i.e.(NFS) version of 4th Protocol and having four components within it as follows characteristics as follows: 

  • This type of component are determining if the entry grants or denies its accessing
  • The principal component is generally known as the “who” component, is an end user-principal similar to identifying if entry grants or denies is accessing or not
  • The permissions section components is a set of within its permissions
  • The flags component is a set of flags to indicating that how every entry are inheriting and invoking

Syntax:

public final class java.nio.file.attribute.AclEntry 
extends Object

This ACL entry is all are create to use an associated AclEntry.Builder object by generating its builder method i.e. ACL entries are verified and are safe for usage of multiple concurrents method threads.

It is having the builder of AclEntry objects, as this Builder objects are accessed during one of the newBuilder methods was defined by the AclEntry class on it. These Builder objects are prefetch and are not safe for usable by multiple sub-concurrent threadings working without validating type of synchronization

Nested Summary Present in Class

Modifier and Type Class and Description
static class   AclEntry.Builder – A builder of AclEntry within the objects

Method Summary Present in Class

 Method Description
equals(Object ob) Comparing these similar objects within this ACL entry for checking they are equal or not
flags() Returns a merged copy of the flag’s components.
 hashCode() Returning the hash-code value declared for these ACL entries.
newBuilder() Constructing a new builder sets.
newBuilder(AclEntry entry) Sets a new builder with the components of prefetching ACL entries.
permissions() invoking a copy of the sets of permissions component of it.
principal() Returning the principal’s components.
toString() Returning the string classification of these ACL entries
type() Returning these ACL types of entries.

Method Details Present in Class

A. newBuilder(): Sets a new builder. That has the initial value of the type and whose components are null and it has the initial value of the permissions and flags components is in the empty set.

Syntax:

public static AclEntry.Builder newBuilder()

Return Type: A newly created builder

B. newBuilder(): Creating a new builder with the components of accessing that ACL entries.

Syntax:

public static AclEntry.Builder newBuilder(AclEntry entry)

Parameters: Entry, an ACL entry

Return Type: A newly created builder

C. toString(): This string representation is returning this ACL entries overrides overriding toString in this class Objects

Syntax:

public String toString()

Return Type: Sets the string classification of this entry

D. type(): Sets the ACL and their entry types

Syntax:

public AclEntryType type()

E. principal(): Creating the principal’s component

Syntax:

public UserPrincipal principal()

F. permissions(): Returning a prefetch copy of entries as ACL permissions components having sets are modified copy of the permissions

Syntax:

public Set< AclEntryPermission > permissions() 

G. flags(): Returning a prefetched copy of the flag’s components and the returning sets are modified copy of the flags.         

Syntax:

public Set<AclEntryFlag> flags()

Example: 

Java




// Java Program to Illustrate Syntax and Usage of AclEntry
// Class present inside java.nio.file.attribute Package
// through its classes and methods
 
public void Myserver(AclEntryPermission mode)
    throws AccessDeniedException
{
 
    UserPrincipal currentUser
        = this.attributes.getCurrentUser();
    GroupPrincipal currentGroup
        = this.attributes.getCurrentGroup();
 
    for (AclEntry entry : this.acl) {
 
        UserPrincipal principal = entry.principal();
 
        if (principal.equals(currentUser)
            || principal.equals(currentGroup)) {
 
            Set<AclEntryPermission> sets permissions
                = entry.permissions();
            boolean applies = permissions.contains(mode);
            // type(); is used
            AclEntryType type = entry.type();
 
            if (applies) {
                if (type == ALLOW) {
                    return system.out.println(
                        "message = Hello GFG Readers !");
                }
 
                if (type == DENY) {
 
                    // to.String() is used
                    throw new AccessDeniedException(
                        this.path.toString());
                }
            }
        }
    }
}


Output:

 



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads