活动介绍

WebLogicServer的JAAS编写与安全领域定制

立即解锁
发布时间: 2025-08-24 00:58:30 阅读量: 1 订阅数: 7
# WebLogic Server的JAAS编写与安全领域定制 ## 1. WebLogic Server的JAAS扩展 JAAS(Java Authentication and Authorization Service)示例通常用于JAAS v1.0包,而WebLogic Server对其进行了扩展,以便在WebLogic认证和安全领域中使用。与传统的JAAS实现相比,WebLogic Server的认证登录使用URL来访问服务器,而不是通过策略文件,并且调用WebLogic Server的Authenticate类来验证用户。 ### 1.1 登录函数示例 以下是一个登录函数的示例代码: ```java /** * Authenticate the user by username and password passed in * * @return true in all cases * * @exception LoginException if this LoginModule * is unable to perform the authentication. */ public boolean login() throws LoginException { // Verify that the client supplied a callback handler if (callbackHandler == null) { throw new LoginException("No CallbackHandler Specified"); } // Populate callback list Callback[] callbacks = new Callback[2]; callbacks[0] = new NameCallback("username: "); callbacks[1] = new PasswordCallback("password: ", false); try { // Prompt for username and password callbackHandler.handle(callbacks); // Retrieve username username = ((NameCallback) callbacks[0]).getName(); // Retrieve password, converting from char[] to String char[] charPassword = ((PasswordCallback) callbacks[1]).getPassword(); if (charPassword == null) { // Treat a NULL password as an empty password, not NULL charPassword = new char[0]; } password = new String(charPassword); } catch (IOException ioe) { throw new LoginException(ioe.toString()); } catch (UnsupportedCallbackException uce) { throw new LoginException("Error: Callback " + uce.getCallback().toString() + " Not Available"); } // Populate weblogic environment and authenticate /* WebLogic Only */ Environment env = new Environment(); env.setProviderUrl(url); env.setSecurityPrincipal(username); env.setSecurityCredentials(password); try { // Authenticate user credentials, populating Subject /* WebLogic Specific */ Authenticate.authenticate(env, subject); /* Non−WebLogic Function for Login */ //authenticate(username, password); } catch(RemoteException re) { System.err.println("Error: Remote Exception on authenticate, " + re.getMessage()); throw new LoginException(re.toString()); } catch(IOException ioe) { System.err.println("Error: IO Exception on authenticate, " + ioe.getMessage()); throw new LoginException(ioe.toString()); } catch (LoginException le) { System.err.println("Error: Login Exception on authenticate, " + le.getMessage()); throw new LoginException(le.toString()); } // Successfully authenticated subject with supplied info succeeded = true; return succeeded; } ``` ### 1.2 替代策略文件 通过重写Configuration对象的getAppConfigurationEntry()函数,可以使用URL替代策略文件。以下是一个示例配置类: ```java package com.hungryminds.wljaas; /* * Class SampleAction */ import java.util.Hashtable; import javax.security.auth.login.Configuration; import javax.security.auth.login.AppConfigurationEntry; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; /** * Sample configuration class for JAAS user authentication. */ public class ConfigFile extends Configuration { String configFileName = null; /** * * Create a new Configuration object. */ public ConfigFile() { } /** * Retrieve an entry from the Configuration object * using an application name as an index. */ public AppConfigurationEntry[] getAppConfigurationEntry( String applicationName) { AppConfigurationEntry[] list = new AppConfigurationEntry[1]; AppConfigurationEntry entry = null; /* Get the spcified configuration file */ configFileName = System.getProperty("weblogic.security.jaas.Policy"); try { FileReader fr = new FileReader(configFileName); BufferedReader reader = new BufferedReader(fr); String line; line = reader.readLine(); while(line != null) { // Skip lines until the line starting with a ‘{‘ if(line.length() == 0 || line.charAt(0) != ‘{‘) { line = reader.readLine(); continue; } /* Read following line which contains the LoginModule configured */ line = reader.readLine(); int i; for(i = 0; i < line.length(); i++) { char c = line.charAt(i); if(c != ‘ ‘) break; } int sep = line.indexOf(‘ ‘, i); String LMName = line.substring(0, sep).trim(); String LMFlag = line.substring(sep + 1, line.indexOf(‘ ‘, sep + 1)); if(LMFlag.equalsIgnoreCase("OPTIONAL")) { entry = new AppConfigurationEntry(LMName, AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL, new Hashtable()); list[0] = entry; } else if(LMFlag.equalsIgnoreCase("REQUIRED")) { entry = new AppConfigurationEntry(LMName, AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, new Hashtable()); list[0] = entry; } else if(LMFlag.equalsIgnoreCase("REQUISITE")) { entry = new AppConfigurationEntry(LMName, AppConfigurationEntry.LoginModuleControlFlag.REQUISITE, new Hashtable()); list[0] = entry; } else if(LMFlag.equalsIgnoreCase("SUFFICIENT")) { entry = new AppConfigurationEntry(LMName, AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT, new Hashtable()); list[0] = entry; } else { throw new IllegalArgumentException("Invalid controlFlag"); } line = reader.readLine(); } reader.close(); } catch(java.io.FileNotFoundException ioe) { System.out.println(ioe.toString()); } catch(java.io.IOException ioe) { System.out.println(ioe.toString()); } return list; } /** * Refresh and reload the Configuration object by reading * all of the login configurations again. */ public void refresh() { // No Implementation } } ``` ### 1.3 用户登录与测试 用户登录WebLogic Server时,需要在authenticate函数中输入有效的用户名和密码。示例代码中硬编码的用户名和密码如下: ```java private final static String USERNAME = "rich"; private final static String PASSWORD = "richpass"; ``` 以下是一个测试认证和JAAS客户端访问WebLogic Server的示例类: ```java package com.hungryminds.wljaas; import java.security.PrivilegedAction; import javax.naming.Context; import javax.naming.InitialContext; import java.util.Hashtable; import javax.naming.*; public class SampleAction implements PrivilegedAction { public Object run() { Object obj = null; Context ctx = null; String url = null; try { // Retrieve WLS server URL string url = System.getProperty("weblogic.security.jaas.ServerURL"); } catch (NullPointerException npe) { System.err.println("Error: ServerURL Not Specified"); return null; } catch (IllegalArgumentException iae) { System.err.println("Error: ServerURL Not Specified"); return null; } catch (SecurityException se) { System.err.println( "Error: Security Exception on accessing ServerURL Specification"); return null; } // Populate environment Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); env.put(Context.PROVIDER_URL, url); try { // Create InitialContext ctx = new InitialContext(env); printBindingList("", ctx.listBindings("")); printNameList("", ctx.list("")); /** * Execute target EJB Frobable.frob() method. (This is left over from * the WLS example − it is intended to show that there is differences * and similarities to show that the same code slightly modified * works in both instances.) */ System.out.println("JNDI Lists successfully"); } catch (Throwable t) { t.printStackTrace(); System.out.println("Failed to lists JNDI"); } finally { try { // Close InitialContext ctx.close(); } catch (Exception e) { // Deal with any failures } } return obj; } void printNameList(String msg, NamingEnumeration nl) { System.out.println(msg); if (nl == null) { System.out.println("No items in name list"); } else { try { while (nl.hasMore()) { System.out.println(nl.next()); } } catch (NamingException e) { e.printStackTrace(); } } } void printBindingList(String msg, NamingEnumeration bl) { System.out.println(msg); if (bl == null) { System.out.println("No items in binding list"); } else { try { while (bl.hasMore()) { Binding b = (Binding) bl.next(); System.out.println(b.getName() + "(" + b.getObject() + ")"); } } catch (NamingException e) { e.printStackTrace(); } } } } ``` ### 1.4 JNDI权限问题 默认情况下,每个用户都有列出和修改JNDI条目的权限,这可能会带来安全风险。一些JNDI服务应该只对系统用户开放。 ## 2. 授权与安全领域 WebLogic Server有自己的安全领域类型,并使用自己的ACL(Access Control List)接口进行通信。weblogic.security.acl.Security类仅在服务器端代码中可用,需要访问客户端类无法访问的安全领域。 ### 2.1 Security类的使用 Security类有许多功能,其中Security.getRealm()是一个静态函数,返回BasicRealm的实例。BasicRealm提供了对安全领域的最小接口,可列出领域管理的所有实例,并具有创建和销毁实例的能力。访问BasicRealm后,可以使用getUser()函数从安全领域中检索用户,使用getPermission()函数检索权限。 ### 2.2 权限检查方法 Security.hasPermission()和Security.checkPermission()是Security类中定义的静态函数,用于测试用户是否具有访问资源的正确权限。两者的区别在于,Security.checkPermission()在用户没有权限时会抛出java.lang.SecurityException,而Security.hasPermission()会返回false。 ## 3. 构建自定义RDBMS安全领域 WebLogic允许创建自定义安全领域,下面以RDBMS为例进行说明。 ### 3.1 数据存储定义 WebLogic Server 6.1附带了Cloudscape数据库的评估版本,这是一个纯Java的关系型数据库管理系统(RDBMS)。使用Cloudscape与WebLogic Server时,需要将Cloudscape库cloudscape.jar添加到WebLogic Server的CLASSPATH中,并设置cloudscape.system.home Java系统属性为包含C
corwn 最低0.47元/天 解锁专栏
赠100次下载
继续阅读 点击查看下一篇
profit 400次 会员资源下载次数
profit 300万+ 优质博客文章
profit 1000万+ 优质下载资源
profit 1000万+ 优质文库回答
复制全文

