本文整理匯總了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;
}