Example usage for org.apache.wicket Component getDefaultModel

List of usage examples for org.apache.wicket Component getDefaultModel

Introduction

In this page you can find the example usage for org.apache.wicket Component getDefaultModel.

Prototype

public final IModel<?> getDefaultModel() 

Source Link

Document

Gets the model.

Usage

From source file:org.wicketstuff.security.components.SecureComponentHelper.java

License:Apache License

/**
 * Default implementation for {@link ISecureComponent#isActionAuthorized(WaspAction)} and
 * {@link WaspAuthorizationStrategy#isActionAuthorized(Component, org.apache.wicket.authorization.Action)}
 * . First tries to use the {@link ISecurityCheck} from the component if that is not available
 * it tries the {@link ISecureModel} if neither is present the action is authorized on the
 * component./*from   w w  w  .j a va2  s  .com*/
 * 
 * @param component
 *            the component to check
 * @param action
 *            the required action(s)
 * 
 * @return true, if the component is authorized, false otherwise.
 * @see ISecureComponent#isActionAuthorized(WaspAction)
 * @see ISecurityCheck
 * @see ISecureModel
 */
public static boolean isActionAuthorized(Component component, WaspAction action) {
    if (action == null)
        return true;
    ISecurityCheck check = saveGetSecurityCheck(component);
    if (check != null)
        return check.isActionAuthorized(action);
    if (hasSecureModel(component))
        return ((ISecureModel<?>) component.getDefaultModel()).isAuthorized(component, action);
    return true;
}

From source file:org.wicketstuff.security.components.SecureComponentHelper.java

License:Apache License

/**
 * Default implementation for {@link ISecureComponent#isAuthenticated()}. First tries to use the
 * {@link ISecurityCheck} from the component if that is not available it tries the
 * {@link ISecureModel} if neither is present the user is authenticated if
 * {@link WaspAuthorizationStrategy#isUserAuthenticated()} returns true.
 * /*from   w ww .j a  v  a2 s.c  o m*/
 * @param component
 *            the component to check
 * 
 * @return true, if the user is authenticated, false otherwise.
 * @see ISecureComponent#isAuthenticated()
 * @see ISecurityCheck
 * @see ISecureModel
 */
public static boolean isAuthenticated(Component component) {
    ISecurityCheck check = saveGetSecurityCheck(component);
    if (check != null)
        return check.isAuthenticated();
    if (hasSecureModel(component))
        return ((ISecureModel<?>) component.getDefaultModel()).isAuthenticated(component);
    return getStrategy().isUserAuthenticated();
}

From source file:org.wicketstuff.security.strategies.WaspAuthorizationStrategy.java

License:Apache License

/**
 * /*w  w w .  j  a  va  2  s  .c o  m*/
 * @see org.apache.wicket.authorization.IAuthorizationStrategy#isActionAuthorized(org.apache.wicket.Component,
 *      org.apache.wicket.authorization.Action)
 */
public boolean isActionAuthorized(Component component, Action action) {
    if (component != null) {
        ISecurityCheck check = getSecurityCheck(component);
        if (check != null) {
            if (check.isActionAuthorized(getActionFactory().getAction(action)))
                return true;
            IAuthorizationMessageSource message = getMessageSource();
            if (message != null) {
                message.setComponent(component);
                message.addVariable("wicket.action", action);
                message.addVariable("wasp.action", getActionFactory().getAction(action));
                logMessage(message);
            }
            return false;

        }
        IModel<?> model = component.getDefaultModel();
        if (model instanceof ISecureModel<?>) {
            if (((ISecureModel<?>) model).isAuthorized(component, getActionFactory().getAction(action)))
                return true;
            IAuthorizationMessageSource message = getMessageSource();
            if (message != null) {
                message.setComponent(component);
                message.addVariable("wicket.action", action);
                message.addVariable("wasp.action", getActionFactory().getAction(action));
                logMessage(message);
            }
            return false;
        }
    }
    return true;
}

From source file:wicket.contrib.tinymce.InPlaceSaveBehavior.java

License:Open Source License

@Override
protected final void respond(AjaxRequestTarget target) {
    Request request = RequestCycle.get().getRequest();
    String newContent = request.getRequestParameters().getParameterValue(PARAM_HTMLCONT).toString();
    newContent = onSave(target, newContent);
    Component component = getComponent();
    IModel defaultModel = component.getDefaultModel();
    defaultModel.setObject(newContent);/*from   ww w  .  j av a 2 s  . c o m*/
    target.add(component);
}