怀化市优化办电话seo是什么意思职业
web/
2025/10/5 4:13:31/
文章来源:
怀化市优化办电话,seo是什么意思职业,那个公司做的网站详情页好看,昆明网络推广spring防止爬虫Spring Security可以为您做很多事情。 帐户被封锁#xff0c;密码盐。 但是蛮力阻断剂呢#xff1f; 那是你必须自己做的。 幸运的是#xff0c;Spring是一个非常灵活的框架#xff0c;因此对其进行配置并不是什么大问题。 让我向您展示一些如何针对Grai… spring防止爬虫 Spring Security可以为您做很多事情。 帐户被封锁密码盐。 但是蛮力阻断剂呢 那是你必须自己做的。 幸运的是Spring是一个非常灵活的框架因此对其进行配置并不是什么大问题。 让我向您展示一些如何针对Grails应用程序执行此操作的指南。 首先您必须在config.groovy中启用springSecurityEventListener grails.plugins.springsecurity.useSecurityEventListener true 然后实现监听器 在/ src / bruteforce中创建类 /**
Registers all failed attempts to login. Main purpose to count attempts for particular account ant block user*/
class AuthenticationFailureListener implements ApplicationListener {LoginAttemptCacheService loginAttemptCacheServiceOverridevoid onApplicationEvent(AuthenticationFailureBadCredentialsEvent e) {loginAttemptCacheService.failLogin(e.authentication.name)}
} 接下来我们必须创建侦听器以成功登录 在同一包装中 /**Listener for successfull logins. Used for reseting number on unsuccessfull logins for specific account
*/
class AuthenticationSuccessEventListener implements ApplicationListener{LoginAttemptCacheService loginAttemptCacheServiceOverridevoid onApplicationEvent(AuthenticationSuccessEvent e) {loginAttemptCacheService.loginSuccess(e.authentication.name)}
} 我们没有将它们放在grails-app文件夹中因此我们需要将这些类作为spring bean重新命名。 在grails-app / conf / spring / resources.groovy中添加下一行 beans {authenticationFailureListener(AuthenticationFailureListener) {loginAttemptCacheService ref(loginAttemptCacheService)}authenticationSuccessEventListener(AuthenticationSuccessEventListener) {loginAttemptCacheService ref(loginAttemptCacheService)}
} 您可能会注意到LoginAttemptCacheService loginAttemptCacheService的用法 让我们实现它。 这将是典型的grails服务 package com.picsel.officeanywhereimport com.google.common.cache.CacheBuilder
import com.google.common.cache.CacheLoader
import com.google.common.cache.LoadingCacheimport java.util.concurrent.TimeUnit
import org.apache.commons.lang.math.NumberUtils
import javax.annotation.PostConstructclass LoginAttemptCacheService {private LoadingCacheattempts;private int allowedNumberOfAttemptsdef grailsApplicationPostConstructvoid init() {allowedNumberOfAttempts grailsApplication.config.brutforce.loginAttempts.allowedNumberOfAttemptsint time grailsApplication.config.brutforce.loginAttempts.timelog.info account block configured for $time minutesattempts CacheBuilder.newBuilder().expireAfterWrite(time, TimeUnit.MINUTES).build({0} as CacheLoader);}/*** Triggers on each unsuccessful login attempt and increases number of attempts in local accumulator* param login - username which is trying to login* return*/def failLogin(String login) {def numberOfAttempts attempts.get(login)log.debug fail login $login previous number for attempts $numberOfAttemptsnumberOfAttemptsif (numberOfAttempts allowedNumberOfAttempts) {blockUser(login)attempts.invalidate(login)} else {attempts.put(login, numberOfAttempts)}}/*** Triggers on each successful login attempt and resets number of attempts in local accumulator* param login - username which is login*/def loginSuccess(String login) {log.debug successfull login for $loginattempts.invalidate(login)}/*** Disable user account so it would not able to login* param login - username that has to be disabled*/private void blockUser(String login) {log.debug blocking user: $logindef user User.findByUsername(login)if (user) {user.accountLocked true;user.save(flush: true)}}
} 我们将使用Google番石榴库中的CacheBuilder。 因此将下一行添加到BuildConfig.groovy dependencies {runtime com.google.guava:guava:11.0.1} 最后一步将服务配置添加到cinfig.groovy brutforce {loginAttempts {time 5allowedNumberOfAttempts 3} 就是这样您准备运行您的应用程序。 对于典型的Java项目几乎一切都是一样的。 相同的侦听器和相同的服务。 有关Spring Security Events的更多信息 有关使用Google番石榴进行缓存的更多信息 Grails用户可以简单地使用此插件https://github.com/grygoriy/bruteforcedefender 祝您编程愉快别忘了分享 参考在Grygoriy Mykhalyuno的博客博客中我们的JCG合作伙伴 Grygoriy Mykhalyuno 使用Spring Security防止了暴力攻击 。 翻译自: https://www.javacodegeeks.com/2012/10/spring-security-prevent-brute-force.htmlspring防止爬虫
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/87154.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!