nameconvertsid service namese

8122人阅读
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 方法一
首先,先简单介绍一下MD5
MD5的全称是message-digest algorithm 5(信息-摘要算法,在90年代初由mit laboratory for computer science和rsa data security inc的ronald l. rivest开发出来, 经md2、md3和md4发展而来。
MD5具有很好的安全性(因为它具有不可逆的特征,加过密的密文经过解密后和加密前的东东相同的可能性极小)
引用using System.Security.Cusing System.T
具体代码如下(写在按钮的Click事件里):byte[] result = Encoding.Default.GetBytes(this.tbPass.Text.Trim());&&& //tbPass为输入密码的文本框MD5 md5 = new MD5CryptoServiceProvider();byte[] output = puteHash(result);this.tbMd5pass.Text = BitConverter.ToString(output).Replace("-","");& //tbMd5pass为输出加密文本的文本框
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 方法二
C# md5加密(上) //加密前数据 //加密后数据b=System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(a,"MD5")
using&& Susing&& System.Security.C
public&& static&& string&& GetMD5(string&& myString)&& {MD5&& md5&&&& =&& new&& MD5CryptoServiceProvider();byte[]&& fromData&& =&& System.Text.Encoding.Unicode.GetBytes(myString);byte[]&& targetData&& =&& puteHash(fromData);string&& byte2String&& =&&
for&& (int&& i=0;&& i&targetData.L&& i++)&& {byte2String&& +=&& targetData[i].ToString("x");}
return&& byte2S}
using&& System.Security.C
///&& &summary&///&& 给一个字符串进行MD5加密///&& &/summary&///&& &param&& name="strText"&待加密字符串&/param&///&& &returns&加密后的字符串&/returns&public&& static&& string&& MD5Encrypt(string&& strText){&& MD5&& md5&& =&& new&& MD5CryptoServiceProvider();byte[]&& result&& =&& puteHash(System.Text.Encoding.Default.GetBytes(strText));return&& System.Text.Encoding.Default.GetString(result);}
C# MD5加密 using System.Security.C
private void btnOK_Click(object sender, System.EventArgs e){&& string strConn = "server=192.168.0.51;database=User id= password=123";&& if(texName.Text.Trim()=="")&& {&&& this.RegisterStartupScript("sf","&script language='javascript'&alert('用户名不能为空');document.all('texName').focus()&/script&");&&&&& }&& else if(texPassword.Text.Trim()=="")&& {&&& this.RegisterStartupScript("sfs","&script language='javascript'&alert('密码不能为空');document.all('texPassword').focus()&/script&");&&&&& }&& else&& {&&& //将获取的密码加密与数据库中加了密的密码相比较&&& byte[] by = puteHash(utf.GetBytes(texPassword.Text.Trim()));&&& string resultPass = System.Text.UTF8Encoding.Unicode.GetString(by);&&& conn.ConnectionString=strC&&& SqlCommand comm = new SqlCommand();&&& string name = texName.Text.Trim().ToString();&&& mandText="select Ruser_pwd,Ruser_nm from Ruser where Accountno = @name";&&& comm.Parameters.Add("@name",SqlDbType.NVarChar,40);&&& comm.Parameters["@name"].Value=&&& try&&& {&&&& &&&& conn.Open();&&&& comm.Connection=&&&& SqlDataReader dr=comm.ExecuteReader();&&&& if(dr.Read())&&&& {&&&&& //用户存在,对密码进行检查&&&&& if(dr.GetValue(0).Equals(resultPass))&&&&& {&&&&&& string user_name=dr.GetValue(1).ToString();&&&&&& string user_Accountno=texName.Text.Trim();&&&&&& Session["logon_name"]=user_&&&&&& Session["logon_Accountno"]=user_A&&&&&& //登录成功,进行页面导向
&&&&& }&&&&& else&&&&& {&&&&&& this.RegisterStartupScript("wp","&script language='javascript'&alert('密码错误,请检查。')&/script&");&&&&& }&&&&& &&&& }&&&& else&&&& {&&&&& this.RegisterStartupScript("nu","&script language=javascript&alert('用户名不存在,请检查。')&/script&");&&&& }&&& }&&& catch(Exception exec)&&& { &&&& this.RegisterStartupScript("wc","&script language=javascript&alert('网络连接有异,请稍后重试。')&/script&");&&& } &&& finally&&& {&&&& conn.Close();&&& }&& }}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 方法三C# MD5加密
C#开发笔记&& 一、C# MD5-16位加密实例,32位加密实例(两种方法)
环境:vs.net2005/sql server2000/xp测试通过1.MD5 16位加密实例using Susing System.Collections.Gusing System.Tusing System.Security.C
namespace md5{&&& class Program&&& {&&&&&&& static void Main(string[] args)&&&&&&& {&&&&&&&&&&&& Console.WriteLine(UserMd5("8"));&&&&&&&&&&&& Console.WriteLine(GetMd5Str("8"));&&&&&&&& }&&&&&&& /**//// &summary&&&&&&&& /// MD5 16位加密 加密后密码为大写&&&&&&& /// &/summary&&&&&&&& /// &param name="ConvertString"&&/param&&&&&&&& /// &returns&&/returns&&&&&&&& public static string GetMd5Str(string ConvertString)&&&&&&& {&&&&&&&&&&&& MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();&&&&&&&&&&& string t2 = BitConverter.puteHash(UTF8Encoding.Default.GetBytes(ConvertString)), 4, 8);&&&&&&&&&&&& t2 = t2.Replace("-", "");&&&&&&&&&&& return t2;&&&&&&&& }
& /**//// &summary&&&&&&&& /// MD5 16位加密 加密后密码为小写&&&&&&& /// &/summary&&&&&&&& /// &param name="ConvertString"&&/param&&&&&&&& /// &returns&&/returns&&&&&&&& public static string GetMd5Str(string ConvertString)&&&&&&& {&&&&&&&&&&&& MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();&&&&&&&&&&& string t2 = BitConverter.puteHash(UTF8Encoding.Default.GetBytes(ConvertString)), 4, 8);&&&&&&&&&&&& t2 = t2.Replace("-", "");
&&&&&&&&&&& t2 = t2.ToLower();
&&&&&&&&&&&& return t2;&&&&&&&& }
&&&&&&& /**//// &summary&&&&&&&& /// MD5 32位加密&&&&&&& /// &/summary&&&&&&&& /// &param name="str"&&/param&&&&&&&& /// &returns&&/returns&&&&&&& static& string UserMd5(string str)&&&&&&& {&&&&&&&&&&& string cl =&&&&&&&&&&& string pwd = "";&&&&&&&&&&&& MD5 md5 = MD5.Create();//实例化一个md5对像&&&&&&&&&&& // 加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择 &&&&&&&&&&& byte[] s = puteHash(Encoding.UTF8.GetBytes(cl));&&&&&&&&&&& // 通过使用循环,将字节类型的数组转换为字符串,此字符串是常规字符格式化所得&&&&&&&&&&& for (int i = 0; i & s.L i++)&&&&&&&&&&& {&&&&&&&&&&&&&&& // 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符
&&&&&&&&&&&&&&&& pwd = pwd + s[i].ToString("X");&&&&&&&&&&&&&&& &&&&&&&&&&&& }&&&&&&&&&&&&&&&&&&& }&&&& }}
using System.Security.Cusing System.T
public static string StringToMD5Hash(string inputString)&&&&&&& {&&&&&&&&&&& MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();&&&&&&&&&&& byte[] encryptedBytes = puteHash(Encoding.ASCII.GetBytes(inputString));&&&&&&&&&&& StringBuilder sb = new StringBuilder();&&&&&&&&&&& for (int i = 0; i & encryptedBytes.L i++)&&&&&&&&&&& {&&&&&&&&&&&&&&& sb.AppendFormat("{0:x2}", encryptedBytes[i]);&&&&&&&&&&& }&&&&&&&&&&& return sb.ToString();&&&&&&& }
二、首先在界面中引入:using System.Web.S
假设密码对话框名字password,对输入的密码加密后存入变量pwd中,语句如下:
&string pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(password.Text, "MD5");
如果要录入则录入pwd,这样数据库实际的密码为202*****等乱码了。
如果登录查询则要:
select username,password from users where username='"+ UserName.Text +"' and password='"+ pwd +"'
因为MD5不能解密,只能把原始密码加密后与数据库中加密的密码比较
三、C# MD5 加密方法 16位或32位
& public string md5(string str,int code) & { &&& if(code==16) //16位MD5加密(取32位加密的9~25字符) && { &&&&&& return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str,"MD5").ToLower().Substring(8,16) ; && }& && else//32位加密 && { &&&&&& return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str,"MD5").ToLower(); && }& &}
&&& 四、做一个网站时,必然涉及用户登录,用户登录必然涉及密码,密码必然涉及安全,安全必然涉及加密。加密现时最流行也是据说最安全的算法是MD5算法,MD5是一种不可逆的算法,也就是 明文经过加密后,根据加密过的密文无法还原出明文来。目前有好多网站专搞MD5破密,百度上搜一下MD5就搜出一大堆了,今天早上无聊试了几个破密网站,6位以内纯数字密码的MD5密文可以还原出明文,长点的或带字符的就不行了。他们是采用穷举对比的,就是说把收录到的明文和密文放到数据库里,通过密文的对比来确定明文,毕竟收录的数据有限,所以破解的密码很有限。扯远了,搞破密MD5需要大量的MONEY,因为要一个运算得超快的计算机和一个查找性能超好的数据库和超大的数据库收录。但搞加密就比较简单。以下是我用C#写的一个MD5加密的方法,用到.NET中的方法, 通过MD5_APP.StringToMD5(string str, int i)可以直接调用:
public class MD5_APP{&public MD5_APP()&{&&&& &}
&&& public static string StringToMD5(string str, int i)&&& {&&&&&&& //获取要加密的字段,并转化为Byte[]数组&&&&&&& byte[] data = System.Text.Encoding.Unicode.GetBytes(str.ToCharArray());&&&&&&& //建立加密服务&&&&&&& System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();&&&&&&& //加密Byte[]数组&&&&&&& byte[] result = puteHash(data);&&&&&&& //将加密后的数组转化为字段&&&&&&& if (i == 16 && str != string.Empty)&&&&&&& {&&&&&&&&&&& return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower().Substring(8, 16);&&&&&&& }&&&&&&& else if (i == 32 && str != string.Empty)&&&&&&& {&&&&&&&&&&& return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower();&&&&&&& }&&&&&&& else&&&&&&& {&&&&&&&&&&& switch (i)&&&&&&&&&&& {&&&&&&&&&&&&&&& case 16: return "000";&&&&&&&&&&&&&&& case 32: return "000000";&&&&&&&&&&&&&&& default: return "请确保调用函数时第二个参数为16或32";&&&&&&&&&&& }
&&&&&&& }&&& }
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:12126次
排名:千里之外java - Spring dependency issue - no matching editors or conversion strategy found - Stack Overflow
to customize your list.
Announcing Stack Overflow Documentation
We started with Q&A. Technical documentation is next, and we need your help.
Whether you're a beginner or an experienced developer, you can contribute.
I have a web application which fails while deployment. I get following error:
Aug 8, :21 PM org.springframework.web.context.ContextLoader initWebApplicationContext
SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.filterChains': Cannot resolve reference to bean 'org.springframework.security.web.DefaultSecurityFilterChain#2' while setting bean property 'sourceList' with key [2]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#2': Cannot resolve reference to bean 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0' while setting constructor argument with key [3]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0': Cannot resolve reference to bean 'CustomLoginSuccessHandler' while setting bean property 'authenticationSuccessHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'CustomLoginSuccessHandler': Injection of autowired nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.abc.xyz.ldapservices.LDAPUtil com.abc.xyz.web.CustomLoginSuccessHandler.ldapC nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ldapContact' defined in ServletContext resource [/WEB-INF/spring/spring-security.xml]: Initializ nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type '$Proxy213 implementing org.springframework.ldap.core.LdapOperations,org.springframework.beans.factory.InitializingBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'org.springframework.ldap.core.LdapTemplate' for property 'ldapTemplate'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [$Proxy213 implementing org.springframework.ldap.core.LdapOperations,org.springframework.beans.factory.InitializingBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [org.springframework.ldap.core.LdapTemplate] for property 'ldapTemplate': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:329)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:353)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:154)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1391)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1132)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:589)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at weblogic.servlet.internal.EventsManager$FireContextListenerAction.run(EventsManager.java:661)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
at weblogic.servlet.internal.EventsManager.executeContextListener(EventsManager.java:241)
at weblogic.servlet.internal.EventsManager.notifyContextCreatedEvent(EventsManager.java:198)
at weblogic.servlet.internal.EventsManager.notifyContextCreatedEvent(EventsManager.java:183)
at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:1783)
at weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:2807)
at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1661)
at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:822)
at weblogic.application.internal.ExtensibleModuleWrapper$StartStateChange.next(ExtensibleModuleWrapper.java:360)
at weblogic.application.internal.ExtensibleModuleWrapper$StartStateChange.next(ExtensibleModuleWrapper.java:356)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:42)
at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:138)
at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:213)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:208)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:42)
at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:70)
at weblogic.application.internal.flow.StartModulesFlow.activate(StartModulesFlow.java:24)
at weblogic.application.internal.BaseDeployment$2.next(BaseDeployment.java:729)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:42)
at weblogic.application.internal.BaseDeployment.activate(BaseDeployment.java:258)
at weblogic.application.internal.SingleModuleDeployment.activate(SingleModuleDeployment.java:48)
at weblogic.application.internal.DeploymentStateChecker.activate(DeploymentStateChecker.java:165)
at weblogic.deploy.internal.targetserver.AppContainerInvoker.activate(AppContainerInvoker.java:80)
at weblogic.deploy.internal.targetserver.operations.AbstractOperation.activate(AbstractOperation.java:586)
at weblogic.deploy.internal.targetserver.operations.ActivateOperation.activateDeployment(ActivateOperation.java:148)
at weblogic.deploy.internal.targetserver.operations.ActivateOperation.doCommit(ActivateOperation.java:114)
at weblogic.deploy.internal.targetserver.mit(AbstractOperation.java:339)
at weblogic.deploy.internal.targetserver.DeploymentManager.handleDeploymentCommit(DeploymentManager.java:846)
at weblogic.deploy.internal.targetserver.DeploymentManager.activateDeploymentList(DeploymentManager.java:1275)
at weblogic.deploy.internal.targetserver.DeploymentManager.handleCommit(DeploymentManager.java:442)
at weblogic.deploy.internal.mit(DeploymentServiceDispatcher.java:176)
at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.doCommitCallback(DeploymentReceiverCallbackDeliverer.java:195)
at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.access$100(DeploymentReceiverCallbackDeliverer.java:13)
at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer$2.run(DeploymentReceiverCallbackDeliverer.java:68)
at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:550)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:295)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:254)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#2': Cannot resolve reference to bean 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0' while setting constructor argument with key [3]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0': Cannot resolve reference to bean 'CustomLoginSuccessHandler' while setting bean property 'authenticationSuccessHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'CustomLoginSuccessHandler': Injection of autowired nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.abc.xyz.ldapservices.LDAPUtil com.abc.xyz.web.CustomLoginSuccessHandler.ldapC nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ldapContact' defined in ServletContext resource [/WEB-INF/spring/spring-security.xml]: Initializ nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type '$Proxy213 implementing org.springframework.ldap.core.LdapOperations,org.springframework.beans.factory.InitializingBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'org.springframework.ldap.core.LdapTemplate' for property 'ldapTemplate'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [$Proxy213 implementing org.springframework.ldap.core.LdapOperations,org.springframework.beans.factory.InitializingBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [org.springframework.ldap.core.LdapTemplate] for property 'ldapTemplate': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:329)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:353)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:154)
at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:615)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:148)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1049)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:953)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:490)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:323)
I am loading my configuration XML's in web.xml using:
&context-param&
&param-name&contextConfigLocation&/param-name&
&param-value&
WEB-INF/spring/spring-security.xml
WEB-INF/spring/applicationContext-db.xml
WEB-INF/spring/applicationContext.xml
&/param-value&
&/context-param&
The error comes from my spring-security.xml file, which has :
&security:http auto-config="true" use-expressions="true"
access-denied-page="/auth/denied"&
&security:intercept-url pattern="/auth/login"
access="permitAll" /&
&security:intercept-url pattern="/main/admin"
access="hasRole('ROLE_ADMIN')" /&
&security:intercept-url pattern="/main/common"
access="hasRole('ROLE_RI')" /&
&security:form-login login-page="/auth/login"
authentication-failure-url="/auth/login?error=true"
default-target-url="/main/common" authentication-success-handler-ref="CustomLoginSuccessHandler" /&
&security:logout invalidate-session="true" logout-url="/auth/logout"
success-handler-ref="CustomLogoutSuccessHandler" /&
&/security:http&
&bean id="CustomLoginSuccessHandler"
class="com.abc.xyz.web.CustomLoginSuccessHandler"&
&property name="ldapContact" ref="ldapContact"&&/property&
&bean id="CustomLogoutSuccessHandler"
class="com.abc.xyz.web.CustomLogoutSuccessHandler"&
&security:authentication-manager&
&security:ldap-authentication-provider
user-search-filter="(uid={0})" user-search-base="ou=Users"
group-search-filter="(roleOccupant={0})" group-search-base="ou=Groups"
group-role-attribute="cn" role-prefix="ROLE_"&
&/security:ldap-authentication-provider&
&/security:authentication-manager&
&security:ldap-server url="ldap://localhost:389/dc=maxcrc,dc=com"
manager-dn="cn=Manager,dc=maxcrc,dc=com" manager-password="secret" /&
&security:global-method-security
secured-annotations="enabled" /&
&bean id="placeHolderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&
&property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/&
&property name="location" value="/WEB-INF/classes/ldap.properties"&&/property&
&context:property-placeholder location="classpath:WEB-INF/classes/ldap.properties"/&
&bean id="contextSource"
class="org.springframework.security.ldap.DefaultSpringSecurityContextSource"&
&constructor-arg value="ldap://localhost:389/dc=maxcrc,dc=com" /&
&property name="userDn" value="cn=Manager,dc=maxcrc,dc=com" /&
&property name="password" value="secret" /&
&bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate"&
&constructor-arg ref="contextSource" /&
&property name="ignorePartialResultException" value="true" /&
&bean id="ldapContact" class="com.abc.xyz.ldapservices.LDAPUtil"&
&property name="ldapTemplate" ref="ldapTemplate" /&
My CustomLoginSuccessHandler class is like:
public class CustomLoginSuccessHandler implements AuthenticationSuccessHandler {
/** The redirect strategy. */
private RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
/** The ldap contact. */
@Autowired
LDAPUtil ldapC
I am new to spring but i guess it is due to the bean dependencies configuration.
1. What is the sequence of spring bean dependency, does it uses
sequence of XML configuration from web.xml?
2. Suppose I refer bean A
in a XML file, which is defined below where it is refered, will it
create any problem?
My LDAPUtil class is like:
private LdapOperations ldapT
public void setLdapTemplate(LdapTemplate ldapTemplate) {
this.ldapTemplate = ldapT
1,41831548
error gives useful elements. The cause (last error in chain) is (stripped down string) :
Error creating bean with name 'ldapContact' ... Failed to convert property value of type '$Proxy213 implementing ... LdapOperations ...' to required type '....LdapTemplate' for property 'ldapTemplate'
You did not show LdapUtil source, but from CustomSuccessHandler and the error, I presume it contains somewhere :
@Autowired
LdapTemplate ldapT
The error indicates that there is an AOP proxying mechanisme around the ldapTemplatebean.
It is not a problem, except that by default Spring AOP uses JDK proxies, and a proxy implements all interfaces, but does not extends the original class. You should be able to fix the error by referencing ldapTemplate through an interface :
@Autowired
LdapOperations ldapT
Alternatively, you can ask Spring to use cglib proxies, that do extend original class by using &aop:config proxy-target-class = "true"& in xml file (or &aop:aspectj-autoproxy proxy-target-class="true"/& if you are using annotations). But that requires cglib jars to be on the path, and as you can use interfaces, I advice you to use first solution.
Your edited post shows how you load ldapTemplate in LdapUtil. You load it as a class, when you should use the interface that way :
private LdapOperations ldapT
public void setLdapTemplate(LdapOperations ldapTemplate) {
this.ldapTemplate = ldapT
42.8k42669
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabled

我要回帖

更多关于 sid service name 的文章

 

随机推荐