Skip to content

Commit 18a405e

Browse files
committed
improve oauth error messages
1 parent fc07223 commit 18a405e

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

server/src/main/java/password/pwm/http/servlet/oauth/OAuthConsumerServlet.java

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ protected void processAction( final PwmRequest pwmRequest )
105105
pwmRequest.getPwmResponse().sendRedirect( nextUrl );
106106
return;
107107
}
108-
final String errorMsg = "oauth consumer reached, but oauth authentication has not yet been initiated.";
108+
final String errorMsg = "oauth consumer reached, but oauth authentication has not yet been initiated";
109109
final ErrorInformation errorInformation = new ErrorInformation( PwmError.ERROR_OAUTH_ERROR, errorMsg );
110110
pwmRequest.respondWithError( errorInformation );
111111
LOGGER.error( pwmRequest, () -> errorMsg );
@@ -118,9 +118,9 @@ protected void processAction( final PwmRequest pwmRequest )
118118
final String oauthRequestError = pwmRequest.readParameterAsString( "error" );
119119
if ( oauthRequestError != null && !oauthRequestError.isEmpty() )
120120
{
121-
final String errorMsg = "incoming request from remote oauth server is indicating an error: " + oauthRequestError;
122-
final ErrorInformation errorInformation = new ErrorInformation( PwmError.ERROR_OAUTH_ERROR, errorMsg, "Remote Error: " + oauthRequestError, null );
123-
LOGGER.error( pwmRequest, () -> errorMsg );
121+
final String errorMsg = "incoming request from remote oauth server has indicated an error";
122+
final ErrorInformation errorInformation = new ErrorInformation( PwmError.ERROR_OAUTH_ERROR, errorMsg );
123+
LOGGER.error( pwmRequest, () -> errorMsg + ": " + oauthRequestError );
124124
pwmRequest.respondWithError( errorInformation );
125125
return;
126126
}
@@ -131,19 +131,18 @@ protected void processAction( final PwmRequest pwmRequest )
131131
{
132132
switch ( oAuthUseCaseCase )
133133
{
134-
case Authentication:
135-
LOGGER.debug( pwmRequest, () -> "oauth consumer reached, but user is already authenticated; will proceed and verify authcode matches current user identity." );
136-
break;
137-
138-
case ForgottenPassword:
134+
case Authentication ->
135+
LOGGER.debug( pwmRequest, () -> "oauth consumer reached, but user is already authenticated; "
136+
+ "will proceed and verify authcode matches current user identity." );
137+
case ForgottenPassword ->
138+
{
139139
final String errorMsg = "oauth consumer reached via " + OAuthUseCase.ForgottenPassword + ", but user is already authenticated";
140140
final ErrorInformation errorInformation = new ErrorInformation( PwmError.ERROR_OAUTH_ERROR, errorMsg );
141141
pwmRequest.respondWithError( errorInformation );
142142
LOGGER.error( pwmRequest, () -> errorMsg );
143143
return;
144-
145-
default:
146-
PwmUtil.unhandledSwitchStatement( oAuthUseCaseCase );
144+
}
145+
default -> PwmUtil.unhandledSwitchStatement( oAuthUseCaseCase );
147146
}
148147

149148
}
@@ -276,9 +275,9 @@ protected void processAction( final PwmRequest pwmRequest )
276275
}
277276
catch ( final PwmOperationalException e )
278277
{
279-
final String errorMsg = "error while examining incoming oauth code for already authenticated session: " + e.getMessage();
278+
final String errorMsg = "error while examining incoming oauth code for already authenticated session";
280279
final ErrorInformation errorInformation = new ErrorInformation( PwmError.ERROR_OAUTH_ERROR, errorMsg );
281-
LOGGER.error( pwmRequest, () -> errorMsg );
280+
LOGGER.error( pwmRequest, () -> errorMsg + ": " + e.getMessage() );
282281
pwmRequest.respondWithError( errorInformation );
283282
return;
284283
}
@@ -302,8 +301,9 @@ protected void processAction( final PwmRequest pwmRequest )
302301
}
303302
catch ( final PwmException e )
304303
{
305-
LOGGER.error( pwmRequest, () -> "error during OAuth authentication attempt: " + e.getMessage() );
306-
final ErrorInformation errorInformation = new ErrorInformation( PwmError.ERROR_OAUTH_ERROR, e.getMessage() );
304+
final String errorMsg = "error during OAuth authentication attempt";
305+
LOGGER.error( pwmRequest, () -> errorMsg + ": " + e.getMessage() );
306+
final ErrorInformation errorInformation = new ErrorInformation( PwmError.ERROR_OAUTH_ERROR, errorMsg );
307307
pwmRequest.respondWithError( errorInformation );
308308
return;
309309
}
@@ -316,17 +316,17 @@ private static OAuthSettings makeOAuthSettings( final PwmRequest pwmRequest, fin
316316
final OAuthUseCase oAuthUseCase = oAuthState.getUseCase();
317317
switch ( oAuthUseCase )
318318
{
319-
case Authentication:
319+
case Authentication ->
320+
{
320321
return OAuthSettings.forSSOAuthentication( pwmRequest.getDomainConfig() );
321-
322-
case ForgottenPassword:
322+
}
323+
case ForgottenPassword ->
324+
{
323325
final ProfileID profileId = oAuthState.getForgottenProfileId();
324326
final ForgottenPasswordProfile profile = pwmRequest.getDomainConfig().getForgottenPasswordProfiles().get( profileId );
325327
return OAuthSettings.forForgottenPassword( profile );
326-
327-
default:
328-
PwmUtil.unhandledSwitchStatement( oAuthUseCase );
329-
328+
}
329+
default -> PwmUtil.unhandledSwitchStatement( oAuthUseCase );
330330
}
331331

332332
final String errorMsg = "unable to calculate oauth settings for incoming request state";
@@ -335,7 +335,8 @@ private static OAuthSettings makeOAuthSettings( final PwmRequest pwmRequest, fin
335335
throw new PwmUnrecoverableException( errorInformation );
336336
}
337337

338-
private void redirectToForgottenPasswordServlet( final PwmRequest pwmRequest, final String oauthSuppliedUsername ) throws IOException, PwmUnrecoverableException
338+
private void redirectToForgottenPasswordServlet( final PwmRequest pwmRequest, final String oauthSuppliedUsername )
339+
throws IOException, PwmUnrecoverableException
339340
{
340341
final OAuthForgottenPasswordResults results = new OAuthForgottenPasswordResults( true, oauthSuppliedUsername );
341342
final String encryptedResults = pwmRequest.getPwmDomain().getSecureService().encryptObjectToString( results );

0 commit comments

Comments
 (0)