forked from federecio/dropwizard-swagger
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace FireFox with Chrome (federecio#51)
* [maven-release-plugin] rollback the release of v1.0.0-2 * Added a sample application to view the documentation from within this repo * Try replacing FireFox with Chrome. The tests are more reliable, but now we're getting ElementNotVisibleExceptions :( * Upgrade to swagger-ui 2.2.5 and remove custom auth UI code in favor of SecurityDefinition annotations * Tests with Chrome are now passing. This requires the next SNAPSHOT release of swagger-core to fix an issue with the ApiKeys
- Loading branch information
Showing
16 changed files
with
877 additions
and
541 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Swagger-specific options. | ||
swagger: | ||
|
||
resourcePackage: io.federecio.dropwizard.sample | ||
title: Sample API | ||
version: v1 | ||
description: Sample service API | ||
contact: [email protected] | ||
license: Apache 2.0 | ||
licenseUrl: https://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
# HTTP-specific options. | ||
server: | ||
|
||
type: simple | ||
applicationContextPath: / | ||
adminContextPath: /admin | ||
connector: | ||
type: http | ||
port: 8080 |
51 changes: 51 additions & 0 deletions
51
src/main/java/io/federecio/dropwizard/sample/SampleApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.federecio.dropwizard.sample; | ||
|
||
import org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature; | ||
import io.dropwizard.Application; | ||
import io.dropwizard.auth.AuthDynamicFeature; | ||
import io.dropwizard.auth.AuthValueFactoryProvider; | ||
import io.dropwizard.auth.PrincipalImpl; | ||
import io.dropwizard.auth.basic.BasicCredentialAuthFilter; | ||
import io.dropwizard.setup.Bootstrap; | ||
import io.dropwizard.setup.Environment; | ||
import io.federecio.dropwizard.swagger.SwaggerBundle; | ||
import io.federecio.dropwizard.swagger.SwaggerBundleConfiguration; | ||
|
||
public class SampleApplication extends Application<SampleConfiguration> { | ||
|
||
public static void main(final String[] args) throws Exception { | ||
new SampleApplication().run(args); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "sample"; | ||
} | ||
|
||
@Override | ||
public void initialize(Bootstrap<SampleConfiguration> bootstrap) { | ||
bootstrap.addBundle(new SwaggerBundle<SampleConfiguration>() { | ||
@Override | ||
protected SwaggerBundleConfiguration getSwaggerBundleConfiguration( | ||
SampleConfiguration configuration) { | ||
return configuration.getSwagger(); | ||
} | ||
}); | ||
}; | ||
|
||
@Override | ||
public void run(SampleConfiguration configuration, Environment environment) | ||
throws Exception { | ||
|
||
environment.jersey().register(new AuthDynamicFeature( | ||
new BasicCredentialAuthFilter.Builder<PrincipalImpl>() | ||
.setAuthenticator(new SampleAuthenticator()) | ||
.setRealm("SUPER SECRET STUFF").buildAuthFilter())); | ||
environment.jersey().register(RolesAllowedDynamicFeature.class); | ||
environment.jersey().register( | ||
new AuthValueFactoryProvider.Binder<>(PrincipalImpl.class)); | ||
|
||
// resources | ||
environment.jersey().register(new SampleResource()); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/io/federecio/dropwizard/sample/SampleAuthenticator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.federecio.dropwizard.sample; | ||
|
||
import java.util.Optional; | ||
import io.dropwizard.auth.AuthenticationException; | ||
import io.dropwizard.auth.Authenticator; | ||
import io.dropwizard.auth.PrincipalImpl; | ||
import io.dropwizard.auth.basic.BasicCredentials; | ||
|
||
public class SampleAuthenticator | ||
implements Authenticator<BasicCredentials, PrincipalImpl> { | ||
|
||
@Override | ||
public Optional<PrincipalImpl> authenticate(BasicCredentials credentials) | ||
throws AuthenticationException { | ||
if ("secret".equals(credentials.getPassword())) { | ||
return Optional.of(new PrincipalImpl(credentials.getUsername())); | ||
} | ||
return Optional.empty(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/io/federecio/dropwizard/sample/SampleConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.federecio.dropwizard.sample; | ||
|
||
import javax.validation.Valid; | ||
import javax.validation.constraints.NotNull; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import io.dropwizard.Configuration; | ||
import io.federecio.dropwizard.swagger.SwaggerBundleConfiguration; | ||
|
||
public class SampleConfiguration extends Configuration { | ||
|
||
@Valid | ||
@NotNull | ||
private final SwaggerBundleConfiguration swagger = new SwaggerBundleConfiguration(); | ||
|
||
@JsonProperty("swagger") | ||
public SwaggerBundleConfiguration getSwagger() { | ||
return swagger; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/io/federecio/dropwizard/sample/SampleResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package io.federecio.dropwizard.sample; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
import io.dropwizard.auth.Auth; | ||
import io.dropwizard.auth.PrincipalImpl; | ||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiOperation; | ||
import io.swagger.annotations.ApiResponse; | ||
import io.swagger.annotations.ApiResponses; | ||
import io.swagger.annotations.BasicAuthDefinition; | ||
import io.swagger.annotations.SecurityDefinition; | ||
import io.swagger.annotations.SwaggerDefinition; | ||
|
||
@Api("/") | ||
@Path("/") | ||
@SwaggerDefinition(securityDefinition = @SecurityDefinition(basicAuthDefinions = { | ||
@BasicAuthDefinition(key = "sample") })) | ||
public class SampleResource { | ||
|
||
@GET | ||
@Path("/hello") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@ApiOperation(value = "Hello", notes = "Returns hello") | ||
@ApiResponses(value = { @ApiResponse(code = 200, message = "hello") }) | ||
public Saying hello() { | ||
return new Saying("hello"); | ||
} | ||
|
||
@GET | ||
@Path("/secret") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@ApiOperation(value = "Secret", notes = "Returns secret") | ||
@ApiResponses(value = { @ApiResponse(code = 200, message = "secret") }) | ||
public Saying secret(@Auth PrincipalImpl user) { | ||
return new Saying("secret"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.federecio.dropwizard.sample; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public class Saying { | ||
|
||
private final String message; | ||
|
||
public Saying(String message) { | ||
this.message = message; | ||
} | ||
|
||
@JsonProperty | ||
public String getMessage() { | ||
return message; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.