de.inren.frontend.auth.B4AuthorizationStrategy.java Source code

Java tutorial

Introduction

Here is the source code for de.inren.frontend.auth.B4AuthorizationStrategy.java

Source

/**
 * Copyright 2014 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package de.inren.frontend.auth;

import org.apache.wicket.Component;
import org.apache.wicket.RestartResponseAtInterceptPageException;
import org.apache.wicket.Session;
import org.apache.wicket.authorization.Action;
import org.apache.wicket.authorization.IAuthorizationStrategy;
import org.apache.wicket.request.component.IRequestableComponent;

import de.inren.frontend.common.templates.ISecured;
import de.inren.security.BasicAuthenticationSession;

/**
 * @author Ingo Renner
 *
 */
public class B4AuthorizationStrategy implements IAuthorizationStrategy {

    @Override
    public <T extends IRequestableComponent> boolean isInstantiationAuthorized(Class<T> componentClass) {

        // Allow all non secured components
        if (!ISecured.class.isAssignableFrom(componentClass)) {
            return true;
        }

        // Deny all others
        if (!((BasicAuthenticationSession) Session.get()).isSignedIn()) {
            throw new RestartResponseAtInterceptPageException(LoginPage.class);
        }

        return true;
    }

    @Override
    public boolean isActionAuthorized(Component component, Action action) {
        return true;
    }

}