Skip to content

Commit

Permalink
minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
orubel committed Jul 12, 2017
1 parent f23c1c3 commit d0db71d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 31 deletions.
7 changes: 3 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,13 @@ dependencies {
compile 'org.springframework.boot:spring-boot-autoconfigure'
provided 'org.springframework.boot:spring-boot-starter-tomcat'

compile('org.grails.plugins:spring-security-core:3.1.1') {
exclude(module: 'org.springframework.security:spring-security-web')
}
//compile('org.grails.plugins:spring-security-core:3.1.1') {
// exclude(module: 'org.springframework.security:spring-security-web')
//}

compile('org.grails.plugins:spring-security-rest:2.0.0.M2') {
exclude(module: 'com.google.guava:guava-io')
exclude(module: 'org.springframework.security:spring-security-web')
exclude(module: 'org.grails.plugins:spring-security-core')
}

runtime('org.grails:grails-web'){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class ContentTypeMarshallerFilter extends OncePerRequestFilter {

String format = (request?.format)?request.format.toUpperCase():'JSON'
List formats = ['XML', 'JSON']
String contentType = doesContentTypeMatch(request)

if(!doesContentTypeMatch(request)){
println("ContentType ["+request.getContentType()+"] does not match Requested Format ["+request.format.toUpperCase()+"]")
Expand Down Expand Up @@ -84,7 +83,6 @@ class ContentTypeMarshallerFilter extends OncePerRequestFilter {

}
} catch (Exception e) {
println("ContentTypeMarshallerFilter: Formatting exception "+e)
//log.error "marshalling failed: ${e.message}"
response.status = 401
response.setHeader('ERROR', 'Failed')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ class TokenCacheValidationFilter extends GenericFilterBean {
return
}
} catch (AuthenticationException ae) {
//log.debug "Authentication failed: ${ae.message}"
httpResponse.status = 401
httpResponse.setHeader('ERROR', 'Authorization Attempt Failed')
httpResponse.writer.flush()
Expand All @@ -107,23 +106,6 @@ class TokenCacheValidationFilter extends GenericFilterBean {

}

// ehcache may not be accessible at filter. need to grab bean
boolean checkAuth(List roles, AccessToken accessToken){
try {
if(roles.size()==1 && roles[0]=='permitAll'){
return true
}

if (accessToken.getAuthorities()*.authority.any { roles.contains(it.toString())}) {
return true
}

return false
}catch(Exception e) {
throw new Exception("[ApiCommProcess :: checkAuth] : Exception - full stack trace follows:",e)
}
}

@CompileDynamic
private void processFilterChain(ServletRequest request, ServletResponse response, FilterChain chain, AccessToken authenticationResult) {
HttpServletRequest httpRequest = request as HttpServletRequest
Expand All @@ -132,7 +114,7 @@ class TokenCacheValidationFilter extends GenericFilterBean {
String actualUri = httpRequest.requestURI - httpRequest.contextPath

if (!active) {
//log.debug "Token validation is disabled. Continuing the filter chain"
//println("Token validation is disabled. Continuing the filter chain")
return
}

Expand All @@ -156,7 +138,6 @@ class TokenCacheValidationFilter extends GenericFilterBean {
return
}


ApplicationContext ctx = Holders.grailsApplication.mainContext
GrailsCacheManager grailsCacheManager = ctx.getBean("grailsCacheManager");

Expand All @@ -170,7 +151,6 @@ class TokenCacheValidationFilter extends GenericFilterBean {
session['cache'] = cache as LinkedHashMap
}


String version = cache['cacheversion']

if(!cache?."${version}"?."${action}"){
Expand All @@ -181,7 +161,6 @@ class TokenCacheValidationFilter extends GenericFilterBean {
}else{
def session = RCH.currentRequestAttributes().getSession()
session['cache'] = cache
//println(session['cache'].getAttribute('cacheversion'))
}

List roles = cache?."${version}"?."${action}"?.roles as List
Expand All @@ -192,15 +171,30 @@ class TokenCacheValidationFilter extends GenericFilterBean {
//httpResponse.writer.flush()
return
}else {
//System.out.println("####[TokenCacheValidationFilter :: processFilterChain] ${actualUri} / ${validationEndpointUrl}")
log.debug "Continuing the filter chain"
//log.debug "Continuing the filter chain"
}
}
} else {
log.debug "Request does not contain any token. Letting it continue through the filter chain"
//println("Request does not contain any token. Letting it continue through the filter chain")
}

chain.doFilter(request, response)
}


boolean checkAuth(List roles, AccessToken accessToken){
List tokenRoles = []
accessToken.getAuthorities()*.authority.each() { tokenRoles.add(it) }
try {
if (roles.size()==1 && roles[0] == 'permitAll') {
return true
} else if(roles.intersect(tokenRoles).size()>0) {
return true
}
return false
}catch(Exception e) {
//println("[TokenCacheValidationFilter :: checkAuth] : Exception - full stack trace follows:"+e)
throw new Exception("[TokenCacheValidationFilter :: checkAuth] : Exception - full stack trace follows:",e)
}
}
}

0 comments on commit d0db71d

Please sign in to comment.