Skip to content

Commit 20694c9

Browse files
author
Diego Silva
committed
inicio
1 parent ecd1455 commit 20694c9

File tree

79 files changed

+4410
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+4410
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ target
88
/plugins
99
/web-app/plugins
1010
/web-app/WEB-INF/classes
11+
.classpath
12+
.project

application.properties

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#Grails Metadata file
2+
#Thu Nov 01 15:13:53 BRST 2012
3+
app.grails.version=2.1.1
4+
app.name=hacking_london
5+
app.servlet.version=2.4
6+
app.version=0.1
7+
plugins.hibernate=2.1.1
8+
plugins.spring-security-core=1.2.6
9+
plugins.svn=1.0.0.M1
10+
plugins.tomcat=2.1.1

grails-app/conf/BootStrap.groovy

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import hacking.OrgUser
2+
import hacking.Organization
3+
import hacking.Role
4+
import hacking.User
5+
import hacking.UserRole
6+
7+
class BootStrap {
8+
9+
def init = { servletContext ->
10+
def adminRole = Role.findByAuthority('ROLE_ADMIN') ?: new Role(authority: 'ROLE_ADMIN').save()
11+
def userRole = Role.findByAuthority('ROLE_USER') ?: new Role(authority: 'ROLE_USER').save()
12+
13+
def org1 = Organization.findByName('Org1') ?: new Organization(name: 'Org1').save()
14+
def org2 = Organization.findByName('Org2') ?: new Organization(name: 'Org2').save()
15+
16+
if (!User.count()) {
17+
def admin = new User(username: 'admin', password: 'password', enabled: true).save()
18+
new OrgUser(user: admin, organization: org1).save()
19+
UserRole.create admin, adminRole
20+
21+
def user = new User(username: 'user', password: 'password', enabled: true).save()
22+
new OrgUser(user: user, organization: org2).save()
23+
UserRole.create user, userRole
24+
25+
def disabledUser = new User(username: 'disabled', password: 'password').save()
26+
new OrgUser(user: disabledUser, organization: org1).save()
27+
UserRole.create disabledUser, userRole
28+
}
29+
}
30+
}

grails-app/conf/BuildConfig.groovy

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
grails.project.work.dir = 'target'
2+
3+
grails.project.dependency.resolution = {
4+
5+
inherits 'global'
6+
log 'warn'
7+
8+
repositories {
9+
grailsPlugins()
10+
grailsHome()
11+
grailsCentral()
12+
}
13+
14+
dependencies {}
15+
}
16+

grails-app/conf/Config.groovy

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
grails.project.groupId = appName
2+
grails.mime.file.extensions = false
3+
grails.mime.use.accept.header = false
4+
grails.mime.types = [
5+
html: ['text/html','application/xhtml+xml'],
6+
xml: ['text/xml', 'application/xml'],
7+
text: 'text/plain',
8+
js: 'text/javascript',
9+
rss: 'application/rss+xml',
10+
atom: 'application/atom+xml',
11+
css: 'text/css',
12+
csv: 'text/csv',
13+
all: '*/*',
14+
json: ['application/json','text/json'],
15+
form: 'application/x-www-form-urlencoded',
16+
multipartForm: 'multipart/form-data'
17+
]
18+
19+
grails.views.default.codec = 'none'
20+
grails.views.gsp.encoding = 'UTF-8'
21+
grails.converters.encoding = 'UTF-8'
22+
grails.views.gsp.sitemesh.preprocess = true
23+
grails.scaffolding.templates.domainSuffix = 'Instance'
24+
grails.json.legacy.builder = false
25+
grails.enable.native2ascii = true
26+
grails.logging.jul.usebridge = true
27+
grails.spring.bean.packages = []
28+
29+
environments {
30+
development {}
31+
test {}
32+
production {}
33+
}
34+
35+
log4j = {
36+
error 'org.codehaus.groovy.grails',
37+
'org.springframework',
38+
'org.hibernate',
39+
'net.sf.ehcache.hibernate'
40+
}
41+
42+
// Added by the Spring Security Core plugin:
43+
//grails.plugins.springsecurity.userLookup.userDomainClassName = 'hacking.User'
44+
//grails.plugins.springsecurity.userLookup.authorityJoinClassName = 'hacking.UserRole'
45+
//grails.plugins.springsecurity.authority.className = 'hacking.Role'

