小编Spa*_*key的帖子

@PreAuthorize不适用于方法安全规则和方法参数

我将Spring Security添加到一个Spring项目中.系统的体系结构是REST,用户可以访问不同的资源.

我想向拥有此信息的管理员和用户提供个人信息访问权限.我已经开始简单:过滤用户配置文件,如下所示:

在我的服务层中,我想使用方法注释并包含方法参数.

@PreAuthorize("hasRole('ROLE_ADMIN') or principal.userId == #id")
public Usuario getUser(int id) throws DAOException {
    ...
}
Run Code Online (Sandbox Code Playgroud)

但这根本不起作用.当请求此URL时,任何用户都可以看到所有配置文件(管理员和所有用户)(Web层):

@RequestMapping(value="/user/{uid}", method=RequestMethod.GET)
    public ModelAndView getUser(@PathVariable int uid) throws DAOException {
        userDAO = new UsuarioJPADAO();
        userService.setUsuarioDAO(userDAO);

    return new ModelAndView("user", "user", userService.getUser(uid));
}
Run Code Online (Sandbox Code Playgroud)

这是我的 security.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
       xmlns:beans="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
       http://www.springframework.org/schema/security
       http://www.springframework.org/schema/security/spring-security-3.1.xsd">

<!-- Security Annotations -->
    <global-method-security 
        pre-post-annotations="enabled"/>

<http auto-config="true" use-expressions="true">
    <intercept-url pattern="/css/**" access="permitAll" />
    <intercept-url pattern="/images/**" access="permitAll" />
    <intercept-url pattern="/js/**" access="permitAll" />
    <intercept-url …
Run Code Online (Sandbox Code Playgroud)

java annotations aspectj spring-security

11
推荐指数
1
解决办法
1万
查看次数

使用JPA中的MAX()无法使用SELECT查询获得正确的值

我是JPA的新手,当我尝试使用MAX()函数查询数据库时遇到问题.我的功能代码如下.谁能帮我?谢谢.

public int getMaxId(){

    entityManager = this.entityManagerFactory.createEntityManager();

    Query query = entityManager.createQuery("SELECT * FROM user WHERE id = (SELECT MAX(u.id) FROM user u)");
    User user = (User) query.getSingleResult();

    int id = user.getId();
    return id;
}
Run Code Online (Sandbox Code Playgroud)

我正在使用JPA,TopLink和Apache Derby.我的方法应该返回表用户的最大id.

编辑:我从服务中调用该函数:

try {
        int id = userDAO.getMaxId();
        logger.info("Max id: " + id);
        user.setId(id+1);

    }
    catch (Exception ex){
        logger.error("Unable to get the max id.");
    }
Run Code Online (Sandbox Code Playgroud)

user.setId()始终为"0".

编辑(2):记录

    Caused by: Exception [EclipseLink-8034] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Error compiling the query …
Run Code Online (Sandbox Code Playgroud)

java jpa toplink derby jpql

6
推荐指数
1
解决办法
4万
查看次数

使用UICollectionView具有不同单元大小的部分

我必须在Swift项目中创建一个带有两个不同部分的视图.第一个有七个方形的细胞.第二个有三个矩形的单元格.单元格内的数据是静态的.在所有情况下,这些部分应该适合整个屏幕宽度(主要是横向模式).

我没有太多使用经验,UICollectionViewController因此我决定使用一个UICollectionViewController类和两个可重复使用的单元来完成此操作,但是当我设置第一个单元格宽度时,第二个单元格也受到影响,然后单元格宽度被切割.

我的观点是否正确?我应该使用不同的UICollectionViewControllers(每个部分一个)?

更新:我的控制器代码

import UIKit

class InverterController: UICollectionViewController, UICollectionViewDelegateFlowLayout {

    let moduleCell = "moduleCell"
    let parameterCell = "parameterCell"

    func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
        if section > 0 {
            return CGSizeZero
        } else {
            return CGSize(width: collectionView.frame.width, height: CGFloat(195))
        }
    }

    func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtPath indexPath: NSIndexPath) -> CGSize {

        var newSize = CGSizeZero

        if indexPath.section == 0 {

            newSize =  CGSizeMake(CGFloat(105), CGFloat(105)) …
Run Code Online (Sandbox Code Playgroud)

ios uicollectionview swift

5
推荐指数
1
解决办法
5353
查看次数