/** * @see org.apache.wicket.authorization.IAuthorizationStrategy#isActionAuthorized(org.apache.wicket.Component, * org.apache.wicket.authorization.Action) */ @Override public boolean isActionAuthorized(final Component component, final Action action) { // Get component's class final Class<?> componentClass = component.getClass(); return isActionAuthorized(componentClass, action); }
protected boolean isActionAuthorized(final Class<?> componentClass, final Action action) { // Check for a single action if (!check(action, componentClass.getAnnotation(AuthorizeAction.class))) { return false; } // Check for multiple actions final AuthorizeActions authorizeActionsAnnotation = componentClass.getAnnotation(AuthorizeActions.class); if (authorizeActionsAnnotation != null) { for (final AuthorizeAction authorizeActionAnnotation : authorizeActionsAnnotation.actions()) { if (!check(action, authorizeActionAnnotation)) { return false; } } } return true; }
private boolean isResourceAnnotationSatisfied(AuthorizeResource annotation) { if (annotation != null) { // we have an annotation => we must check for the required roles return hasAny(new Roles(annotation.value())); } else { // no annotation => no required roles => this resource can be accessed return true; } } }
/** * @param action * The action to check * @param authorizeActionAnnotation * The annotations information * @return False if the action is not authorized */ private boolean check(final Action action, final AuthorizeAction authorizeActionAnnotation) { if (authorizeActionAnnotation != null) { if (action.getName().equals(authorizeActionAnnotation.action())) { Roles deniedRoles = new Roles(authorizeActionAnnotation.deny()); if (isEmpty(deniedRoles) == false && hasAny(deniedRoles)) { return false; } Roles acceptedRoles = new Roles(authorizeActionAnnotation.roles()); if (!hasAny(acceptedRoles)) { return false; } } } return true; }
/** * Construct. * * @param roleCheckingStrategy * the role checking strategy */ public RoleAuthorizationStrategy(final IRoleCheckingStrategy roleCheckingStrategy) { add(new AnnotationsRoleAuthorizationStrategy(roleCheckingStrategy)); add(new MetaDataRoleAuthorizationStrategy(roleCheckingStrategy)); } }
/** * Check if annotated instantiation is allowed. * * @param authorizeInstantiationAnnotation * The annotations information * @return False if the instantiation is not authorized */ private <T extends IRequestableComponent> boolean check( final AuthorizeInstantiation authorizeInstantiationAnnotation) { // We are authorized unless we are found not to be boolean authorized = true; // Check class annotation first because it is more specific than package annotation if (authorizeInstantiationAnnotation != null) { authorized = hasAny(new Roles(authorizeInstantiationAnnotation.value())); } return authorized; }
@WicketHomePage @MountPath("home") @AuthorizeInstantiation("USER") public class HomePage extends BasePage { public HomePage(){ add(new BookmarkablePageLink<String>("customersLink", CustomerListPage.class)); } }
@Override public boolean isResourceAuthorized(IResource resource, PageParameters pageParameters) { Class<? extends IResource> resourceClass = resource.getClass(); boolean allowedByResourceItself = isResourceAnnotationSatisfied( resourceClass.getAnnotation(AuthorizeResource.class)); boolean allowedByPackage = isResourceAnnotationSatisfied( resourceClass.getPackage().getAnnotation(AuthorizeResource.class)); return allowedByResourceItself && allowedByPackage; }
/** * @param action * The action to check * @param authorizeActionAnnotation * The annotations information * @return False if the action is not authorized */ private boolean check(final Action action, final AuthorizeAction authorizeActionAnnotation) { if (authorizeActionAnnotation != null) { if (action.getName().equals(authorizeActionAnnotation.action())) { Roles deniedRoles = new Roles(authorizeActionAnnotation.deny()); if (isEmpty(deniedRoles) == false && hasAny(deniedRoles)) { return false; } Roles acceptedRoles = new Roles(authorizeActionAnnotation.roles()); if (!hasAny(acceptedRoles)) { return false; } } } return true; }
/** * Construct. * * @param roleCheckingStrategy * the role checking strategy */ public RoleAuthorizationStrategy(final IRoleCheckingStrategy roleCheckingStrategy) { add(new AnnotationsRoleAuthorizationStrategy(roleCheckingStrategy)); add(new MetaDataRoleAuthorizationStrategy(roleCheckingStrategy)); } }
private boolean isResourceAnnotationSatisfied(AuthorizeResource annotation) { if (annotation != null) { // we have an annotation => we must check for the required roles return hasAny(new Roles(annotation.value())); } else { // no annotation => no required roles => this resource can be accessed return true; } } }
/** * Check if annotated instantiation is allowed. * * @param authorizeInstantiationAnnotation * The annotations information * @return False if the instantiation is not authorized */ private <T extends IRequestableComponent> boolean check( final AuthorizeInstantiation authorizeInstantiationAnnotation) { // We are authorized unless we are found not to be boolean authorized = true; // Check class annotation first because it is more specific than package annotation if (authorizeInstantiationAnnotation != null) { authorized = hasAny(new Roles(authorizeInstantiationAnnotation.value())); } return authorized; }
protected boolean isActionAuthorized(final Class<?> componentClass, final Action action) { // Check for a single action if (!check(action, componentClass.getAnnotation(AuthorizeAction.class))) { return false; } // Check for multiple actions final AuthorizeActions authorizeActionsAnnotation = componentClass.getAnnotation(AuthorizeActions.class); if (authorizeActionsAnnotation != null) { for (final AuthorizeAction authorizeActionAnnotation : authorizeActionsAnnotation.actions()) { if (!check(action, authorizeActionAnnotation)) { return false; } } } return true; }
/** * @see org.apache.wicket.authorization.IAuthorizationStrategy#isActionAuthorized(org.apache.wicket.Component, * org.apache.wicket.authorization.Action) */ @Override public boolean isActionAuthorized(final Component component, final Action action) { // Get component's class final Class<?> componentClass = component.getClass(); return isActionAuthorized(componentClass, action); }
@MountPath("customers") @AuthorizeInstantiation("USER") public class CustomerListPage extends BasePage {
@Override public boolean isResourceAuthorized(IResource resource, PageParameters pageParameters) { Class<? extends IResource> resourceClass = resource.getClass(); boolean allowedByResourceItself = isResourceAnnotationSatisfied( resourceClass.getAnnotation(AuthorizeResource.class)); boolean allowedByPackage = isResourceAnnotationSatisfied( resourceClass.getPackage().getAnnotation(AuthorizeResource.class)); return allowedByResourceItself && allowedByPackage; }
public WicketOrientDbAuthorizationStrategy(final IRoleCheckingStrategy roleCheckingStrategy) { add(new AnnotationsRoleAuthorizationStrategy(roleCheckingStrategy)); add(new OrientResourceAuthorizationStrategy()); } }
public WicketOrientDbAuthorizationStrategy(final IRoleCheckingStrategy roleCheckingStrategy) { add(new AnnotationsRoleAuthorizationStrategy(roleCheckingStrategy)); add(new OrientResourceAuthorizationStrategy()); } }