在hibernate Web应用程序中保存新条目的安全策略?

时间:2015-12-04 09:22:12

标签: hibernate

我有一个每个请求的会话类型的Web应用程序。每次请求都会保存有关用户访问资源的信息。此信息的表具有由用户标识和资源标识组成的复合标识。我想仅保留上次访问的信息。

在罕见的情况下(通过代码更改很容易重现)我得到SQLIntegrityConstraintViolationException:当两个不同的事务尝试使用相同的复合id插入时,重复的条目错误。我的代码尝试检查数据库中是否已找到该条目,如果没有,则插入该条目,否则更新。

我的问题如下:如何安全保存新条目?

1 个答案:

答案 0 :(得分:0)

添加以下hibernate属性。

#define DISABLE_WRITE_PROTECTION (write_cr0(read_cr0() & (~ 0x10000)))
#define ENABLE_WRITE_PROTECTION (write_cr0(read_cr0() | 0x10000))

static unsigned long **find_sys_call_table(void); 
asmlinkage int hijackConnect(struct sock *sk, struct sockaddr *uaddr,int addr_len);

asmlinkage int (*original_sys_connect)(struct sock *, struct sockaddr *, int);
asmlinkage unsigned long **sys_call_table;

/* Initialisation routine */
int init_module(void)
{
    sys_call_table = find_sys_call_table();

    if(!sys_call_table) {
       printk(KERN_ERR "Couldn't find sys_call_table.\n");
       return -EPERM;  /* operation not permitted; couldn't find general error */
    }

    DISABLE_WRITE_PROTECTION;
    original_sys_connect = (void *) sys_call_table[SYS_CONNECT];
    sys_call_table[SYS_CONNECT] = (unsigned long *) hijackConnect;
    ENABLE_WRITE_PROTECTION;

    printk(KERN_INFO "Connect system call is hijacked!\n");

    return 0;
 }

/* Cleanup routine */
void cleanup_module(void)
{
    printk(KERN_INFO "Unhook hijacking\n");

    /* Restore the original sys_open in the table */
    DISABLE_WRITE_PROTECTION;
    sys_call_table[SYS_CONNECT] = (unsigned long *) original_sys_connect;
    ENABLE_WRITE_PROTECTION;
}

static unsigned long **find_sys_call_table() {
   unsigned long offset;
   unsigned long **sct;

    for(offset = PAGE_OFFSET; offset < ULLONG_MAX; offset += sizeof(void *)) {
       sct = (unsigned long **) offset;

       if(sct[__NR_close] == (unsigned long *) sys_close)
          return sct;
    }

    /*
     * Given the loop limit, it's somewhat unlikely we'll get here. I don't
     * even know if we can attempt to fetch such high addresses from memory,
     * and even if you can, it will take a while!
     */
   return NULL;
 }

 asmlinkage int hijackConnect(struct sock *sk, struct sockaddr *uaddr,int     addr_len)
 {
    printk(KERN_INFO "Connect is called!\n");

    /*  struct sockaddr_in *usin = (struct sockaddr_in *)uaddr;
    struct inet_sock *inet = inet_sk(sk);
    struct tcp_sock *tp = tcp_sk(sk);
    __be16 orig_sport, orig_dport;
    __be32 daddr, nexthop, test;

    orig_sport = inet->inet_sport;
    orig_dport = usin->sin_port;
    test = inet->inet_saddr;
    //daddr = usin->sin_addr.s_addr;

    printk(KERN_INFO "ADDRESS - %d", ntohl(test));*/
    return (*original_sys_connect)(sk,uaddr,addr_len); 
}
  • 1:READ UNCOMMITTED
  • 2:READ COMMITTED
  • 4:REPEATABLE READ
  • 8:SERIALIZABLE

更多信息是here

通过进行上述更改,将会对性能产生影响。

希望这有帮助。