grails-app/conf/DataSource.groovy

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
dataSource {
2+
pooled = true
3+
driverClassName = 'org.hsqldb.jdbcDriver'
4+
username = 'sa'
5+
password = ''
6+
}
7+
hibernate {
8+
cache.use_second_level_cache = true
9+
cache.use_query_cache = true
10+
cache.provider_class = 'net.sf.ehcache.hibernate.EhCacheProvider'
11+
}
12+
13+
environments {
14+
development {
15+
dataSource {
16+
dbCreate = 'create-drop'
17+
url = 'jdbc:hsqldb:mem:devDB'
18+
}
19+
}
20+
test {
21+
dataSource {
22+
dbCreate = 'update'
23+
url = 'jdbc:hsqldb:mem:testDb'
24+
}
25+
}
26+
production {
27+
dataSource {
28+
dbCreate = 'update'
29+
url = 'jdbc:hsqldb:file:prodDb;shutdown=true'
30+
}
31+
}
32+
}

grails-app/conf/UrlMappings.groovy

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class UrlMappings {
2+
3+
static mappings = {
4+
"/$controller/$action?/$id?"{
5+
constraints {
6+
// apply constraints here
7+
}
8+
}
9+
10+
"/"(view:"/index")
11+
"500"(view:'/error')
12+
}
13+
}

grails-app/conf/hibernate/.gitignore

