/*************************************************************************
* Copyright 2009-2015 Eucalyptus Systems, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
* Please contact Eucalyptus Systems, Inc., 6755 Hollister Ave., Goleta
* CA 93117, USA or visit http://www.eucalyptus.com/licenses/ if you need
* additional information or have any questions.
************************************************************************/
package com.eucalyptus.objectstorage.policy;
import java.util.Set;
import javax.annotation.Nullable;
import com.eucalyptus.auth.PolicyResourceContext;
import com.eucalyptus.auth.type.RestrictedType;
import com.eucalyptus.objectstorage.entities.S3AccessControlledEntity;
import com.eucalyptus.objectstorage.policy.ObjectStoragePolicyContext.ObjectStoragePolicyContextResource;
import com.eucalyptus.records.Logs;
import com.eucalyptus.util.TypeMappers;
import com.google.common.collect.Sets;
/**
*
*/
public class ObjectStoragePolicyResourceInterceptor implements PolicyResourceContext.PolicyResourceInterceptor {
private static final Set<Class<? extends RestrictedType>> accepted = Sets.newCopyOnWriteArraySet( );
private static final Set<Class<? extends RestrictedType>> rejected = Sets.newCopyOnWriteArraySet( );
@SuppressWarnings( "unchecked" )
@Override
public void onResource( @Nullable final PolicyResourceContext.PolicyResourceInfo resource,
@Nullable final String action ) {
ObjectStoragePolicyContext.clearContext( );
if ( resource != null &&
resource.getResourceObject() != null &&
S3AccessControlledEntity.class.isAssignableFrom( resource.getResourceClass( ) ) ) {
if ( accepted.contains( resource.getResourceClass( ) ) ||
(!rejected.contains( resource.getResourceClass( ) ) &&
S3AccessControlledEntity.class.isAssignableFrom( resource.getResourceClass( ) ) ) ) try {
ObjectStoragePolicyContext.setObjectStoragePolicyContextResource(
TypeMappers.transform( resource.getResourceObject( ), ObjectStoragePolicyContextResource.class ) );
accepted.add( (Class<? extends RestrictedType>) resource.getResourceClass( ) );
} catch ( IllegalArgumentException e ) {
rejected.add( (Class<? extends RestrictedType>) resource.getResourceClass( ) );
Logs.exhaust( ).info(
"Policy context not set for resource type: " + resource.getResourceClass().getSimpleName( ) );
}
}
}
}