Browse Source

[MRM-1296] Audit Log Report

o added selenium test for viewing audit log reports
o fixed bu when querying log using artifactId


git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1296@890811 13f79535-47bb-0310-9956-ffa450edef68
MRM-1296
Maria Odea B. Ching 14 years ago
parent
commit
3078e1af86

+ 1
- 1
archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArchivaAuditLogsConstraint.java View File

@@ -49,7 +49,7 @@ public class ArchivaAuditLogsConstraint
{
whereClause = whereClause + " && artifact.like(desiredArtifact)";
declParamsList.add( "String desiredArtifact" );
paramsList.add( desiredArtifact + "%" );
paramsList.add( desiredArtifact );
}

if ( desiredRepositoryId != null && !"".equals( desiredRepositoryId ) )

+ 1
- 0
archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/config/testng.xml View File

@@ -33,6 +33,7 @@ under the License.
<include name= "reposcan" />
<include name= "artifactmanagement" />
<include name= "search" />
<include name= "auditlogsreport" />
<include name= "browse" />
<include name= "reports" />
<include name= "virtualrepository" />

+ 120
- 0
archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/AuditLogsReportTest.java View File

@@ -0,0 +1,120 @@
package org.apache.archiva.web.test;

/*
* 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.
*/

import org.apache.archiva.web.test.parent.AbstractArchivaTest;
import org.testng.annotations.Test;

@Test( groups = { "auditlogsreport" }, dependsOnMethods = { "testWithCorrectUsernamePassword" } )
public class AuditLogsReportTest
extends AbstractArchivaTest
{
private void goToAuditLogReports()
{
clickLinkWithText( "Audit Log Report" );
}
private void assertAuditLogsReportPage()
{
assertPage( "Apache Archiva \\ Audit Log Report" );
assertTextPresent( "Audit Log Report" );
assertElementPresent( "repository" );
assertElementPresent( "groupId" );
assertElementPresent( "artifactId" );
assertElementPresent( "startDate" );
assertElementPresent( "endDate" );
assertElementPresent( "rowCount" );
assertButtonWithValuePresent( "View Audit Log" );
}
@Test(dependsOnMethods = { "testWithCorrectUsernamePassword" } )
public void testAuditLogsReport()
{
goToAuditLogReports();
assertAuditLogsReportPage();
}
@Test(dependsOnMethods = { "testWithCorrectUsernamePassword" } )
public void testViewAuditLogsNoDataFound()
{
goToAuditLogReports();
assertAuditLogsReportPage();
setFieldValue( "groupId", "non.existing" );
submit();
assertPage( "Apache Archiva \\ Audit Log Report" );
assertTextPresent( "No audit logs found." );
}
@Test (dependsOnMethods = { "testAddArtifactValidValues" } )
public void testViewAuditLogsDataFound()
{
goToAuditLogReports();
assertAuditLogsReportPage();
selectValue( "repository", "internal" );
setFieldValue( "groupId", "test" );
submit();
assertAuditLogsReportPage();
assertTextNotPresent( "No audit logs found." );
assertTextPresent( "test:test:1.0" );
assertTextPresent( "Uploaded File" );
assertTextPresent( "internal" );
assertTextPresent( "admin" );
}
@Test (dependsOnMethods = { "testViewAuditLogsDataFound" } )
public void testViewAuditLogsOnlyArtifactIdIsSpecified()
{
goToAuditLogReports();
assertAuditLogsReportPage();
selectValue( "repository", "internal" );
setFieldValue( "artifactId", "test" );
submit();
assertAuditLogsReportPage();
assertTextNotPresent( "No audit logs found." );
assertTextPresent( "test:test:1.0" );
assertTextPresent( "Uploaded File" );
assertTextPresent( "internal" );
assertTextPresent( "admin" );
}
@Test (dependsOnMethods = { "testViewAuditLogsOnlyArtifactIdIsSpecified" } )
public void testViewAuditLogsForAllRepositories()
{
goToAuditLogReports();
assertAuditLogsReportPage();
selectValue( "repository", "all" );
submit();
assertAuditLogsReportPage();
assertTextNotPresent( "No audit logs found." );
assertTextPresent( "test:test:1.0" );
assertTextPresent( "Uploaded File" );
assertTextPresent( "internal" );
assertTextPresent( "admin" );
}
}

