猿问

Spring Security Acl 对象

我创建 Acl 的服务是这样的:


@Autowired

JdbcMutableAclService aclService;


public void createAcl(AclDTO aclDTO) throws ClassNotFoundException {


    ObjectIdentity oi = new ObjectIdentityImpl(getClass().getClassLoader().loadClass(aclDTO.getClassPath()),

        aclDTO.getObjectIdentityId());

    Sid sid = new PrincipalSid(aclDTO.getSid());


    Permission p = getPermission(aclDTO.getPermissionDesc());


    // Create or update the relevant ACL

    MutableAcl acl = null;

    try {

        acl = (MutableAcl) this.aclService.readAclById(oi);

    } catch (NotFoundException nfe) {

        acl = aclService.createAcl(oi);

    }


    // Now grant some permissions via an access control entry (ACE)

    acl.insertAce(acl.getEntries().size(), p, sid, true);

    this.aclService.updateAcl(acl);

}

但是这个类似乎有问题,当它运行时,我得到了这样的错误:


2019-02-25 11:02:18.410 错误 10608 --- [XNIO-2 task-1] cssacl.aop.logging.LoggingAspect:com.spring.security.acl.service.AccessGrantService.createAcl() 中的异常原因= 'com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: PROCEDURE security_acl.identity 不存在'并且异常 = 'StatementCallback; 错误的 SQL 语法 [call identity()]; 嵌套异常是 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: PROCEDURE security_acl.identity 不存在'


org.springframework.jdbc.BadSqlGrammarException: StatementCallback; 错误的 SQL 语法 [call identity()]; 嵌套异常是 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: PROCEDURE security_acl.identity 不存在于 org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:93) at org.springframework.jdbc.support。 AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) at org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1398) at org .springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:388) 在 org.springframework.jdbc.core。


如果有人可以帮助我解决这个问题,我将不胜感激!


泛舟湖上清波郎朗
浏览 139回答 2
2回答

慕后森

看来您正在使用 MySQL。我遇到了同样的错误,并通过如下设置 JdbcMutableAclService 解决了它:// Based on https://github.com/eugenp/tutorials/blob/master/spring-security-acl/src/main/java/org/baeldung/acl/config/ACLContext.java@Beanpublic JdbcMutableAclService aclService() {  JdbcMutableAclService jdbcMutableAclService = new JdbcMutableAclService(dataSource, lookupStrategy(), aclCache());  // TODO: for MySQL ONLY  jdbcMutableAclService.setClassIdentityQuery("SELECT @@IDENTITY");  jdbcMutableAclService.setSidIdentityQuery("SELECT @@IDENTITY");  return jdbcMutableAclService;}希望这有帮助。

慕森卡

使用 PostgreSQL 时的解决方案JdbcMutableAclService:@Beanpublic MutableAclService aclService() {    JdbcMutableAclService aclService = new JdbcMutableAclService(dataSource, lookupStrategy(), aclCache());    aclService.setSidIdentityQuery("SELECT currval('acl_sid_id_seq')");    aclService.setClassIdentityQuery("SELECT currval('acl_class_id_seq')");    return aclService;}
随时随地看视频慕课网APP

相关分类

Java
我要回答