当前位置: 首页>>代码示例>>Java>>正文


Java RolesAllowed.value方法代码示例

本文整理汇总了Java中javax.annotation.security.RolesAllowed.value方法的典型用法代码示例。如果您正苦于以下问题:Java RolesAllowed.value方法的具体用法?Java RolesAllowed.value怎么用?Java RolesAllowed.value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.annotation.security.RolesAllowed的用法示例。


在下文中一共展示了RolesAllowed.value方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: SecurityInvocationHandler

import javax.annotation.security.RolesAllowed; //导入方法依赖的package包/类
SecurityInvocationHandler(SessionContext sessionContext, Method beanMethod) {
    this.sessionContext = sessionContext;
    RolesAllowed rolesAllowed = beanMethod.getAnnotation(RolesAllowed.class);

    // a somewhat nasty scenario: a bean is spied using Mockito, so the
    // roles allowed annotations have to be retrieved from the superclass...
    Class<?> declaringClass = beanMethod.getDeclaringClass();
    Class<?> superclass = declaringClass.getSuperclass();
    if (declaringClass.getName().contains("Mockito")
            && !superclass.equals(Object.class)) {
        try {
            Method method = superclass.getMethod(beanMethod.getName(),
                    beanMethod.getParameterTypes());
            rolesAllowed = method.getAnnotation(RolesAllowed.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    if (rolesAllowed == null) {
        this.rolesAllowed = new String[0];
    } else {
        this.rolesAllowed = rolesAllowed.value();
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:26,代码来源:SecurityInvocationHandler.java

示例2: isAccessGranted

import javax.annotation.security.RolesAllowed; //导入方法依赖的package包/类
@Override
public boolean isAccessGranted(UI ui, String beanName) {

	if (applicationContext.findAnnotationOnBean(beanName, DenyAll.class) != null) {
		// DenyAll (no authentication required)
		return false;
	}
	if (applicationContext.findAnnotationOnBean(beanName, PermitAll.class) != null) {
		// PermitAll (no authentication required)
		return true;
	}

	// RolesAllowed - authentication required
	RolesAllowed ra = applicationContext.findAnnotationOnBean(beanName, RolesAllowed.class);
	if (ra != null) {

		// check authentication
		final AuthContext authContext = AuthContext.getCurrent()
				.orElseThrow(() -> new IllegalStateException("No AuthContext available as Context resource: "
						+ "failed to validate RolesAllowed security annotation on View bean name [" + beanName
						+ "]"));
		if (!authContext.getAuthentication().isPresent()) {
			// not authenticated
			return false;
		}

		// check permissions
		if (ra.value().length > 0) {
			// for empty roles names, no role is required, only authentication
			if (!authContext.isPermittedAny(ra.value())) {
				// no roles matches (with ANY semantic)
				return false;
			}
		}
	}

	return true;
}
 
开发者ID:holon-platform,项目名称:holon-vaadin,代码行数:39,代码来源:SecurityAnnotationsViewAccessControl.java

示例3: isRoleAllowed

import javax.annotation.security.RolesAllowed; //导入方法依赖的package包/类
private boolean isRoleAllowed(Method method, UserRoleType roleType) {
    RolesAllowed rolesAllowed = method.getAnnotation(RolesAllowed.class);
    if (rolesAllowed == null) {
        return true;
    }

    for (String role : rolesAllowed.value()) {
        if (role.equals(roleType.name())) {
            return true;
        }
    }

    return false;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:15,代码来源:AccountServiceBeanPermissionTest.java


注:本文中的javax.annotation.security.RolesAllowed.value方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。