Whitespace-only changes.
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import hacking.extralogin.auth.OrganizationAuthenticationProvider
2+
import hacking.extralogin.ui.OrganizationFilter
3+
import hacking.logout.CustomLogoutSuccessHandler
4+
5+
import org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils
6+
7+
beans = {
8+
9+
def conf = SpringSecurityUtils.securityConfig
10+
11+
// custom authentication
12+
authenticationProcessingFilter(OrganizationFilter) {
13+
authenticationManager = ref('authenticationManager')
14+
sessionAuthenticationStrategy = ref('sessionAuthenticationStrategy')
15+
authenticationSuccessHandler = ref('authenticationSuccessHandler')
16+
authenticationFailureHandler = ref('authenticationFailureHandler')
17+
rememberMeServices = ref('rememberMeServices')
18+
authenticationDetailsSource = ref('authenticationDetailsSource')
19+
filterProcessesUrl = conf.apf.filterProcessesUrl
20+
usernameParameter = conf.apf.usernameParameter
21+
passwordParameter = conf.apf.passwordParameter
22+
continueChainBeforeSuccessfulAuthentication = conf.apf.continueChainBeforeSuccessfulAuthentication
23+
allowSessionCreation = conf.apf.allowSessionCreation
24+
postOnly = conf.apf.postOnly
25+
}
26+
27+
// custom authentication
28+
daoAuthenticationProvider(OrganizationAuthenticationProvider) {
29+
passwordEncoder = ref('passwordEncoder')
30+
saltSource = ref('saltSource')
31+
preAuthenticationChecks = ref('preAuthenticationChecks')
32+
postAuthenticationChecks = ref('postAuthenticationChecks')
33+
}
34+
35+
// custom logout redirect
36+
logoutSuccessHandler(CustomLogoutSuccessHandler) {
37+
redirectStrategy = ref('redirectStrategy')
38+
defaultTargetUrl = conf.logout.afterLogoutUrl
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
import grails.converters.JSON
2+
3+
import javax.servlet.http.HttpServletResponse
4+
5+
import org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils
6+
7+
import org.springframework.security.authentication.AccountExpiredException
8+
import org.springframework.security.authentication.CredentialsExpiredException
9+
import org.springframework.security.authentication.DisabledException
10+
import org.springframework.security.authentication.LockedException
11+
import org.springframework.security.core.context.SecurityContextHolder as SCH
12+
import org.springframework.security.web.WebAttributes
13+
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
14+
15+
class LoginController {
16+
17+
/**
18+
* Dependency injection for the authenticationTrustResolver.
19+
*/
20+
def authenticationTrustResolver
21+
22+
/**
23+
* Dependency injection for the springSecurityService.
24+
*/
25+
def springSecurityService
26+
27+
/**
28+
* Default action; redirects to 'defaultTargetUrl' if logged in, /login/auth otherwise.
29+
*/
30+
def index = {
31+
if (springSecurityService.isLoggedIn()) {
32+
redirect uri: SpringSecurityUtils.securityConfig.successHandler.defaultTargetUrl
33+
}
34+
else {
35+
redirect action: 'auth', params: params
36+
}
37+
}
38+
39+
/**
40+
* Show the login page.
41+
*/
42+
def auth = {
43+
44+
def config = SpringSecurityUtils.securityConfig
45+
46+
if (springSecurityService.isLoggedIn()) {
47+
redirect uri: config.successHandler.defaultTargetUrl
48+
return
49+
}
50+
51+
String view = 'auth'
52+
String postUrl = "${request.contextPath}${config.apf.filterProcessesUrl}"
53+
render view: view, model: [postUrl: postUrl,
54+
rememberMeParameter: config.rememberMe.parameter]
55+
}
56+
57+
/**
58+
* The redirect action for Ajax requests.
59+
*/
60+
def authAjax = {
61+
response.setHeader 'Location', SpringSecurityUtils.securityConfig.auth.ajaxLoginFormUrl
62+
response.sendError HttpServletResponse.SC_UNAUTHORIZED
63+
}
64+
65+
/**
66+
* Show denied page.
67+
*/
68+
def denied = {
69+
if (springSecurityService.isLoggedIn() &&
70+
authenticationTrustResolver.isRememberMe(SCH.context?.authentication)) {
71+
// have cookie but the page is guarded with IS_AUTHENTICATED_FULLY
72+
redirect action: 'full', params: params
73+
}
74+
}
75+
76+
/**
77+
* Login page for users with a remember-me cookie but accessing a IS_AUTHENTICATED_FULLY page.
78+
*/
79+
def full = {
80+
def config = SpringSecurityUtils.securityConfig
81+
render view: 'auth', params: params,
82+
model: [hasCookie: authenticationTrustResolver.isRememberMe(SCH.context?.authentication),
83+
postUrl: "${request.contextPath}${config.apf.filterProcessesUrl}"]
84+
}
85+
86+
/**
87+
* Callback after a failed login. Redirects to the auth page with a warning message.
88+
*/
89+
def authfail = {
90+
91+
def username = session[UsernamePasswordAuthenticationFilter.SPRING_SECURITY_LAST_USERNAME_KEY]
92+
String msg = ''
93+
def exception = session[WebAttributes.AUTHENTICATION_EXCEPTION]
94+
if (exception) {
95+
if (exception instanceof AccountExpiredException) {
96+
msg = g.message(code: "springSecurity.errors.login.expired")
97+
}
98+
else if (exception instanceof CredentialsExpiredException) {
99+
msg = g.message(code: "springSecurity.errors.login.passwordExpired")
100+
}
101+
else if (exception instanceof DisabledException) {
102+
msg = g.message(code: "springSecurity.errors.login.disabled")
103+
}
104+
else if (exception instanceof LockedException) {
105+
msg = g.message(code: "springSecurity.errors.login.locked")
106+
}
107+
else {
108+
msg = g.message(code: "springSecurity.errors.login.fail")
109+
}
110+
}
111+
112+
if (springSecurityService.isAjax(request)) {
113+
render([error: msg] as JSON)
114+
}
115+
else {
116+
flash.message = msg
117+
redirect action: 'auth', params: params
118+
}
119+
}
120+
121+
/**
122+
* The Ajax success redirect url.
123+
*/
124+
def ajaxSuccess = {
125+
render([success: true, username: springSecurityService.authentication.name] as JSON)
126+
}
127+
128+
/**
129+
* The Ajax denied redirect url.
130+
*/
131+
def ajaxDenied = {
132+
render([error: 'access denied'] as JSON)
133+
}
134+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils
2+
3+
class LogoutController {
4+
5+
/**
6+
* Index action. Redirects to the Spring security logout uri.
7+
*/
8+
def index = {
9+
// TODO put any pre-logout code here
10+
redirect uri: SpringSecurityUtils.securityConfig.logout.filterProcessesUrl // '/j_spring_security_logout'
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package hacking
2+
3+
import grails.plugins.springsecurity.Secured
4+
5+
class SecureController {
6+
7+
def index = {
8+
render 'not secured'
9+
}
10+
11+
@Secured(['ROLE_ADMIN'])
12+
def admin = {
13+
render 'you have ROLE_ADMIN'
14+
}
15+
16+
@Secured(['ROLE_USER'])
17+
def user = {
18+
render 'you have ROLE_USER'
19+
}
20+
21+
@Secured(['ROLE_ADMIN', 'ROLE_USER'])
22+
def adminOrUser = {
23+
render 'you have ROLE_ADMIN or ROLE_USER'
24+
}
25+
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package hacking
2+
3+
class OrgUser {
4+
5+
User user
6+
Organization organization
7+
8+
static constraints = {
9+
organization unique: 'user'
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package hacking
2+
3+
class Organization {
4+
5+
String name
6+
7+
static constraints = {
8+
name unique: true, blank: false
9+
}
10+
}

0 commit comments

Comments
 (0)