Back Forum Reply New

Retrieving login information from database

Heya guys!

I've just begun using spring-security and I've encountered a problem, I can't seem to find how to retrieve username, password and Role from a database.

My goal is to make sure that the authentication page matches the usernames, passowrds and roles in my DB instead of;

lt;authentication-managergt;       lt;authentication-providergt;lt;password-encoder hash=quot;md5quot;/gt;lt;user-servicegt;    lt;user name=quot;rodquot; password=quot;a564de63c2d0da68cf47586ee05984d7quot; authorities=quot;ROLE_USERquot; /gt;    lt;user name=quot;diannequot; password=quot;65d15fe9156f9c4bbffd98085992a44equot; authorities=quot;ROLE_USERquot; /gt;    lt;user name=quot;scottquot; password=quot;2b58af6dddbd072ed27ffc86725d7d3aquot; authorities=quot;ROLE_USERquot; /gt;    lt;user name=quot;peterquot; password=quot;22b5c9accc6e1ba628cedc63a72d57f8quot; authorities=quot;ROLE_ADMINquot; /gt;lt;/user-servicegt;       lt;/authentication-providergt;   lt;/authentication-managergt;

I've tried to find pages about this, thought since i am new to this, I might have been looking in the wrong places.

some code that might be of use for you;

(applicationContext-security.xml)  lt;from use-expressions=quot;truequot;gt;       lt;intercept-ucl pattern=quot;/quot; access=quot;permitAllquot;/gt;       lt;intercept-ucl pattern=quot;/**quot; access=quot;isAuthenticated()quot; /gt;       lt;form-login /gt;       lt;logout /gt;   lt;/fromgt;

(Web.xml)
lt;context-paramgt;   lt;param-namegt;contextConfigLocationlt;/param-namegt;   lt;param-valuegt;     /WEB-INF/news-service-servlet.xml     /WEB-INF/applicationContext-security.xml   lt;/param-valuegt;
lt;/context-paramgt;

lt;filtergt;   lt;filter-namegt;springSecurityFilterChainlt;/filter-namegt;   lt;filter-classgt;org..web.filter.DelegatingFil  terProxylt;/filter-classgt;
lt;/filtergt;
lt;filter-mappinggt;   lt;filter-namegt;springSecurityFilterChainlt;/filter-namegt;   lt;ucl-patterngt;/*lt;/ucl-patterngt;
lt;/filter-mappinggt;

Any help or pointer in the right direction would be most valued.

Thanks!

Try following some of the spring security sample applications. You can configure a lt;jdbc-user-servicegt; instead of the in-memory user service you have now. The JDBC user service can point to any database and access it via JDBC, but is still easily configurable via the Spring Security XML configuration. ref. Section 6.2.2 of the docs.

.apache.xerces.internal.util.ErrorHandl  erWrapper.createSAXParseException(ErrorHandlerWrap  per.java:198)
at com.sun.org.apache.xerces.internal.util.ErrorHandl  erWrapper.error(ErrorHandlerWrapper.java:134)
at com.sun.org.apache.xerces.internal.impl.XMLErrorRe  porter.reportError(XMLErrorReporter.java:387)
at com.sun.org.apache.xerces.internal.impl.XMLErrorRe  porter.reportError(XMLErrorReporter.java:321)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSche  maValidator.handleStartElement(XMLSchemaValidator.  java:1919)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSche  maValidator.startElement(XMLSchemaValidator.java:7  09)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocum  entScannerImpl.scanStartElement(XMLNSDocumentScann  erImpl.java:376)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocum  entScannerImpl$NSContentDriver.scanRootElementHook  (XMLNSDocumentScannerImpl.java:602)
at com.sun.org.apache.xerces.internal.impl.XMLDocumen  tFragmentScannerImpl$FragmentContentDriver.next(XM  LDocumentFragmentScannerImpl.java:3080)
at com.sun.org.apache.xerces.internal.impl.XMLDocumen  tScannerImpl$PrologDriver.next(XMLDocumentScannerI  mpl.java:899)

applicationcontext-security:Code:
lt;?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?gt;

lt;beans
xmlns=quot;schema/securityquot;
xmlns:beans=quot;schema/beansquot;
xmlns:p=quot;schema/pquot;
xmlns:xsi=quot;2001/XMLSchema-instancequot;
xmlns:context=quot;schema/contextquot;
xsi:schemaLocation=quot;schema/beans schema/beans/spring-beans-2.5.xsd            schema/security schema/security/spring-security-3.0.xsd             schema/context schema/context/spring-context-2.5.xsdquot;gt;

lt;global-method-security pre-post-annotations=quot;enabledquot;gt;
lt;!--
AspectJ pointcut expression that locates our quot;postquot; method and
applies security that way lt;protect-pointcut expression=quot;execution(*
bigbank.*Service.post*(..))quot; access=quot;ROLE_TELLERquot;/gt;
--gt;
lt;/global-method-securitygt;

lt;from use-expressions=quot;truequot;gt;
lt;intercept-ucl pattern=quot;/quot; access=quot;permitAllquot; /gt;
lt;intercept-ucl pattern=quot;/**quot; access=quot;isAuthenticated()quot; /gt;
lt;form-login /gt;
lt;logout /gt;
lt;/fromgt;

lt;context:property-placeholder location=quot;classpath:/jdbc.propertiesquot; /gt;
Code:
lt;bean id=quot;dataSourcequot;
class=quot;org..jdbc.datasource.DriverManagerDataSourcequot;gt;
lt;property name=quot;driverClassNamequot; value=quot;${jdbc.driverClassName}quot; /gt;
lt;property name=quot;uclquot; value=quot;${jdbc.ucl}quot; /gt;
lt;property name=quot;usernamequot; value=quot;${jdbc.username}quot; /gt;
lt;property name=quot;passwordquot; value=quot;${jdbc.password}quot; /gt;
lt;/beangt;

lt;bean id=quot;userDetailsServicequot;
class=quot;org..security.core.userdetails.jdbc.JdbcDaoImplquot;gt;
lt;property name=quot;dataSourcequot; ref=quot;dataSourcequot; /gt;
lt;/beangt;
Is there anything that is totally wrong here?

Sorry for asking alot of questions, very glad that u guys can find the time to help me


Originally Posted by ymerIs there anything that is totally wrong here?

Sorry for asking alot of questions, very glad that u guys can find the time to help me

From the previous post it appears that beans is not using the default namespaceCode:
lt;?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?gt;

lt;beans
xmlns=quot;schema/securityquot;
xmlns:beans=quot;schema/beansquot;
xmlns:p=quot;schema/pquot;so you need to specify your configuration with the beans: prefix. For example...Code:
lt;beans:bean id=quot;dataSourcequot;
class=quot;org..jdbc.datasource.DriverManagerDataSourcequot;gt; lt;beans:property name=quot;driverClassNamequot; value=quot;${jdbc.driverClassName}quot; /gt; ...
lt;/beans:beangt;Thanks alot mate, that solved the problem completely!

Keep up the awesome work everyone!
¥
Back Forum Reply New