关于weblogic:全网最全weblogic自定义Provider开发教程
weblogic Provider做过OAM,OID我的项目的同学应该都晓得,要集成OAM和OID须要在weblogic的Security Realms中配置Provider,那什么是Provider?在业务零碎中,认证和受权始终是最简单的一块,体现在 认证协定多样性,比方OAuth2,SAML等认证形式多样性,比方二次认证,验证码认证等认证策略多样性,比方有多个认证源,策略能够多样性,能够是一个不通过就不通过,也能够是只有有一个通过就全副通过自定义认证的需要,这个在企业外面还是挺多的,一些零碎上线时还没有相应的规范进去,所以都是自开发明码认证策略多样性,大部分零碎明码存储是不可逆的,如果一开始没有将明码存储在LDAP之类的服务里,后续如果要做降级,就无奈拿到原始明码,那么就须要自定义明码认证策略。总之,认证并不是用户名明码验证这么简略,所以weblogic针对不同的认证场景提供不同的Provider,weblogic作为成熟的商业服务器,天然蕴含大部分认证场景,以weblogic 11g为例,蕴含了以下Provider SAML2IdentityAsserterX3gppAssertedIdentityAsserterX3gppAssertedIdentityStrictAsserterDBMSDigestIdentityAsserterIdentityAssertionAuthenticatorIdentityHeaderAsserterLdapDigestIdentityAsserterPAssertedIdentityAsserterPAssertedIdentityStrictAsserterCrossTenantAuthenticatorTrustServiceIdentityAsserterOSSOIdentityAsserterOAMIdentityAsserterOAMAuthenticatorActiveDirectoryAuthenticatorCustomDBMSAuthenticatorDefaultAuthenticatorDefaultIdentityAsserterIPlanetAuthenticatorLDAPAuthenticatorLDAPX509IdentityAsserterNegotiateIdentityAsserterNovellAuthenticatorOpenLDAPAuthenticatorOracleInternetDirectoryAuthenticatorOracleVirtualDirectoryAuthenticatorReadOnlySQLAuthenticatorSQLAuthenticatorWindowsNTAuthenticatorSAMLAuthenticatorSAMLIdentityAsserterSAMLIdentityAsserterV2通过观察下面的列表,咱们发现有两类Provider xxxAsserterxxxAuthenticator那么这两个有什么区别,搞清楚这两个的区别十分重要,你进小区,如果你有带房卡就能够间接进,如果没有,你就得证实你是小区的户主,可能就须要你提供身份证,电话之类的信息,同理,如果带着token或者cookie拜访零碎那么就须要Asserter进行认证受权,如果带着用户名明码登录零碎就须要Authenticator进行认证,总之,Asserter看token,Authenticator看明码,那配过OAM单点登录的同学应该晓得,要实现OAM单点登录须要配置两个货色 配置OAMIdentityAsserter配置OracleInternetDirectoryAuthenticator那问题来了,为什么有了OAMIdentityAsserter还须要OracleInternetDirectoryAuthenticator?用户在登录页登录后,后续所有的申请都是通过OAMIdentityAsserter解析OAM信息进行认证受权,那么还须要Authenticator干嘛?Asserter获取的用户信息无限,只能从token外面解析出无限的用户信息,个别就是用户ID,那么须要判断用户存不存在或者须要更多的用户信息就须要借助Authenticator JAASJAAS(Java Authentication and Authorization Service)是Java提供集成在JDK中(在javax.security.auth门路下)规范用户认证与受权模型,简略来说,JAAS提供了一系列的接口,不同认证形式通过实现接口从而能够以插件的模式集成到java应用程序中,JAAS架构图下 在JAAS中有几个重要的概念须要理解 SubjectSubject示意请求者,可能是一个人也可能是一个设施 PrincipalPrincipal是关联在Subject下,后面提到Subject示意的是请求者,咱们用登录用户会更好了解点,那么Principal就是用户的账号,可能是用手机号登录的,也可能是用邮箱登录的,Subject能够有多个Principal LoginContextLoginContext认证上下文,提供一系列认证办法,负责调用具体的认证实现(LoginModule),并且认证胜利后返回Subject LoginModule认证的具体实现,其中login办法实现登录逻辑,存储后果,commit办法最终将Subject提交到上下文 CallbackHandler当LoginModule须要拿到用户名和明码等认证信息时,就须要调用CallbackHandler返回这些信息,在gui利用中,CallbackHandler可能会弹出一个窗口让用户输出用户名和明码 CallbackLoginModule须要获取的用户信息成为Callback,比方须要向CallbackHandler获取用户名,那么就会创立一个NameCallback,须要获取明码就会创立一个PasswordCallback,CallbackHandler依据Callback的类型返回用户信息 我的项目背景某我的项目须要将OAM替换成其余产品,要求不能批改利用,做到无缝切换,利用部署在webogic上,通过OAMIdentityAsserter和OracleInternetDirectoryAuthenticator集成OAM和OID实现单点登录,利用局部配置如下 web.xml <security-constraint> <web-resource-collection> <web-resource-name>SecurePages</web-resource-name> <description>These pages are only accessible by authorized users.</description> <url-pattern>/*</url-pattern> <http-method>GET</http-method> </web-resource-collection> <auth-constraint> <description>These are the roles who have access.</description> <role-name>ValidUser</role-name> </auth-constraint> <user-data-constraint> <description>This is how the user data must be transmitted.</description> <transport-guarantee>NONE</transport-guarantee> </user-data-constraint></security-constraint><login-config> <auth-method>CLIENT-CERT</auth-method> <realm-name>myrealm</realm-name></login-config><security-role> <description>These are the roles who have access.</description> <role-name>ValidUser</role-name></security-role>weblogic.xml <wls:security-role-assignment> <wls:role-name>ValidUser</wls:role-name> <wls:principal-name>users</wls:principal-name> </wls:security-role-assignment>留神到web.xml中login-config的配置<auth-method>CLIENT-CERT</auth-method>,这个配置示意利用从上下文获取用户信息,也就是从HttpServletRequest的getUserPrincipal办法获取用户信息 ...