Search in sources :

Example 6 with AuditLogRequest

use of com.emc.storageos.security.audit.AuditLogRequest in project coprhd-controller by CoprHD.

the class AuditService method getAuditLogs.

/**
 * Retrieves the bulk auditlogs and alerts based on passed request paramters
 * or hour).
 *
 * @param timeBucket Time bucket for retrieval of auditlogs. Acceptable
 *            formats are: yyyy-MM-dd'T'HH for hour bucket,
 *            yyyy-MM-dd'T'HH:mm for minute bucket
 * @param startTimeStr Overrided if timeBucket specified .start time for retieval of auditlogs.
 *                     formats are: yyyy-MM-dd'T'HH
 * @param endTimeStr  Override if timeBucket specified .end time for retieval of auditlogs.
 *                   formats are: yyyy-MM-dd'T'HH
 * @param svcType service type for retrieval of auditlogs
 * @param user the user of auditlogs to retrieve
 * @param result the result of auditlogs to retrieve
 * @param keyword the containing keyword of auditlog to retrive
 * @param language Lanuage for the auditlog description. "en_US" by default
 * @brief Show audit logs for time period with specified paramters
 * @return Output stream of auditlogs or an error status.
 */
@GET
@Path("/logs")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN })
@CheckPermission(roles = { Role.SYSTEM_AUDITOR })
public Response getAuditLogs(@QueryParam("time_bucket") final String timeBucket, @QueryParam("start") final String startTimeStr, @QueryParam("end") final String endTimeStr, @QueryParam("service_type") final String svcType, @QueryParam("user") final String user, @QueryParam("result") final String result, @QueryParam("keyword") final String keyword, @QueryParam("language") @DefaultValue("en_US") final String language, @Context HttpHeaders header) {
    MediaType mType = MediaType.APPLICATION_XML_TYPE;
    List<MediaType> mTypes = header.getAcceptableMediaTypes();
    if (mTypes != null) {
        for (MediaType media : mTypes) {
            if (media.equals(MediaType.APPLICATION_JSON_TYPE) || media.equals(MediaType.TEXT_PLAIN_TYPE)) {
                mType = media;
                break;
            }
        }
    }
    _logger.info("mtype is :{}", mType);
    DateTime startTime, endTime;
    if (timeBucket != null && !timeBucket.isEmpty()) {
        startTime = getDataTime(timeBucket, HOUR_BUCKET_TIME_FORMAT);
        if (startTime != null) {
            endTime = startTime.plusMinutes(59);
        } else {
            startTime = getDataTime(timeBucket, MINUTE_BUCKET_TIME_FORMAT);
            if (startTime != null) {
                endTime = startTime.plusSeconds(59);
            } else {
                throw APIException.badRequests.invalidTimeBucket(timeBucket);
            }
        }
    } else {
        startTime = getDataTime(startTimeStr, HOUR_BUCKET_TIME_FORMAT);
        if (startTime == null) {
            throw APIException.badRequests.invalidDate(startTimeStr, HOUR_BUCKET_TIME_FORMAT);
        }
        endTime = getDataTime(endTimeStr, HOUR_BUCKET_TIME_FORMAT);
        if (endTime == null) {
            throw APIException.badRequests.invalidDate(endTimeStr, HOUR_BUCKET_TIME_FORMAT);
        }
        validateDataTimePair(startTime, endTime);
    }
    validateResultValue(result);
    String auditResult = null;
    if (result != null) {
        auditResult = (result.equalsIgnoreCase("S") ? AuditLogManager.AUDITLOG_SUCCESS : AuditLogManager.AUDITLOG_FAILURE);
    }
    AuditLogRequest auditLogRequest = new AuditLogRequest.Builder().serviceType(svcType).user(user).result(auditResult).keyword(keyword).lang(language).timeBucket(timeBucket).start(startTime).end(endTime).build();
    return Response.ok(getStreamOutput(auditLogRequest, mType), mType).build();
}
Also used : DateTime(org.joda.time.DateTime) AuditLogRequest(com.emc.storageos.security.audit.AuditLogRequest) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

AuditLogRequest (com.emc.storageos.security.audit.AuditLogRequest)6 DbAuditLogRetriever (com.emc.storageos.api.service.impl.resource.utils.DbAuditLogRetriever)4 MarshallingExcetion (com.emc.storageos.api.service.impl.resource.utils.MarshallingExcetion)4 DummyDBClient (com.emc.storageos.api.service.utils.DummyDBClient)4 MediaType (javax.ws.rs.core.MediaType)4 Test (org.junit.Test)4 DateTime (org.joda.time.DateTime)3 AuditLogs (com.emc.storageos.api.service.utils.AuditLogs)2 RetryableDatabaseException (com.emc.storageos.db.exceptions.RetryableDatabaseException)1 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)1 JAXBContext (javax.xml.bind.JAXBContext)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 AnnotationIntrospector (org.codehaus.jackson.map.AnnotationIntrospector)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 JaxbAnnotationIntrospector (org.codehaus.jackson.xc.JaxbAnnotationIntrospector)1