+ 1
- 2
archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/RepositoryTest.java View File

@@ -39,8 +39,7 @@ public class RepositoryTest
@Test(dependsOnMethods = { "testAddManagedRepoValidValues" } )
public void testAddManagedRepoInvalidValues()
{
goToRepositoriesPage();
{
assertRepositoriesPage();
clickLinkWithLocator( "//div[@id='contentArea']/div/div/a[@href='/archiva/admin/addRepository.action']" );
addManagedRepository( "", "" , "" , "", "Maven 2.x Repository", "", "", "" );

+ 2
- 3
archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/VirtualRepositoryTest.java View File

@@ -51,9 +51,8 @@ public class VirtualRepositoryTest
@Test(dependsOnMethods = { "testAddRepositoryToRepositoryGroup" } )
public void testDeleteRepositoryOfRepositoryGroup()
{
goToRepositoryGroupsPage();
deleteRepositoryInRepositoryGroups();
{
deleteRepositoryInRepositoryGroups();
assertTextPresent( "Repository Groups" );
assertTextNotPresent( "No Repository Groups Defined." );
waitPage();

+ 2
- 1
archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractArchivaTest.java View File

@@ -394,12 +394,13 @@ public abstract class AbstractArchivaTest
assertLinkPresent( "Browse" );
assertLinkPresent( "Upload Artifact" );
assertLinkPresent( "Delete Artifact" );
assertLinkPresent( "Audit Log Report" );
assertLinkNotPresent( "Repositories" );
}
else
{
assertTextPresent( "Search" );
String navMenu = "Find Artifact,Browse,Reports,User Management,User Roles,Appearance,Upload Artifact,Delete Artifact,Repository Groups,Repositories,Proxy Connectors,Legacy Support,Network Proxies,Repository Scanning,Database";
String navMenu = "Find Artifact,Browse,Reports,Audit Log Report,User Management,User Roles,Appearance,Upload Artifact,Delete Artifact,Repository Groups,Repositories,Proxy Connectors,Legacy Support,Network Proxies,Repository Scanning,Database";
String[] arrayMenu = navMenu.split( "," );
for (String navmenu : arrayMenu )
assertLinkPresent( navmenu );

+ 117
- 50
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/ViewAuditLogReportAction.java View File

@@ -24,6 +24,7 @@ import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;

@@ -49,140 +50,176 @@ import org.codehaus.redback.integration.interceptor.SecureActionException;
import com.opensymphony.xwork2.Preparable;

/**
* @plexus.component role="com.opensymphony.xwork2.Action" role-hint="viewAuditLogReport" instantiation-strategy="per-lookup"
* @plexus.component role="com.opensymphony.xwork2.Action" role-hint="viewAuditLogReport"
* instantiation-strategy="per-lookup"
*/
public class ViewAuditLogReportAction
extends PlexusActionSupport
implements SecureAction, ServletRequestAware, Preparable
{
{
protected HttpServletRequest request;
/**
* @plexus.requirement
*/
private UserRepositories userRepositories;
/**
* @plexus.requirement role-hint="jdo"
*/
private ArchivaAuditLogsDao auditLogsDao;
/**
* @plexus.requirement role-hint="jdo"
*/
private ArchivaDAO dao;
private String repository;

private List<String> repositories;
private String groupId;
private String artifactId;
private Date startDate;

private Date endDate;
private int rowCount = 30;
private int page = 1;

private List<ArchivaAuditLogs> auditLogs;
private String prev;

private String next;

protected boolean isLastPage = true;

private List<ArchivaAuditLogs> auditLogs;

private static final String ALL_REPOSITORIES = "all";
protected int[] range = new int[2];
public SecureActionBundle getSecureActionBundle()
throws SecureActionException
{
{
return null;
}

public void setServletRequest( HttpServletRequest request )
{
{
this.request = request;
}

@SuppressWarnings( "unchecked" )
public void prepare()
throws Exception
{
{
repositories = new ArrayList<String>();
repositories.add( ALL_REPOSITORIES );
repositories.addAll( getObservableRepositories() );
auditLogs = null;
SimpleConstraint constraint = new MostRecentArchivaAuditLogsConstraint();
groupId = "";
artifactId = "";
repository = "";

SimpleConstraint constraint = new MostRecentArchivaAuditLogsConstraint();
auditLogs = (List<ArchivaAuditLogs>) dao.query( constraint );
}
public String execute()
throws Exception
{
{
auditLogs = null;
String artifact = "";
if( groupId != null || !"".equals( groupId.trim() ) )
if ( groupId != null && !"".equals( groupId.trim() ) )
{
artifact = groupId;
}
if( artifactId != null || !"".equals( artifactId.trim() ) )
{
artifact = artifact + ":" + artifactId;
artifact = groupId + ( ( artifactId != null && !"".equals( artifactId.trim() ) ) ? ( ":" + artifactId + ":%" ) : ":%" );
}
else
{
artifact = ( artifactId != null && !"".equals( artifactId.trim() ) ) ? ( "%:" + artifactId + ":%" ) : "";
}
if( startDate == null )
if ( startDate == null )
{
Calendar cal = Calendar.getInstance();
cal.set( Calendar.HOUR, 0 );
cal.set( Calendar.MINUTE, 0 );
cal.set( Calendar.SECOND, 0 );
startDate = cal.getTime();
cal.set( Calendar.SECOND, 0 );
startDate = cal.getTime();
}
if( startDate.equals( endDate ) || endDate == null )
if ( startDate.equals( endDate ) || endDate == null )
{
endDate = Calendar.getInstance().getTime();
}
range[0] = ( page - 1 ) * rowCount;
range[1] = ( page * rowCount ) + 1;
range[1] = ( page * rowCount ) + 1;

ArchivaAuditLogsConstraint constraint = null;
if( !repository.equals( ALL_REPOSITORIES ) )
if ( !repository.equals( ALL_REPOSITORIES ) )
{
constraint = new ArchivaAuditLogsConstraint( range, artifact, repository, AuditEvent.UPLOAD_FILE, startDate, endDate );
constraint =
new ArchivaAuditLogsConstraint( range, artifact, repository, AuditEvent.UPLOAD_FILE, startDate, endDate );
}
else
{
constraint = new ArchivaAuditLogsConstraint( range, artifact, null, AuditEvent.UPLOAD_FILE, startDate, endDate );
constraint =
new ArchivaAuditLogsConstraint( range, artifact, null, AuditEvent.UPLOAD_FILE, startDate, endDate );
}
try
{
auditLogs = auditLogsDao.queryAuditLogs( constraint );
startDate = null;
endDate = null;
if( auditLogs.isEmpty() )
{
addActionError( "No audit logs found." );
}
}
catch ( ObjectNotFoundException e )
{
addActionError( "No audit logs found." );
return ERROR;
}
catch( ArchivaDatabaseException e )
catch ( ArchivaDatabaseException e )
{
addActionError( "Error occurred while querying audit logs." );
return ERROR;
}
// pagination
paginate();

startDate = null;
endDate = null;

return SUCCESS;
}

private void paginate()
{
if ( auditLogs.size() <= rowCount )
{
isLastPage = true;
}

prev =
request.getRequestURL() + "?page=" + ( page - 1 ) + "&rowCount=" + rowCount + "&groupId=" + groupId +
"&artifactId=" + artifactId + "&repositoryId=" + repository + "&startDate=" + startDate + "&endDate=" +
endDate;
next =
request.getRequestURL() + "?page=" + ( page + 1 ) + "&rowCount=" + rowCount + "&groupId=" + groupId +
"&artifactId=" + artifactId + "&repositoryId=" + repository + "&startDate=" + startDate + "&endDate=" +
endDate;
}

private List<String> getObservableRepositories()
{
try
@@ -203,7 +240,7 @@ public class ViewAuditLogReportAction
}
return Collections.emptyList();
}
public String getRepository()
{
return repository;
@@ -243,7 +280,7 @@ public class ViewAuditLogReportAction
{
this.artifactId = artifactId;
}
public List<ArchivaAuditLogs> getAuditLogs()
{
return auditLogs;
@@ -263,7 +300,7 @@ public class ViewAuditLogReportAction
{
this.rowCount = rowCount;
}
public Date getStartDate()
{
return startDate;
@@ -283,7 +320,7 @@ public class ViewAuditLogReportAction
{
this.endDate = endDate;
}
public int getPage()
{
return page;
@@ -293,4 +330,34 @@ public class ViewAuditLogReportAction
{
this.page = page;
}

public boolean isLastPage()
{
return isLastPage;
}

public void setLastPage( boolean isLastPage )
{
this.isLastPage = isLastPage;
}
public String getPrev()
{
return prev;
}

public void setPrev( String prev )
{
this.prev = prev;
}

public String getNext()
{
return next;
}

public void setNext( String next )
{
this.next = next;
}
}

+ 1
- 1
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/decorators/default.jsp View File

@@ -90,7 +90,7 @@
</redback:ifAuthorized>
<redback:ifAuthorized permission="archiva-view-audit-logs">
<li class="none">
<my:currentWWUrl action="queryAuditLogReport" namespace="/report">Audit Log Reports</my:currentWWUrl>
<my:currentWWUrl action="queryAuditLogReport" namespace="/report">Audit Log Report</my:currentWWUrl>
</li>
</redback:ifAuthorized>
<redback:ifAuthorized permission="archiva-manage-users">

+ 21
- 10
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/auditLogReport.jsp View File

@@ -46,6 +46,10 @@
<s:form action="viewAuditLogReport" namespace="/report" validate="false">
<p>
<s:actionerror/>
</p>
<div id="auditLogReport">
<s:select label="Repository" name="repository" list="repositories"/>
@@ -80,19 +84,26 @@
<s:textfield label="Row Count" name="rowCount" />
<s:submit value="View Audit Log"/>
<s:set name="page" value="page"/>
<c:if test="${page > 1}"><a href="<s:property value='prev' />">&lt;&lt;</a></c:if>
Page: ${page}
<s:set name="isLastPage" value="isLastPage"/>
<c:if test="${!isLastPage}"><a href="<s:property value='next' />">&gt;&gt;</a></c:if>
</div>
</s:form>
<c:if test="${not empty (auditLogs)}">
<table border="1">
<c:if test="${not empty (auditLogs)}">
<table border="1" cellpadding="5" cellspacing="5" width="100%">
<thead>
<tr>
<th align="center">Event</th>
<th align="center">Repository</th>
<th align="center">Artifact</th>
<th align="center">Event Date</th>
<th align="center">Username</th>
<th style="text-align:center">Event</th>
<th style="text-align:center">Repository</th>
<th style="text-align:center">Artifact</th>
<th style="text-align:center">Event Date</th>
<th style="text-align:center">Username</th>
</tr>
</thead>
<c:forEach items="${auditLogs}" var="auditLog" varStatus="i">
@@ -106,8 +117,8 @@
</tr>
</tbody>
</c:forEach>
</table>
</c:if>
</table>
</c:if>
</div>

</body>

Loading…
Cancel
Save