-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Shanu: Added spring security plugin. Added the create script
- Loading branch information
Shanu
committed
Dec 3, 2010
1 parent
6e3cc47
commit 27e9910
Showing
55 changed files
with
399 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
*.iml | ||
.idea/ | ||
*.ipr | ||
*.iws | ||
*.log | ||
*.jasper | ||
.idea/ | ||
log/ | ||
out/ | ||
war/ | ||
bin/ | ||
target/ | ||
coverage/ | ||
test/ | ||
/application.properties | ||
src/groovy/Sledgehammer-config.properties | ||
/coverage.* | ||
test/reports/ | ||
web-app/gwt | ||
web-app/WEB-INF/classes | ||
Thumbs.db | ||
/stacktrace.log | ||
lib/gwt/ids-gwt-widgets.jar | ||
lib/gwt/lightsaber.jar | ||
*.ser | ||
/dbdeploy/ | ||
/lib/gwt/lightsaber.jar | ||
web-app/css/main.css | ||
web-app/images/grails_logo.jpg | ||
web-app/images/skin/ | ||
web-app/images/spinner.gif | ||
.DS_Store | ||
extras/ | ||
lib/gwt/gwt-graphics.jar | ||
lib/gwt/ids-gwt-graph.jar | ||
id_file | ||
demodb | ||
demo-config/bak |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
drop schema if exists public cascade; | ||
create table role (id int8 not null, version int8 not null, authority varchar(255) not null unique, primary key (id)); | ||
create table user (id int8 not null, version int8 not null, account_expired bool not null, account_locked bool not null, enabled bool not null, "password" varchar(255) not null, password_expired bool not null, username varchar(255) not null unique, primary key (id)); | ||
create table user_role (role_id int8 not null, user_id int8 not null, primary key (role_id, user_id)); | ||
alter table user_role add constraint FK143BF46A5D1CA167 foreign key (role_id) references role; | ||
alter table user_role add constraint FK143BF46A2476547 foreign key (user_id) references user; | ||
create sequence hibernate_sequence; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
#Grails Metadata file | ||
#Fri Dec 03 16:52:54 IST 2010 | ||
#Fri Dec 03 23:09:40 IST 2010 | ||
app.grails.version=1.3.4 | ||
app.name=MGifts | ||
app.servlet.version=2.4 | ||
app.version=0.1 | ||
plugins.hibernate=1.3.4 | ||
plugins.spring-security-core=1.0.1 | ||
plugins.tomcat=1.3.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
class BootStrap { | ||
def springSecurityService | ||
def init = { servletContext -> | ||
|
||
def init = { servletContext -> | ||
} | ||
def destroy = { | ||
} | ||
} | ||
def destroy = { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ class UrlMappings { | |
} | ||
} | ||
|
||
"/"(view:"/index") | ||
"/"(controller:"/login") | ||
"500"(view:'/error') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
class AdminController{ | ||
def index = { | ||
println "Again coming here..." | ||
render view:'dashboard' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import grails.converters.JSON | ||
|
||
import org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils | ||
|
||
import org.springframework.security.authentication.AccountExpiredException | ||
import org.springframework.security.authentication.CredentialsExpiredException | ||
import org.springframework.security.authentication.DisabledException | ||
import org.springframework.security.authentication.LockedException | ||
import org.springframework.security.core.context.SecurityContextHolder as SCH | ||
import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter | ||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter | ||
|
||
class LoginController { | ||
|
||
/** | ||
* Dependency injection for the authenticationTrustResolver. | ||
*/ | ||
def authenticationTrustResolver | ||
|
||
/** | ||
* Dependency injection for the springSecurityService. | ||
*/ | ||
def springSecurityService | ||
|
||
/** | ||
* Default action; redirects to 'defaultTargetUrl' if logged in, /login/auth otherwise. | ||
*/ | ||
def index = { | ||
if (springSecurityService.isLoggedIn()) { | ||
redirect controller: 'admin', action:'index' | ||
} | ||
else { | ||
redirect action: auth, params: params | ||
} | ||
} | ||
|
||
/** | ||
* Show the login page. | ||
*/ | ||
def auth = { | ||
|
||
def config = SpringSecurityUtils.securityConfig | ||
|
||
if (springSecurityService.isLoggedIn()) { | ||
redirect uri: config.successHandler.defaultTargetUrl | ||
return | ||
} | ||
|
||
String view = 'auth' | ||
String postUrl = "${request.contextPath}${config.apf.filterProcessesUrl}" | ||
render view: view, model: [postUrl: postUrl, | ||
rememberMeParameter: config.rememberMe.parameter] | ||
} | ||
|
||
/** | ||
* Show denied page. | ||
*/ | ||
def denied = { | ||
if (springSecurityService.isLoggedIn() && | ||
authenticationTrustResolver.isRememberMe(SCH.context?.authentication)) { | ||
// have cookie but the page is guarded with IS_AUTHENTICATED_FULLY | ||
redirect action: full, params: params | ||
} | ||
} | ||
|
||
/** | ||
* Login page for users with a remember-me cookie but accessing a IS_AUTHENTICATED_FULLY page. | ||
*/ | ||
def full = { | ||
def config = SpringSecurityUtils.securityConfig | ||
render view: 'auth', params: params, | ||
model: [hasCookie: authenticationTrustResolver.isRememberMe(SCH.context?.authentication), | ||
postUrl: "${request.contextPath}${config.apf.filterProcessesUrl}"] | ||
} | ||
|
||
/** | ||
* Callback after a failed login. Redirects to the auth page with a warning message. | ||
*/ | ||
def authfail = { | ||
|
||
def username = session[UsernamePasswordAuthenticationFilter.SPRING_SECURITY_LAST_USERNAME_KEY] | ||
String msg = '' | ||
def exception = session[AbstractAuthenticationProcessingFilter.SPRING_SECURITY_LAST_EXCEPTION_KEY] | ||
if (exception) { | ||
if (exception instanceof AccountExpiredException) { | ||
msg = SpringSecurityUtils.securityConfig.errors.login.expired | ||
} | ||
else if (exception instanceof CredentialsExpiredException) { | ||
msg = SpringSecurityUtils.securityConfig.errors.login.passwordExpired | ||
} | ||
else if (exception instanceof DisabledException) { | ||
msg = SpringSecurityUtils.securityConfig.errors.login.disabled | ||
} | ||
else if (exception instanceof LockedException) { | ||
msg = SpringSecurityUtils.securityConfig.errors.login.locked | ||
} | ||
else { | ||
msg = SpringSecurityUtils.securityConfig.errors.login.fail | ||
} | ||
} | ||
|
||
if (springSecurityService.isAjax(request)) { | ||
render([error: msg] as JSON) | ||
} | ||
else { | ||
flash.message = msg | ||
redirect action: auth, params: params | ||
} | ||
} | ||
|
||
/** | ||
* The Ajax success redirect url. | ||
*/ | ||
def ajaxSuccess = { | ||
render([success: true, username: springSecurityService.authentication.name] as JSON) | ||
} | ||
|
||
/** | ||
* The Ajax denied redirect url. | ||
*/ | ||
def ajaxDenied = { | ||
render([error: 'access denied'] as JSON) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils | ||
|
||
class LogoutController { | ||
|
||
/** | ||
* Index action. Redirects to the Spring security logout uri. | ||
*/ | ||
def index = { | ||
// TODO put any pre-logout code here | ||
redirect uri: SpringSecurityUtils.securityConfig.logout.filterProcessesUrl // '/j_spring_security_logout' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.malabar.gift | ||
|
||
class AppUser { | ||
|
||
String username | ||
String password | ||
boolean enabled | ||
boolean accountExpired | ||
boolean accountLocked | ||
boolean passwordExpired | ||
|
||
static constraints = { | ||
username blank: false, unique: true | ||
password blank: false | ||
} | ||
|
||
static mapping = { | ||
password column: '`password`' | ||
} | ||
|
||
Set<Role> getAuthorities() { | ||
AppUserRole.findAllByAppUser(this).collect { it.role } as Set | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.malabar.gift | ||
|
||
import org.apache.commons.lang.builder.HashCodeBuilder | ||
|
||
class AppUserRole implements Serializable { | ||
|
||
AppUser appUser | ||
Role role | ||
|
||
boolean equals(other) { | ||
if (!(other instanceof AppUserRole)) { | ||
return false | ||
} | ||
|
||
other.appUser?.id == appUser?.id && | ||
other.role?.id == role?.id | ||
} | ||
|
||
int hashCode() { | ||
def builder = new HashCodeBuilder() | ||
if (appUser) builder.append(appUser.id) | ||
if (role) builder.append(role.id) | ||
builder.toHashCode() | ||
} | ||
|
||
static AppUserRole get(long appUserId, long roleId) { | ||
find 'from AppUserRole where appUser.id=:appUserId and role.id=:roleId', | ||
[appUserId: appUserId, roleId: roleId] | ||
} | ||
|
||
static AppUserRole create(AppUser appUser, Role role, boolean flush = false) { | ||
new AppUserRole(appUser: appUser, role: role).save(flush: flush, insert: true) | ||
} | ||
|
||
static boolean remove(AppUser appUser, Role role, boolean flush = false) { | ||
AppUserRole instance = AppUserRole.findByAppUserAndRole(appUser, role) | ||
instance ? instance.delete(flush: flush) : false | ||
} | ||
|
||
static void removeAll(AppUser appUser) { | ||
executeUpdate 'DELETE FROM AppUserRole WHERE appUser=:appUser', [appUser: appUser] | ||
} | ||
|
||
static void removeAll(Role role) { | ||
executeUpdate 'DELETE FROM AppUserRole WHERE role=:role', [role: role] | ||
} | ||
|
||
static mapping = { | ||
id composite: ['role', 'appUser'] | ||
version false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.malabar.gift | ||
|
||
class Role { | ||
|
||
String authority | ||
|
||
static mapping = { | ||
cache true | ||
} | ||
|
||
static constraints = { | ||
authority blank: false, unique: true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
<%@ page contentType="text/html;charset=UTF-8" %> | ||
<html> | ||
<head><title>Simple GSP page</title></head> | ||
<body>Place your content here</body> | ||
</html> |
Oops, something went wrong.