how to set password size constraint when using spring security core in grails? -


i can't set password size constraint, setting minimum size won't cause problem (since encrypted password long) maximum size causes application fail following stack
(when try insert user (called personne in app) valid password in init/bootstrap):

error org.springframework.boot.springapplication - application startup failed java.lang.nullpointerexception: null     @ org.hibernate.engine.spi.batchfetchqueue.removebatchloadableentitykey(batchfetchqueue.java:163)     @ org.hibernate.engine.internal.statefulpersistencecontext.addentity(statefulpersistencecontext.java:389)     @ org.hibernate.engine.internal.statefulpersistencecontext.addentity(statefulpersistencecontext.java:462)     @ org.hibernate.action.internal.abstractentityinsertaction.makeentitymanaged(abstractentityinsertaction.java:143)     @ org.hibernate.engine.spi.actionqueue.addresolvedentityinsertaction(actionqueue.java:203)     @ org.hibernate.engine.spi.actionqueue.addinsertaction(actionqueue.java:181)     @ org.hibernate.engine.spi.actionqueue.addaction(actionqueue.java:216)     @ org.hibernate.event.internal.abstractsaveeventlistener.addinsertaction(abstractsaveeventlistener.java:334)     @ org.hibernate.event.internal.abstractsaveeventlistener.performsaveorreplicate(abstractsaveeventlistener.java:289)     @ org.hibernate.event.internal.abstractsaveeventlistener.performsave(abstractsaveeventlistener.java:195)     @ org.hibernate.event.internal.abstractsaveeventlistener.savewithgeneratedid(abstractsaveeventlistener.java:126)     @ org.hibernate.event.internal.defaultsaveorupdateeventlistener.savewithgeneratedorrequestedid(defaultsaveorupdateeventlistener.java:209)     @ org.hibernate.event.internal.defaultsaveorupdateeventlistener.entityistransient(defaultsaveorupdateeventlistener.java:194)     @ org.hibernate.event.internal.defaultsaveorupdateeventlistener.performsaveorupdate(defaultsaveorupdateeventlistener.java:114)     @ org.hibernate.event.internal.defaultsaveorupdateeventlistener.onsaveorupdate(defaultsaveorupdateeventlistener.java:90)     @ org.grails.orm.hibernate.support.closureeventtriggeringinterceptor.onsaveorupdate(closureeventtriggeringinterceptor.java:105)     @ org.hibernate.internal.sessionimpl.firesaveorupdate(sessionimpl.java:684)     @ org.hibernate.internal.sessionimpl.saveorupdate(sessionimpl.java:676)     @ org.hibernate.internal.sessionimpl.saveorupdate(sessionimpl.java:671)     @ org.grails.orm.hibernate.abstracthibernategorminstanceapi$_performsave_closure3.docall(abstracthibernategorminstanceapi.groovy:235)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:497)     @ org.springsource.loaded.ri.reflectiveinterceptor.jlrmethodinvoke(reflectiveinterceptor.java:1426)     @ org.codehaus.groovy.reflection.cachedmethod.invoke(cachedmethod.java:93)     @ groovy.lang.metamethod.domethodinvoke(metamethod.java:325)     @ org.codehaus.groovy.runtime.metaclass.closuremetaclass.invokemethod(closuremetaclass.java:294)     @ groovy.lang.metaclassimpl.invokemethod(metaclassimpl.java:1021)     @ groovy.lang.closure.call(closure.java:426)     @ org.codehaus.groovy.runtime.convertedclosure.invokecustom(convertedclosure.java:54)     @ org.codehaus.groovy.runtime.conversionhandler.invoke(conversionhandler.java:124)     @ com.sun.proxy.$proxy95.doinhibernate(unknown source)     @ org.grails.orm.hibernate.grailshibernatetemplate.doexecute(grailshibernatetemplate.java:196)     @ org.grails.orm.hibernate.grailshibernatetemplate.execute(grailshibernatetemplate.java:140)     @ org.grails.orm.hibernate.grailshibernatetemplate.execute(grailshibernatetemplate.java:110)     @ org.grails.orm.hibernate.abstracthibernategorminstanceapi.performsave(abstracthibernategorminstanceapi.groovy:234)     @ org.grails.orm.hibernate.abstracthibernategorminstanceapi.save(abstracthibernategorminstanceapi.groovy:154)     @ org.grails.datastore.gorm.gormentity$trait$helper.save(gormentity.groovy:140)     @ org.grails.datastore.gorm.gormentity$trait$helper$save$3.call(unknown source)     @ org.codehaus.groovy.runtime.callsite.callsitearray.defaultcall(callsitearray.java:48)     @ org.codehaus.groovy.runtime.callsite.abstractcallsite.call(abstractcallsite.java:113)     @ org.codehaus.groovy.runtime.callsite.abstractcallsite.call(abstractcallsite.java:133)     @ ma.ac.uir.ecine.authentification.personne.save(personne.groovy)     @ ma.ac.uir.ecine.authentification.personne.save(personne.groovy)     @ org.grails.datastore.gorm.gormentity$save$0.call(unknown source)     @ org.codehaus.groovy.runtime.callsite.callsitearray.defaultcall(callsitearray.java:48)     @ org.codehaus.groovy.runtime.callsite.abstractcallsite.call(abstractcallsite.java:113)     @ org.codehaus.groovy.runtime.callsite.abstractcallsite.call(abstractcallsite.java:125)     @ bootstrap$_closure1.docall(bootstrap.groovy:13)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:497)     @ org.springsource.loaded.ri.reflectiveinterceptor.jlrmethodinvoke(reflectiveinterceptor.java:1426)     @ org.codehaus.groovy.reflection.cachedmethod.invoke(cachedmethod.java:93)     @ groovy.lang.metamethod.domethodinvoke(metamethod.java:325)     @ org.codehaus.groovy.runtime.metaclass.closuremetaclass.invokemethod(closuremetaclass.java:294)     @ groovy.lang.metaclassimpl.invokemethod(metaclassimpl.java:1021)     @ groovy.lang.metaclassimpl.invokemethod(metaclassimpl.java:1086)     @ groovy.lang.metaclassimpl.invokemethod(metaclassimpl.java:1021)     @ groovy.lang.closure.call(closure.java:426)     @ groovy.lang.closure.call(closure.java:420)     @ grails.util.environment.evaluateenvironmentspecificblock(environment.java:437)     @ grails.util.environment.executeforenvironment(environment.java:430)     @ grails.util.environment.executeforcurrentenvironment(environment.java:406)     @ org.grails.web.servlet.boostrap.defaultgrailsbootstrapclass.callinit(defaultgrailsbootstrapclass.java:62)     @ org.grails.web.servlet.context.grailsconfigutils.executegrailsbootstraps(grailsconfigutils.java:65)     @ org.grails.plugins.web.servlet.context.bootstrapclassrunner.onstartup(bootstrapclassrunner.groovy:53)     @ grails.boot.config.grailsapplicationpostprocessor.onapplicationevent(grailsapplicationpostprocessor.groovy:240)     @ grails.boot.config.grailsapplicationpostprocessor.onapplicationevent(grailsapplicationpostprocessor.groovy)     @ org.springframework.context.event.simpleapplicationeventmulticaster.invokelistener(simpleapplicationeventmulticaster.java:163)     @ org.springframework.context.event.simpleapplicationeventmulticaster.multicastevent(simpleapplicationeventmulticaster.java:136)     @ org.springframework.context.support.abstractapplicationcontext.publishevent(abstractapplicationcontext.java:381)     @ org.springframework.context.support.abstractapplicationcontext.publishevent(abstractapplicationcontext.java:335)     @ org.springframework.context.support.abstractapplicationcontext.finishrefresh(abstractapplicationcontext.java:855)     @ org.springframework.boot.context.embedded.embeddedwebapplicationcontext.finishrefresh(embeddedwebapplicationcontext.java:140)     @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:541)     @ org.springframework.boot.context.embedded.embeddedwebapplicationcontext.refresh(embeddedwebapplicationcontext.java:118)     @ org.springframework.boot.springapplication.refresh(springapplication.java:766)     @ org.springframework.boot.springapplication.createandrefreshcontext(springapplication.java:361)     @ org.springframework.boot.springapplication.run(springapplication.java:307)     @ grails.boot.grailsapp.run(grailsapp.groovy:55)     @ grails.boot.grailsapp.run(grailsapp.groovy:374)     @ grails.boot.grailsapp.run(grailsapp.groovy:363)     @ grails.boot.grailsapp$run.call(unknown source)     @ org.codehaus.groovy.runtime.callsite.callsitearray.defaultcall(callsitearray.java:48)     @ org.codehaus.groovy.runtime.callsite.abstractcallsite.call(abstractcallsite.java:113)     @ org.codehaus.groovy.runtime.callsite.abstractcallsite.call(abstractcallsite.java:133)     @ ecine.application.main(application.groovy:8) 

how solve please? should manually check password size? can check password size before encoding , add error message normal validation? i'm using spring security core

you can use custom validator regex expressions. besides, can limit allowed characters. in link, can see examples: link.

an example of application is:

password blank: false, matches: "^(?=.*[0-9])(?=.*[a-z])(?=.*[a-z])(?=\\s+\$).{8,}\$" 

the password must have following pattern:

  • minlength: 8 characters
  • at least uppercase letter.
  • at least lowercase letter.
  • at least number.
  • it allowed special characters.

edit:

you can check situation in controller before validate() or haserrors() actions. of way, check decrypted password.

example:

string pattern = "^(?=.*[0-9])(?=.*[a-z])(?=.*[a-z])(?=\\s+\$).{8,}\$"   def password = userinstance.password  if (!password.matches(pattern)) {    flash.message = "error in password"   render view:".." } 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -