/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.wicket.security.hive.authentication;
import org.apache.wicket.Component;
import org.apache.wicket.model.IModel;
import org.apache.wicket.security.hive.authorization.SimplePrincipal;
import org.apache.wicket.security.pages.HighSecurityPage;
/**
* A context for multi login, this context is used to grant the least amount of
* permissions.
*
* @author marrink
*/
public final class PrimaryLoginContext extends LoginContext
{
/**
* Custom Subject. Note try not to serialize the logincontext with the subject.
*
* @author marrink
*/
private static final class MySubject extends DefaultSubject
{
private static final long serialVersionUID = 1L;
/**
*
* @see org.apache.wicket.security.hive.authentication.DefaultSubject#isClassAuthenticated(java.lang.Class)
*/
@Override
public boolean isClassAuthenticated(Class< ? > class1)
{
// for this test class authentication is enough
if (class1 == null)
return false;
return !HighSecurityPage.class.isAssignableFrom(class1);
}
/**
*
* @see org.apache.wicket.security.hive.authentication.DefaultSubject#isComponentAuthenticated(org.apache.wicket.Component)
*/
@Override
public boolean isComponentAuthenticated(Component component)
{
return true;
}
/**
*
* @see org.apache.wicket.security.hive.authentication.DefaultSubject#isModelAuthenticated(org.apache.wicket.model.IModel,
* org.apache.wicket.Component)
*/
@Override
public boolean isModelAuthenticated(IModel< ? > model, Component component)
{
return true;
}
}
/**
*
* Construct.
*/
public PrimaryLoginContext()
{
super(0);
}
/**
*
* @see org.apache.wicket.security.hive.authentication.LoginContext#login()
*/
@Override
public Subject login()
{
DefaultSubject defaultSubject = new MySubject();
defaultSubject.addPrincipal(new SimplePrincipal("basic"));
return defaultSubject;
}
/**
* @see org.apache.wicket.security.hive.authentication.LoginContext#preventsAdditionalLogins()
*/
@Override
public boolean preventsAdditionalLogins()
{
return false;
}
}