gpt4 book ai didi

spring - 登录 Controller 并在grails 3.0.0M1中查看

转载 作者:行者123 更新时间:2023-12-02 15:05:37 29 4
gpt4 key购买 nike

安装grails 3.0.5并安装spring security core 3.0.0 M1之后
我创建域用户角色并请求映射。
我尝试运行它。
然后我得到这个错误。

    Line | Method
->> 62 | doFilter in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 53 | doFilter in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
| 62 | doFilter in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread

Caused by MissingPropertyException: No such property: SpringSecurityUtils for class: LoginController
->> 123 | propertyMissing in grails.artefact.gsp.TagLibraryInvoker$Trait$Helper
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 51 | auth in LoginController
| 62 | doFilter in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
| 53 | doFilter in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
| 62 | doFilter in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
这就是我得到的...
enter image description here
在哪里可以找到登录 Controller 和登录 View ?
    import com.akiong.HttpSessionCollector
import com.ryo.security.User
import grails.converters.JSON
import org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils
import org.slf4j.Logger
import org.slf4j.LoggerFactory
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.web.WebAttributes
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter

import javax.servlet.http.HttpServletResponse

class LoginController {

/**
* Dependency injection for the authenticationTrustResolver.
*/
def authenticationTrustResolver

/**
* Dependency injection for the springSecurityService.
*/
def springSecurityService
def cifService

private static final Logger logger = LoggerFactory.getLogger(this)

/**
* Default action; redirects to 'defaultTargetUrl' if logged in, /login/auth otherwise.
*/
def index = {
if (springSecurityService.isLoggedIn()) {
redirect uri: SpringSecurityUtils.securityConfig.successHandler.defaultTargetUrl
}
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]
}

/**
* The redirect action for Ajax requests.
*/
def authAjax = {
response.setHeader 'Location', SpringSecurityUtils.securityConfig.auth.ajaxLoginFormUrl
response.sendError HttpServletResponse.SC_UNAUTHORIZED
}

/**
* Show denied page.
*/
def denied = {
if (springSecurityService.isLoggedIn() &&
authenticationTrustResolver.isRememberMe(SecurityContextHolder.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(SecurityContextHolder.context?.authentication),
postUrl: "${request.contextPath}${config.apf.filterProcessesUrl}"]
}

/**
* Callback after a failed login. Redirects to the auth page with a warning message.
*/
def authfail = {
println "failled akiong"
def username = session[UsernamePasswordAuthenticationFilter.SPRING_SECURITY_LAST_USERNAME_KEY]
String msg = ''
def exception = session[WebAttributes.AUTHENTICATION_EXCEPTION]
if (exception) {
if (exception instanceof AccountExpiredException) {
msg = g.message(code: "springSecurity.errors.login.expired")
}
else if (exception instanceof CredentialsExpiredException) {
msg = g.message(code: "springSecurity.errors.login.passwordExpired")
}
else if (exception instanceof DisabledException) {
msg = g.message(code: "springSecurity.errors.login.disabled")
}
else if (exception instanceof LockedException) {
msg = g.message(code: "springSecurity.errors.login.locked")
}
else {
msg = g.message(code: "springSecurity.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 = {
// i want edit this and add something in this ajaxSuccess
}

private void buildMenuList() {
String appName = grailsApplication.metadata['app.name']
StringBuffer contentSB = new StringBuffer();
def roles = User.get(springSecurityService.getPrincipal().id).getAuthorities()*.getAuthority()
if (roles.size() > 0) {
def menus = com.akiong.security.RoleMenu.createCriteria().list{
projections { distinct("menu") }
role{ 'in'("authority", roles) }
}

def parentMenus = menus.findAll {it.parentMenu}*.parentMenu
parentMenus.addAll(menus.findAll {it.parentMenu == null})
parentMenus.unique()
parentMenus = parentMenus.sort {it.sequence}
def childMenu
def root = grailsAttributes.getApplicationUri(request)

parentMenus.each{ x->
childMenu = menus.findAll {it.parentMenu && it.parentMenu.equals(x)}.sort {it.sequence}
if(childMenu){
if(!x.url.equals("") && !x.url.equals("/")){
contentSB.append("<li class='dropdown'><a class='dropdown-tonggle' data-toggle='dropdown' id='mnImg"+x.id+"' onclick=\"window.location='"+root+x.url+"'\" href='").append(root).append(x.url).append("' class='listMChld'>").append(x.name)
}
else{
contentSB.append("<li class='dropdown' id='mnImg"+x.id+"'><a class='dropdown-tonggle' data-toggle='dropdown'>").append(x.name)
}
contentSB.append("<b class='caret'></b></a><ul class='dropdown-menu'>")
childMenu.each {
contentSB.append("<li><a onclick=\"window.location='"+root+it.url+"'\" href='").append(root).append(it.url).append("' class='listMChld'>")
contentSB.append(it.name).append("</a></li>")
}
contentSB.append("</ul></li>")
}
else{
contentSB.append("<li class='dropdown'><a class='dropdown-tonggle' data-toggle='dropdown' id='mnImg"+x.id+"' onclick=\"window.location='"+root+x.url+"'\" href='").append(root).append(x.url).append("' class='listMChld'>").append(x.name).append("</a></li>")
}
}

}

session.setAttribute("menuList", contentSB.toString())
}

/**
* The Ajax denied redirect url.
*/
def ajaxDenied = {
render([error: 'access denied'] as JSON)
}

def concurrentSession = {

def msg = "Your account is logged in from another browser or location."

if (springSecurityService.isAjax(request)) {
render([error: msg] as JSON)
}
else {
flash.message = msg
redirect action: 'auth', params: params
}

}
}
这是我最近使用grails 2.1.1进行的项目中的logincontroller
顺便说一句,如何编辑登录 Controller ?

最佳答案

看起来问题出在SpringSecurityUtils的import语句上

尝试遵循以下导入语句

import grails.converters.JSON
import grails.plugin.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.Authentication
import org.springframework.security.core.context.SecurityContextHolder
import org.springframework.security.web.WebAttributes

import javax.servlet.http.HttpServletResponse

关于spring - 登录 Controller 并在grails 3.0.0M1中查看,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33295598/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com