I'm currently developing an application for my new brand company
and I'd like that supports authentication with username and password , and OpenId.
I could install Acegi Grails Plugin
, but I'm very happy using JSecurity
, ok no problem let's hack.
First, I have to install OpenId Plugin
to support OpenId authenticantion, with this plugin I can manage login process and get openid identifier for OpenId users.
With JSecurity installed and done QuickStart,
I need to pass Openid identifier in auth process, for this I've created class OpenIdContextHolder
to save in a ThreadLocal context.
class OpenIdContextHolder{ private static final ThreadLocal openIdContextHolder = new ThreadLocal(); static void resetContext() { openIdContextHolder.set(null); } static def getOpenIdIdentifier(){ openIdContextHolder.get() } static void setOpenIdIdentifier(id){ openIdContextHolder.set(id) } }
def login = { if(openidService.isLoggedIn(session)){ return redirect(action:'signIn') } return [ username: params.username, rememberMe: (params.rememberMe != null), targetUri: params.targetUri ] } def signIn = { // if is logged with openid set contextholder if(openidService.isLoggedIn(session)){ def openId = openidService.getIdentifier(session) OpenIdContextHolder.setOpenIdIdentifier(openId) params.rememberMe = true params.username = openId params.password = "nullpass" } def authToken = new UsernamePasswordToken(params.username, params.password) // continues the default generated code... // ... }
def authenticate(authToken) { log.info "Attempting to authenticate ${authToken.username} in DB realm..." // experimental!! def openid = OpenIdContextHolder.getOpenIdIdentifier() OpenIdContextHolder.resetContext() log.info "OpenIdContextHolder request with openid: ${openid}" if(openid){ def openidUser = User.findByOpenid(openid) if (!openidUser) throw new UnknownAccountException("No account found for user [${username}]") log.info "Jsecurity with Openid ${openidUser.username} : ${openidUser.openid}" authToken.password = 'secret' authToken.username = openidUser.username }else { def openidUser = User.findByUsername(authToken.username) if(openidUser?.openid?.trim()){ // trying to access with password for openid user log.info "Jsecurity: Trying to access with password for user: ${openidUser.username} : ${openidUser.openid}" throw new IncorrectCredentialsException("Invalid password for openid user '${authToken.username}', try to use openid instead user:password") } } def username = authToken.username // continues the default generated code... // ...
And that's all folks.
相关推荐
Web Hacking 101: How to Make Money Hacking Ethically By 作者: Peter Yaworski Pub Date: 2018 ISBN: n/a Pages: 255 Language: English Format: PDF Size: 10 Mb With a Foreword written by HackerOne Co-...
No Starch Press Penetration Testing A Hands On Introduction to Hacking 英文版 pdf
netfilter_hacking_howto(中文版FreeWill翻译小组):这份文档描述了Linux上的netfilter构架,如何剖析它,以及一些在它上层的某些主要系统,诸如包过滤、连接追踪和网络地址翻译。
### netfilter-hacking-HOWTO #### 一、引言 1. **什么是netfilter?** - **定义**:netfilter是Linux内核中一个用于处理数据包的框架,它位于常规的Berkeley套接字接口之外。该框架允许在特定的数据包传输阶段...
The Basics of Hacking and Penetration Testing, Second Edition, serves as an introduction to the steps required to complete a penetration test or perform an ethical hack from beginning to end....
Hacking How to Hack Computers, Basic Security and Penetration Testing 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
本文档旨在根据提供的《Unreliable Guide To Hacking The Linux Kernel》的部分内容,深入分析与Linux内核相关的技术知识点,包括但不限于基本规则、系统调用替代方案、常见的死锁情况、通用函数及其用法等。...
Ethical hacking is closely related to Python. For this reason this book is organized in three parts. The first part deals with the basics of ethical hacking; the second part deals with Python 3; and ...
### Unreliable Guide to Hacking the Linux Kernel:关键知识点概览 #### 1. 引言 本文档《Unreliable Guide To Hacking The Linux Kernel》由Rusty Russell撰写,旨在为有经验的C程序员提供一份Linux内核开发的...
The goal of this book is to share the art of hacking with everyone. Understanding hacking techniques is often difficult, since it requires both breadth and depth of knowledge. Many hacking texts seem ...
Hacking is the art of creating problem solving, whether used to find an unconventional solution to a difficult problem or to exploit holes in sloppy programming. Many people call themselves hackers, ...
原版Hacking - Firewalls And Networks How To Hack Into Remote Computers.pdf
How to master hacking skills[for green hands] 一篇较简短的说明,希望能对生手有所帮助
《渗透测试:实战黑客入门》是一本深受广大IT爱好者,特别是初涉网络安全领域的读者欢迎的书籍。这本书以其实践性强、理论与实际操作相结合的特点,成为了许多美国高校网络安全课程的首选教材。...
Hacking_ A 101 Hacking Guide,hack参考书,值的一看。
Hacking Basic Security Penetration Testing and How to Hack 英文mobi 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除