Add parameters from error response to exception
Introduce a new exception class to hold the parameters from an authentication error response, allowing simpler retrieval later in the filter processing.pull/1015/merge
parent
f056eb9387
commit
e1ae8f3d8d
|
@ -0,0 +1,33 @@
|
|||
package org.mitre.openid.connect.client;
|
||||
|
||||
import org.springframework.security.authentication.AuthenticationServiceException;
|
||||
|
||||
public class AuthorizationEndpointException extends AuthenticationServiceException {
|
||||
|
||||
private static final long serialVersionUID = 6953119789654778380L;
|
||||
|
||||
private String error;
|
||||
|
||||
private String errorDescription;
|
||||
|
||||
private String errorURI;
|
||||
|
||||
public AuthorizationEndpointException(String error, String errorDescription, String errorURI) {
|
||||
super("Error from Authorization Endpoint: " + error + " " + errorDescription + " " + errorURI);
|
||||
this.error = error;
|
||||
this.errorDescription = errorDescription;
|
||||
this.errorURI = errorURI;
|
||||
}
|
||||
|
||||
public String getError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
public String getErrorDescription() {
|
||||
return errorDescription;
|
||||
}
|
||||
|
||||
public String getErrorURI() {
|
||||
return errorURI;
|
||||
}
|
||||
}
|
|
@ -649,7 +649,7 @@ public class OIDCAuthenticationFilter extends AbstractAuthenticationProcessingFi
|
|||
String errorDescription = request.getParameter("error_description");
|
||||
String errorURI = request.getParameter("error_uri");
|
||||
|
||||
throw new AuthenticationServiceException("Error from Authorization Endpoint: " + error + " " + errorDescription + " " + errorURI);
|
||||
throw new AuthorizationEndpointException(error, errorDescription, errorURI);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package org.mitre.openid.connect.client;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.security.authentication.AuthenticationServiceException;
|
||||
|
||||
public class TestOIDCAuthenticationFilter {
|
||||
|
||||
private OIDCAuthenticationFilter filter = new OIDCAuthenticationFilter();
|
||||
|
||||
@Test
|
||||
public void attemptAuthentication_error() throws Exception {
|
||||
|
||||
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
|
||||
Mockito.when(request.getParameter("error")).thenReturn("Error");
|
||||
Mockito.when(request.getParameter("error_description")).thenReturn("Description");
|
||||
Mockito.when(request.getParameter("error_uri")).thenReturn("http://example.com");
|
||||
|
||||
try {
|
||||
filter.attemptAuthentication(request, mock(HttpServletResponse.class));
|
||||
|
||||
fail("AuthorizationEndpointException expected.");
|
||||
}
|
||||
catch (AuthorizationEndpointException exception) {
|
||||
assertThat(exception.getMessage(),
|
||||
is("Error from Authorization Endpoint: Error Description http://example.com"));
|
||||
|
||||
assertThat(exception.getError(), is("Error"));
|
||||
assertThat(exception.getErrorDescription(), is("Description"));
|
||||
assertThat(exception.getErrorURI(), is("http://example.com"));
|
||||
|
||||
assertThat(exception, is(instanceOf(AuthenticationServiceException.class)));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue