BW----List of logged on users in the Portal

本文介绍了一个使用WebDynpro for Java获取当前门户中登录用户的代码片段。该代码展示了如何利用特定的API获取所有已登录用户的详细信息,并通过消息管理器显示这些用户的信息。

Description : This code snippet gives the list of logged on users in the portal using Webdynpro for JAVA

Required jar files for this code snippet
-> webdynpro_services.jar located at <plugins folder>/com.sap.tc.webdynpro.runtime/lib
-> com.sap.security.api.jar located at <plugins folder>/com.sap.security/lib

import com.sap.tc.webdynpro.services.sal.um.api.IWDClientUser;
import com.sap.tc.webdynpro.services.sal.um.api.WDClientUser;

IWDClientUser currentUsers[] = WDClientUser.getClientUsers();
//Displaying the count of logged on users
wdComponentAPI.getMessageManager().reportSuccess("Number of logged on Users in the portal"+currentUsers.length);
for(int i = 0; i < currentUsers.length; i++)
{
if(currentUsers[i].getSAPUser() != null)
{
//Displaying the logged on users;
wdComponentAPI.getMessageManager().reportSuccess("User - "+currentUsers[i].getSAPUser().getUniqueName());
}
}
Note: I used reportSuccess statement to show the output, instead you can bind the list of users to a node and show in the Table
 
这句话的含义是:该项目属于内部项目,任何已登录的用户都可以访问,但外部用户除外。也就是说,只有在系统内被认可的、完成登录操作的用户才具备访问这个项目的权限,而那些未被纳入系统内部的外部用户则无法访问该项目。 在进行项目权限设置时,可通过以下步骤实现: 1. **用户认证系统**:搭建一个完善的用户认证系统,用于验证用户的登录信息。只有通过认证的用户才能进入系统。 2. **用户分类**:在系统中对用户进行分类,明确区分内部用户和外部用户。可以通过用户注册流程、用户角色等方式来实现。 3. **权限控制**:针对该项目,设置访问权限,仅允许内部已登录用户访问。可以在代码层面进行权限验证,当用户请求访问项目时,系统检查用户的登录状态和用户类型,如果是已登录的内部用户,则允许访问;否则,拒绝访问。 以下是一个简单的 Python Flask 示例代码,用于演示如何实现基本的权限控制: ```python from flask import Flask, request, abort, session app = Flask(__name__) app.secret_key = 'your_secret_key' # 模拟内部用户列表 internal_users = ['user1', 'user2', 'user3'] @app.route('/project') def access_project(): # 检查用户是否登录 if 'username' not in session: abort(401, description="Please log in.") # 检查用户是否为内部用户 if session['username'] not in internal_users: abort(403, description="You are not authorized to access this project.") return "You have successfully accessed the project." @app.route('/login', methods=['POST']) def login(): username = request.form.get('username') if username in internal_users: session['username'] = username return "Logged in successfully." else: abort(401, description="Invalid username.") @app.route('/logout') def logout(): session.pop('username', None) return "Logged out successfully." if __name__ == '__main__': app.run(debug=True) ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值