相关推荐

SW_孙维

开发技术专家
知名科技公司工程师,开发技术领域拥有丰富的工作经验和专业知识。曾负责设计和开发多个复杂的软件系统,涉及到大规模数据处理、分布式系统和高性能计算等方面。
最低0.47元/天 解锁专栏
赠100次下载
百万级 高质量VIP文章无限畅学
千万级 优质资源任意下载
千万级 优质文库回答免费看
立即解锁

专栏目录

最新推荐

网络性能评估必修课:站点调查后的测试与验证方法

![网络性能评估必修课:站点调查后的测试与验证方法](https://images.edrawsoft.com/articles/network-topology-examples/network-topology-examples-cover.png) # 摘要 网络性能评估对于确保网络服务质量至关重要。本文首先介绍了网络性能评估的基础概念,然后详细探讨了站点调查的理论与方法,包括调查的准备、执行及结果分析。接着,文章深入分析了网络性能测试工具与技术,包括测试工具的介绍、技术原理以及测试实施与监控。第四章讨论了性能验证策略,结合案例分析提供了理论基础和实际操作指导。第五章阐述了如何撰写和解

BCM5396日志分析与故障诊断:掌握日志管理,快速定位问题

# 摘要 本文围绕BCM5396日志分析与故障诊断的核心议题展开,首先概述了日志分析与故障诊断的基本概念,随后深入探讨了日志数据的类型、结构、收集、存储、安全性和合规性管理。紧接着,文中介绍了多种日志分析工具及其实践应用,包括模式匹配、日志聚合、排序和可视化技术,并通过实际案例分析展示了日志分析在故障诊断和性能优化中的重要性。文章进一步详细阐述了故障诊断的流程、工具和策略,并对故障案例进行了深入分析,提出了解决方案及预防措施。最后,本文探讨了日志管理的最佳实践以及故障预防和持续改进方法,旨在为网络管理和故障排除提供指导和参考。 # 关键字 BCM5396;日志分析;故障诊断;数据管理;安全合

【统一认证平台集成测试与持续部署】:自动化流程与最佳实践

![【统一认证平台集成测试与持续部署】:自动化流程与最佳实践](https://ares.decipherzone.com/blog-manager/uploads/ckeditor_JUnit%201.png) # 摘要 本文全面探讨了统一认证平台的集成测试与持续部署的理论与实践。首先介绍了统一认证平台的基本概念和重要性,随后深入分析了集成测试的基础知识、工具选择和实践案例。在此基础上,文章转向持续部署的理论基础、工具实施以及监控和回滚策略。接着,本文探讨了自动化流程设计与优化的原则、技术架构以及测试与改进方法。最后,结合统一认证平台,本文提出了一套集成测试与持续部署的案例研究,详细阐述了

用户体验(UX)设计在软件交付中的作用:3个挑战与应对策略

![用户体验(UX)设计在软件交付中的作用:3个挑战与应对策略](https://website-dev.hn.ss.bfcplatform.vn/Pr_F_Mr1_V3x_Vyl1_N_Tao_Xor_Sn00lqzl0_Ca_Kp_N_Iae_Zwya_Ry_Zb_Fi_X_58b5bee1ca.png) # 摘要 用户体验(UX)设计在软件交付中扮演着至关重要的角色。本文首先探讨了用户体验设计的理论基础,包括基本原则、用户研究方法论以及设计思维和迭代过程。然后,分析了在软件交付过程中用户体验设计所面临的挑战,如与开发时间表的冲突、技术限制、以及需求理解和沟通障碍。接着,文中提出了应对这

【打印机响应时间缩短绝招】:LQ-675KT打印机性能优化秘籍

![打印机](https://m.media-amazon.com/images/I/61IoLstfj7L._AC_UF1000,1000_QL80_.jpg) # 摘要 本文首先概述了LQ-675KT打印机的性能,并介绍了性能优化的理论基础。通过对打印机响应时间的概念及性能指标的详细分析,本文揭示了影响打印机响应时间的关键因素,并提出了理论框架。接着,文章通过性能测试与分析,采用多种测试工具和方法,对LQ-675KT的实际性能进行了评估,并基于此发现了性能瓶颈。此外,文章探讨了响应时间优化策略,着重分析了硬件升级、软件调整以及维护保养的最佳实践。最终,通过具体的优化实践案例,展示了LQ-

【飞行模拟器的自动化测试】:实现F-16模拟配平的自动化校准,效率倍增!

![【飞行模拟器的自动化测试】:实现F-16模拟配平的自动化校准,效率倍增!](https://d3i71xaburhd42.cloudfront.net/d30c440a618b1e4e9e24152ae112553108a7a48d/24-Figure4.1-1.png) # 摘要 本文对飞行模拟器自动化测试进行了全面概述,探讨了自动化测试的理论基础、F-16模拟配平自动化校准的实现、自动化校准测试的深度应用与优化,以及未来展望。自动化测试不仅提高了测试效率和准确性,还降低了人力成本。针对F-16模拟配平,文章详细介绍了自动化校准脚本的设计、开发、测试与部署,并分析了校准测试数据,提出了

RTC5振镜卡固件升级全攻略:步骤详解与风险控制技巧

# 摘要 振镜卡作为精密光学设备的关键组成部分,其固件升级对于提高设备性能和稳定性至关重要。本文系统地介绍了振镜卡固件升级的理论基础,包括固件定义、升级必要性及优势,振镜卡工作原理,以及升级过程中可能出现的问题及其对策。文章详细阐述了固件升级的步骤,包括准备工作、下载验证、操作流程,以及问题应对措施。同时,本文还探讨了固件升级的风险控制技巧,包括风险评估、预防措施、应急处理与恢复计划,以及升级后的测试与验证。通过对成功和失败案例的分析,总结了升级经验教训并提供了改进建议。最后,展望了振镜卡固件升级技术的发展方向和行业应用趋势,强调了自动化、智能化升级以及云服务的重要性。 # 关键字 振镜卡;

【Arduino到STM32CubeIDE】:代码补全功能的无缝转换与适应指南

![【Arduino到STM32CubeIDE】:代码补全功能的无缝转换与适应指南](https://reversepcb.com/wp-content/uploads/2023/05/STM32CubeMX-Configuration-Perspective.png.webp) # 摘要 随着物联网技术的发展,Arduino和STM32平台在项目开发中扮演着重要角色。从Arduino向STM32的迁移,涉及到从硬件到软件的多方面差异,其中代码补全技术在提高开发效率和代码质量方面起到了关键作用。本文首先概述了Arduino到STM32CubeIDE的迁移过程,然后深入探讨了代码补全技术的理论

持续集成与部署(CI_CD)实施:S12(X)项目管理秘诀

![持续集成与部署(CI_CD)实施:S12(X)项目管理秘诀](https://www.edureka.co/blog/content/ver.1531719070/uploads/2018/07/CI-CD-Pipeline-Hands-on-CI-CD-Pipeline-edureka-5.png) # 摘要 随着软件开发速度的加快,持续集成与持续部署(CI/CD)已成为企业确保快速交付高质量软件的关键实践。本文深入探讨了CI/CD的核心概念、工具选择与技术实践,并结合S12(X)项目的案例分析了CI/CD的实施细节。文中详细阐述了CI/CD工具的分类与特点,流水线设计原则以及环境配置

固件更新风险评估与减轻策略:系统停机的最小化

![固件更新风险评估与减轻策略:系统停机的最小化](https://montemagno.com/content/images/2021/09/Screen-Shot-2021-09-06-at-7.59.46-AM.png) # 摘要 固件更新作为维护设备安全性与性能的重要手段,在技术快速发展的今天显得尤为重要,但同时伴随着风险和挑战。本文深入探讨了固件更新过程中的风险评估、控制点识别、系统停机成本及影响,并通过实践案例分析了成功与失败的固件更新经验。针对固件更新风险,文章提出了一系列减轻策略,包括风险预防措施、自动化更新流程、持续集成策略以及用户教育和技术支持的重要性。最后,本文展望了固