Nevermind. I am able to fix this by fixing the CORS. But I have another issue. Instead of using @Auth PrincipalImpl user, I am using my own class.
@Auth AuthenticatedUser user And getting this exception. 0:0:0:0:0:0:0:1 - - [10/Oct/2017:04:38:37 +0000] "GET /service/class/all/a HTTP/1.1" 415 - "http://127.0.0.1:3001/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36" 1 ERROR [2017-10-10 04:38:37,452] com.sun.jersey.spi.container.ContainerRequest: A message body reader for Java class com.appgroup.dataaccess.security.AuthenticatedUser, and Java type class com.appgroup.dataaccess.security.AuthenticatedUser, and MIME media type application/octet-stream was not found. The registered message body readers compatible with the MIME media type are: */* -> com.sun.jersey.core.impl.provider.entity.FormProvider com.sun.jersey.core.impl.provider.entity.MimeMultipartProvider where public class AuthenticatedUser extends com.appgroup.security.User { // usrAuthenticated indicates that we have an actual usr.usr to work with in authenticatedName private boolean usrAuthenticated; public AuthenticatedUser(String usr, String displayName, String givenName, String surname, String emailAddr) { super(usr,displayName,givenName,surname,emailAddr); this.usrAuthenticated = true; } public boolean isUsrAuthenticated() { return usrAuthenticated; } public void setUsrAuthenticated(boolean usrAuthenticated) { this.usrAuthenticated = usrAuthenticated; } } And // // Source code recreated from a .class file by IntelliJ IDEA // (powered by Fernflower decompiler) // package com.appgroup.security; import com.fasterxml.jackson.annotation.JsonIgnore; import java.beans.ConstructorProperties; public class User { private final String authenticatedName; private final String displayName; private final String givenName; private final String surname; private final String emailAddress; private String sessionId; @JsonIgnore private boolean superUser = false; @ConstructorProperties({"authenticatedName", "displayName", "givenName", "surname", "emailAddress"}) public User(String authenticatedName, String displayName, String givenName, String surname, String emailAddress) { this.authenticatedName = authenticatedName; this.displayName = displayName; this.givenName = givenName; this.surname = surname; this.emailAddress = emailAddress; } public String getAuthenticatedName() { return this.authenticatedName; } public String getDisplayName() { return this.displayName; } public String getGivenName() { return this.givenName; } public String getSurname() { return this.surname; } public String getEmailAddress() { return this.emailAddress; } public String getSessionId() { return this.sessionId; } public boolean isSuperUser() { return this.superUser; } public void setSessionId(String sessionId) { this.sessionId = sessionId; } public void setSuperUser(boolean superUser) { this.superUser = superUser; } public boolean equals(Object o) { if(o == this) { return true; } else if(!(o instanceof AuthenticatedUser)) { return false; } else { AuthenticatedUser other = (AuthenticatedUser)o; if(!other.canEqual(this)) { return false; } else { label87: { String this$authenticatedName = this.getAuthenticatedName(); String other$authenticatedName = other.getAuthenticatedName(); if(this$authenticatedName == null) { if(other$authenticatedName == null) { break label87; } } else if(this$authenticatedName.equals(other$authenticatedName)) { break label87; } return false; } String this$displayName = this.getDisplayName(); String other$displayName = other.getDisplayName(); if(this$displayName == null) { if(other$displayName != null) { return false; } } else if(!this$displayName.equals(other$displayName)) { return false; } label73: { String this$givenName = this.getGivenName(); String other$givenName = other.getGivenName(); if(this$givenName == null) { if(other$givenName == null) { break label73; } } else if(this$givenName.equals(other$givenName)) { break label73; } return false; } String this$surname = this.getSurname(); String other$surname = other.getSurname(); if(this$surname == null) { if(other$surname != null) { return false; } } else if(!this$surname.equals(other$surname)) { return false; } label59: { String this$emailAddress = this.getEmailAddress(); String other$emailAddress = other.getEmailAddress(); if(this$emailAddress == null) { if(other$emailAddress == null) { break label59; } } else if(this$emailAddress.equals(other$emailAddress)) { break label59; } return false; } String this$sessionId = this.getSessionId(); String other$sessionId = other.getSessionId(); if(this$sessionId == null) { if(other$sessionId != null) { return false; } } else if(!this$sessionId.equals(other$sessionId)) { return false; } if(this.isSuperUser() != other.isSuperUser()) { return false; } else { return true; } } } } protected boolean canEqual(Object other) { return other instanceof AuthenticatedUser; } public int hashCode() { boolean PRIME = true; byte result = 1; String $authenticatedName = this.getAuthenticatedName(); int result1 = result * 59 + ($authenticatedName == null?43:$authenticatedName.hashCode()); String $displayName = this.getDisplayName(); result1 = result1 * 59 + ($displayName == null?43:$displayName.hashCode()); String $givenName = this.getGivenName(); result1 = result1 * 59 + ($givenName == null?43:$givenName.hashCode()); String $surname = this.getSurname(); result1 = result1 * 59 + ($surname == null?43:$surname.hashCode()); String $emailAddress = this.getEmailAddress(); result1 = result1 * 59 + ($emailAddress == null?43:$emailAddress.hashCode()); String $sessionId = this.getSessionId(); result1 = result1 * 59 + ($sessionId == null?43:$sessionId.hashCode()); result1 = result1 * 59 + (this.isSuperUser()?79:97); return result1; } public String toString() { return "User(authenticatedName=" + this.getAuthenticatedName() + ", displayName=" + this.getDisplayName() + ", givenName=" + this.getGivenName() + ", surname=" + this.getSurname() + ", emailAddress=" + this.getEmailAddress() + ", sessionId=" + this.getSessionId() + ", superUser=" + this.isSuperUser() + ")"; } } On Tue, Oct 10, 2017 at 9:22 AM, Piyush Mendhiratta < [email protected]> wrote: > Thanks Ron, > > This works for me. But now I am running into another issues, > > When I am sending a GET request with following prototype, It sends a > OPTIONS call from swagger editor, which returns a 200 response, But how > will I send the GET request to get the API working.? > > public Saying secret(@ApiParam(hidden = true) @Auth PrincipalImpl user) > { > > > > > Thanks > Piyush > > On Monday, October 9, 2017 at 11:01:47 PM UTC+5:30, Ron wrote: >> >> You can hide any generated parameter by adding the @ApiParam(hidden=true) >> annotation. >> >> >> >> >> >> >> >> *From: *<[email protected]> on behalf of Piyush Mendhiratta >> <[email protected]> >> *Reply-To: *"[email protected]" <swagger-sw...@googlegroups. >> com> >> *Date: *Monday, October 9, 2017 at 01:18 >> *To: *Swagger <[email protected]> >> *Subject: *Swagger Dropwizard Authentication >> >> >> >> I am trying to create swagger using the swaggerUI. My API framework uses >> dropwizard. Now when I am trying to use a GET resource with @Auth for >> authentication, swagger that is generated have a body that should have a >> "User". But ideally any GET request should not have a "body". ANy >> suggestions on how to deal with the situation. Or if anyone has used >> swagger with dropwizard. >> >> >> >> @GET >> @Path(*"/all/{userName}/"*) >> @Produces(MediaType.*APPLICATION_JSON*) >> @ApiOperation( >> value = *"Journal Number"*, >> notes = *"Returns Journal Number for a company"*, >> response = GeneralLedger.*class*, >> authorizations = {@Authorization(value=*"basicAuth"*)}) >> *public *Response classInfoForUsername >> (@Auth AuthenticatedUser user, >> @PathParam(*"userName"*) String userName) { >> >> .... >> >> } >> >> >> >> >> >> >> >> >> >> Swagger generated is : >> >> >> >> "/class/all/{userName}" : { >> >> "get" : { >> >> "summary" : "Journal Number", >> >> "description" : "Returns Journal Number for a company", >> >> "operationId" : "classInfoForUsername", >> >> "consumes" : [ "application/json" ], >> >> "produces" : [ "application/json" ], >> >> "parameters" : [ { >> >> "in" : "body", >> >> "name" : "body", >> >> "required" : false, >> >> "schema" : { >> >> "$ref" : "#/definitions/AuthenticatedUser" >> >> } >> >> }, { >> >> "name" : "userName", >> >> "in" : "path", >> >> "required" : true, >> >> "type" : "string" >> >> } ], >> >> "responses" : { >> >> "default" : { >> >> "description" : "successful operation" >> >> } >> >> }, >> >> "security" : [ { >> >> "basicAuth" : [ ] >> >> } ] >> >> } >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Swagger" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> For more options, visit https://groups.google.com/d/optout. >> >> -- > You received this message because you are subscribed to a topic in the > Google Groups "Swagger" group. > To unsubscribe from this topic, visit https://groups.google.com/d/ > topic/swagger-swaggersocket/zvuwPhebNP4/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- Piyush Mendhiratta 9999414230 -- You received this message because you are subscribed to the Google Groups "Swagger" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
