@ POST @ Produces ( MediaType . TEXT_PLAIN ) @ ApiOperation ( value = "Assert login credentials" , notes = "Upon a successful login, a JWT will be returned in the response. This functionality requires authentication to be enabled." , response = String . class ) @ ApiResponses ( value = { @ ApiResponse ( code = 200 , message = "Success" ) , @ ApiResponse ( code = 401 , message = "Unauthorized" ) } ) @ AuthenticationNotRequired public Response validateCredentials ( @ FormParam ( "username" ) String username , @ FormParam ( "password" ) String password ) { final Authenticator auth = new Authenticator ( username , password ) ; try { final Principal principal = auth . authenticate ( ) ; if ( principal != null ) { LOGGER . info ( SecurityMarkers . SECURITY_AUDIT , "Login succeeded (username: " + username + " / ip address: " + super . getRemoteAddress ( ) + " / agent: " + super . getUserAgent ( ) + ")" ) ; final JsonWebToken jwt = new JsonWebToken ( ) ; final String token = jwt . createToken ( principal ) ; return Response . ok ( token ) . build ( ) ; } } catch ( AuthenticationException e ) { LOGGER . warn ( SecurityMarkers . SECURITY_AUDIT , "Unauthorized login attempt (username: " + username + " / ip address: " + super . getRemoteAddress ( ) + " / agent: " + super . getUserAgent ( ) + ")" ) ; } return Response . status ( Response . Status . UNAUTHORIZED ) . build ( ) ; }
Processes login requests .