Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Panel
borderWidth1
titleBGColor#c6f68d
borderStylesolid
titleDescription
English

Active Directory schemas often comes with a plethora of customizations to cater to the specific requirements of an organization.

The sample code snippet below can be used in Bean Shell Permission, to retrieve the values of your custom user object attribute, to perform permission logic.

Thai

สกีมา Active Directory มักจะมาพร้อมกับการปรับแต่งมากมายเพื่อตอบสนองความต้องการเฉพาะขององค์กร

ตัวอย่างโค้ดด้านล่างสามารถใช้ใน Bean Shell Permission เพื่อดึงค่าของแอตทริบิวต์วัตถุผู้ใช้ที่กำหนดเองของคุณเพื่อดำเนินการตรรกะการอนุญาต

Panel
bgColor#fff2df
borderStylesolid

This guide is applicable for all permission types, e.g: Form Permission, UI Category Permission, etc.

Thai

คู่มือนี้ใช้ได้กับทุกประเภทการอนุญาตเช่นการอนุญาตแบบฟอร์มการอนุญาตหมวดหมู่ Userview และอื่น ๆ

Code Block
languagejava
linenumberstrue
import java.util.Map;
import org.joget.directory.model.User;
import org.joget.plugin.ldap.model.UserLDAPImpl;
import javax.naming.directory.Attributes;

public boolean isAuthorized(User user, Map params) {

    /* 
    'user' parameter is current user
    'user' parameter is of User object, UserLDAPImpl extends User
    */

    // Check if current user is not anonymous & current user belongs to AD user
    if (user != null && user instanceof UserLDAPImpl) {

        // Cast 'user' object to UserLDAPImpl
        UserLDAPImpl ldapUser = (UserLDAPImpl) user;

        // Re-use method getAttributes() to get user details
        Attributes attrs = ldapUser.getAttributes();

        //Change the attribute name here to suit your requirements
        String attributeName = "cn";
        if (attrs.get(attributeName) != null) {

            //This is how to retrieve attribute values
            System.out.println(attrs.get(attributeName).get().toString());

            /*
            Perform your permission logic for AD users here
            */
        }
    } else if (user != null && !(user instanceof UserLDAPImpl)) {
        /*
        Handle permission logic for non-AD users
        */
    } else {
        return false;
    }
}

//call isAuthorized method with injected variable
return isAuthorized(user, requestParams);