Permalink
Browse files

Merge pull request #861 from sonatype/nexus-5714-status-resource

[2.6] NEXUS-5714: Status resource without perms
  • Loading branch information...
2 parents 8457c9c + ced0252 commit 7b5b8ea17efd140ed5498b08bb8ec5bbc3781151 @jdillon jdillon committed May 18, 2013
@@ -35,7 +35,7 @@ public void testSecurityDisabledStatus()
{
NexusStatusUtil statusUtil = getNexusStatusUtil();
- StatusResource statusResource = statusUtil.getNexusStatus().getData();
+ StatusResource statusResource = statusUtil.getNexusStatus( true ).getData();
List<ClientPermission> permisisons = statusResource.getClientPermissions().getPermissions();
@@ -108,17 +108,40 @@ else if ( statusCode != 200 )
}
/**
- * Get Nexus Status, failing if the request response is not successfully returned.
- *
+ * Get Nexus Status, failing if the request response is not successfully returned. Delegates call to
+ * {@link #getNexusStatus(boolean)} with {@code false} parameter.
+ *
* @return the status resource
* @throws NexusIllegalStateException
*/
public StatusResourceResponse getNexusStatus()
throws NexusIllegalStateException
{
+ return getNexusStatus( false );
+ }
+
+ /**
+ * Get Nexus Status, failing if the request response is not successfully returned.
+ *
+ * @param withPermissions if {@code true}, it will ask for permissions too, as returned before Nexus 2.6
+ * @return the status resource
+ * @throws NexusIllegalStateException
+ * @since 2.6
+ */
+ public StatusResourceResponse getNexusStatus( final boolean withPermissions )
+ throws NexusIllegalStateException
+ {
try
{
- String entityText = RequestFacade.doGetForText( "service/local/status" );
+ final String entityText;
+ if ( withPermissions )
+ {
+ entityText = RequestFacade.doGetForText( "service/local/status?perms=1" );
+ }
+ else
+ {
+ entityText = RequestFacade.doGetForText( "service/local/status" );
+ }
StatusResourceResponse status =
(StatusResourceResponse) XStreamFactory.getXmlXStream().fromXML( entityText );
return status;
@@ -90,7 +90,7 @@ define('Nexus/config',['extjs', 'Nexus/messagebox', 'Sonatype/init', 'Nexus/conf
configCurrent : servicePath + '/configs/current',
logs : servicePath + '/logs',
logConfig : servicePath + '/log/config',
- status : servicePath + '/status',
+ status : servicePath + '/status?perms=1',
schedules : servicePath + '/schedules',
scheduleRun : servicePath + '/schedule_run',
scheduleTypes : servicePath + '/schedule_types',
@@ -18,17 +18,18 @@
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
-import com.yammer.metrics.annotation.Timed;
import org.codehaus.enunciate.contract.jaxrs.ResourceMethodSignature;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.restlet.Context;
+import org.restlet.data.Form;
import org.restlet.data.Request;
import org.restlet.data.Response;
import org.restlet.resource.ResourceException;
import org.restlet.resource.Variant;
-import org.sonatype.nexus.Nexus;
+import org.sonatype.nexus.ApplicationStatusSource;
import org.sonatype.nexus.SystemStatus;
import org.sonatype.nexus.rest.model.NexusAuthenticationClientPermissions;
import org.sonatype.nexus.rest.model.StatusResource;
@@ -38,6 +39,8 @@
import org.sonatype.security.rest.authentication.AbstractUIPermissionCalculatingPlexusResource;
import org.sonatype.security.rest.model.AuthenticationClientPermissions;
+import com.yammer.metrics.annotation.Timed;
+
@Component( role = ManagedPlexusResource.class, hint = "StatusPlexusResource" )
@Path( StatusPlexusResource.RESOURCE_URI )
@Produces( { "application/xml", "application/json" } )
@@ -48,7 +51,7 @@
public static final String RESOURCE_URI = "/status";
@Requirement
- private Nexus nexus;
+ private ApplicationStatusSource applicationStatusSource;
@Override
public Object getPayloadInstance()
@@ -69,18 +72,21 @@ public PathProtectionDescriptor getResourceProtection()
}
/**
- * Get the status of the nexus server.
+ * Returns the status of the Nexus server.
+ *
+ * @param perms If query parameter with this name present (without or with any value, does not matter, it is only
+ * checked for presence), this resource will emit the user permissions too.
*/
@Timed
@Override
@GET
- @ResourceMethodSignature( output = StatusResourceResponse.class )
+ @ResourceMethodSignature( queryParams = { @QueryParam( "perms" ) }, output = StatusResourceResponse.class )
public Object get( Context context, Request request, Response response, Variant variant )
throws ResourceException
{
- SystemStatus status = this.nexus.getSystemStatus();
+ final SystemStatus status = applicationStatusSource.getSystemStatus();
- StatusResource resource = new StatusResource();
+ final StatusResource resource = new StatusResource();
resource.setAppName( status.getAppName() );
@@ -138,7 +144,11 @@ public Object get( Context context, Request request, Response response, Variant
// }
// }
- resource.setClientPermissions( this.getClientPermissions( request ) );
+ final Form form = request.getResourceRef().getQueryAsForm();
+ if ( form.getFirst( "perms" ) != null )
+ {
+ resource.setClientPermissions( getClientPermissions( request ) );
+ }
resource.setBaseUrl( getContextRoot( request ).toString() );

0 comments on commit 7b5b8ea

Please sign in to comment.