本文整理汇总了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();
}
}
示例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;
}
示例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;
}