How to identify a user logged on to the SilverStream Server.
You can run this technique code from:
NOTE First make sure that database is running on your localhost SilverStream Server | |
See the chapter on using the Server Administration API in the Administrator's Guide |
You can use the methods in this example to write security access expressions for objects.
The code uses a table called benefits to illustrate the results of specifying access control for an object. By default, this table has unrestricted access. You can use the SilverStream Management Console (SMC) to restrict access to the table, then log in as different users to test the results. For example, if you log in as a user without access, no data will appear in the table.
The following code uses the getuser() method to determine the login identity of the current user. This method attempts to match the user login name to a user defined in SilverStream users and groups. If it does not find a match, it returns "Anonymous." The code uses setText()
to set the results of getUser()
to the text box lblUser.
} private void handle_btnGetUser_actionPerformed(ActionEvent evt) { lblUser.setText(getUser()); }
This line of code specifes the group to which you want to compare the user to determine memebrship. It uses setText()
to set the field fldUserInGroup to the group name "Administrators." The group specified must already be defined as a SilverStream group.
protected void formLoaded() { fldUserInGroup.setText("Administrators"); }
This code uses the userInGroup()
method in a conditional statement to test for the group membership of the current Silverstream user. It then sets the test result to the text box lblUserinGroup.
private void handle_btnUserInGroup_actionPerformed(ActionEvent evt) { String userInGroup; if (userInGroup(fldUserInGroup.getText())) userInGroup = "true"; else userInGroup = "false"; lblUserInGroup.setText(userInGroup); }