當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。