All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.daedafusion.security.admin.impl.AuditAdminImpl Maven / Gradle / Ivy

There is a newer version: 1.1
Show newest version
package com.daedafusion.security.admin.impl;

import com.daedafusion.sf.AbstractService;
import com.daedafusion.security.admin.AuditAdmin;
import com.daedafusion.security.admin.providers.AuditAdminProvider;
import com.daedafusion.security.audit.AuditEvent;
import com.daedafusion.security.authentication.Subject;
import com.daedafusion.security.authorization.Authorization;
import com.daedafusion.security.common.Context;
import com.daedafusion.security.common.impl.DefaultContext;
import com.daedafusion.security.exceptions.UnauthorizedException;
import org.apache.log4j.Logger;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by mphilpot on 7/21/14.
 */
public class AuditAdminImpl extends AbstractService implements AuditAdmin
{
    private static final Logger log = Logger.getLogger(AuditAdminImpl.class);

    @Override
    public List getEvents(Subject subject, long after, long before, int limit) throws UnauthorizedException
    {
        Authorization auth = getServiceRegistry().getService(Authorization.class);

        Context context = new DefaultContext();

        if(auth.isAuthorized(subject, java.net.URI.create("audit"), "GET", context))
        {
            List result = new ArrayList<>();

            for(AuditAdminProvider aap: getProviders())
            {
                result.addAll(aap.getEvents(after, before, limit));
            }

            return result;
        }
        else
        {
            throw new UnauthorizedException();
        }
    }

    @Override
    public List getEventsByUsername(Subject subject, long after, long before, String username, int limit) throws UnauthorizedException
    {
        Authorization auth = getServiceRegistry().getService(Authorization.class);

        Context context = new DefaultContext();
        context.addContext("username", username);

        if(auth.isAuthorized(subject, java.net.URI.create("audit"), "GET", context))
        {
            List result = new ArrayList<>();

            for(AuditAdminProvider aap: getProviders())
            {
                result.addAll(aap.getEventsByUsername(after, before, username, limit));
            }

            return result;
        }
        else
        {
            throw new UnauthorizedException();
        }
    }

    @Override
    public List getEventsBySource(Subject subject, long after, long before, String source, int limit) throws UnauthorizedException
    {
        Authorization auth = getServiceRegistry().getService(Authorization.class);

        Context context = new DefaultContext();
        context.addContext("source", source);

        if(auth.isAuthorized(subject, java.net.URI.create("audit"), "GET", context))
        {
            List result = new ArrayList<>();

            for(AuditAdminProvider aap: getProviders())
            {
                result.addAll(aap.getEventsBySource(after, before, source, limit));
            }

            return result;
        }
        else
        {
            throw new UnauthorizedException();
        }
    }

    @Override
    public Class getProviderInterface()
    {
        return AuditAdminProvider.class;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy