Search in sources :

Example 1 with ConsumerManager

use of org.openid4java.consumer.ConsumerManager in project spring-security by spring-projects.

the class OpenID4JavaConsumerTests method discoveryExceptionRaisesOpenIDException.

@Test(expected = OpenIDConsumerException.class)
public void discoveryExceptionRaisesOpenIDException() throws Exception {
    ConsumerManager mgr = mock(ConsumerManager.class);
    OpenID4JavaConsumer consumer = new OpenID4JavaConsumer(mgr, new NullAxFetchListFactory());
    when(mgr.discover(anyString())).thenThrow(new DiscoveryException("msg"));
    consumer.beginConsumption(new MockHttpServletRequest(), "", "", "");
}
Also used : ConsumerManager(org.openid4java.consumer.ConsumerManager) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) DiscoveryException(org.openid4java.discovery.DiscoveryException)

Example 2 with ConsumerManager

use of org.openid4java.consumer.ConsumerManager in project spring-security by spring-projects.

the class OpenID4JavaConsumerTests method successfulVerificationReturnsExpectedAuthentication.

@SuppressWarnings("serial")
@Test
public void successfulVerificationReturnsExpectedAuthentication() throws Exception {
    ConsumerManager mgr = mock(ConsumerManager.class);
    OpenID4JavaConsumer consumer = new OpenID4JavaConsumer(mgr, new NullAxFetchListFactory());
    VerificationResult vr = mock(VerificationResult.class);
    DiscoveryInformation di = mock(DiscoveryInformation.class);
    Identifier id = new Identifier() {

        public String getIdentifier() {
            return "id";
        }
    };
    Message msg = mock(Message.class);
    when(mgr.verify(anyString(), any(ParameterList.class), any(DiscoveryInformation.class))).thenReturn(vr);
    when(vr.getVerifiedId()).thenReturn(id);
    when(vr.getAuthResponse()).thenReturn(msg);
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.getSession().setAttribute(DiscoveryInformation.class.getName(), di);
    request.getSession().setAttribute("SPRING_SECURITY_OPEN_ID_ATTRIBUTES_FETCH_LIST", attributes);
    OpenIDAuthenticationToken auth = consumer.endConsumption(request);
    assertThat(auth.getStatus()).isEqualTo(OpenIDAuthenticationStatus.SUCCESS);
}
Also used : Identifier(org.openid4java.discovery.Identifier) ConsumerManager(org.openid4java.consumer.ConsumerManager) VerificationResult(org.openid4java.consumer.VerificationResult) AxMessage(org.openid4java.message.ax.AxMessage) Message(org.openid4java.message.Message) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) DiscoveryInformation(org.openid4java.discovery.DiscoveryInformation) ParameterList(org.openid4java.message.ParameterList)

Example 3 with ConsumerManager

use of org.openid4java.consumer.ConsumerManager in project spring-security by spring-projects.

the class OpenID4JavaConsumerTests method beginConsumptionCreatesExpectedSessionData.

@SuppressWarnings("deprecation")
@Test
public void beginConsumptionCreatesExpectedSessionData() throws Exception {
    ConsumerManager mgr = mock(ConsumerManager.class);
    AuthRequest authReq = mock(AuthRequest.class);
    DiscoveryInformation di = mock(DiscoveryInformation.class);
    when(mgr.authenticate(any(DiscoveryInformation.class), anyString(), anyString())).thenReturn(authReq);
    when(mgr.associate(anyList())).thenReturn(di);
    OpenID4JavaConsumer consumer = new OpenID4JavaConsumer(mgr, new MockAttributesFactory());
    MockHttpServletRequest request = new MockHttpServletRequest();
    consumer.beginConsumption(request, "", "", "");
    assertThat(request.getSession().getAttribute("SPRING_SECURITY_OPEN_ID_ATTRIBUTES_FETCH_LIST")).isEqualTo(attributes);
    assertThat(request.getSession().getAttribute(DiscoveryInformation.class.getName())).isEqualTo(di);
    // Check with empty attribute fetch list
    consumer = new OpenID4JavaConsumer(mgr, new NullAxFetchListFactory());
    request = new MockHttpServletRequest();
    consumer.beginConsumption(request, "", "", "");
}
Also used : AuthRequest(org.openid4java.message.AuthRequest) ConsumerManager(org.openid4java.consumer.ConsumerManager) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) DiscoveryInformation(org.openid4java.discovery.DiscoveryInformation)

Example 4 with ConsumerManager

use of org.openid4java.consumer.ConsumerManager in project spring-security by spring-projects.

the class OpenID4JavaConsumerTests method messageOrConsumerAuthenticationExceptionRaisesOpenIDException.

@Test
public void messageOrConsumerAuthenticationExceptionRaisesOpenIDException() throws Exception {
    ConsumerManager mgr = mock(ConsumerManager.class);
    OpenID4JavaConsumer consumer = new OpenID4JavaConsumer(mgr, new NullAxFetchListFactory());
    when(mgr.authenticate(any(DiscoveryInformation.class), anyString(), anyString())).thenThrow(new MessageException("msg"), new ConsumerException("msg"));
    try {
        consumer.beginConsumption(new MockHttpServletRequest(), "", "", "");
        fail("OpenIDConsumerException was not thrown");
    } catch (OpenIDConsumerException expected) {
    }
    try {
        consumer.beginConsumption(new MockHttpServletRequest(), "", "", "");
        fail("OpenIDConsumerException was not thrown");
    } catch (OpenIDConsumerException expected) {
    }
}
Also used : ConsumerManager(org.openid4java.consumer.ConsumerManager) MessageException(org.openid4java.message.MessageException) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) DiscoveryInformation(org.openid4java.discovery.DiscoveryInformation) ConsumerException(org.openid4java.consumer.ConsumerException)

Example 5 with ConsumerManager

use of org.openid4java.consumer.ConsumerManager in project spring-security by spring-projects.

the class OpenID4JavaConsumerTests method verificationExceptionsRaiseOpenIDException.

@Test
public void verificationExceptionsRaiseOpenIDException() throws Exception {
    ConsumerManager mgr = mock(ConsumerManager.class);
    OpenID4JavaConsumer consumer = new OpenID4JavaConsumer(mgr, new NullAxFetchListFactory());
    when(mgr.verify(anyString(), any(ParameterList.class), any(DiscoveryInformation.class))).thenThrow(new MessageException("")).thenThrow(new AssociationException("")).thenThrow(new DiscoveryException(""));
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setQueryString("x=5");
    try {
        consumer.endConsumption(request);
        fail("OpenIDConsumerException was not thrown");
    } catch (OpenIDConsumerException expected) {
    }
    try {
        consumer.endConsumption(request);
        fail("OpenIDConsumerException was not thrown");
    } catch (OpenIDConsumerException expected) {
    }
    try {
        consumer.endConsumption(request);
        fail("OpenIDConsumerException was not thrown");
    } catch (OpenIDConsumerException expected) {
    }
}
Also used : ConsumerManager(org.openid4java.consumer.ConsumerManager) MessageException(org.openid4java.message.MessageException) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) DiscoveryInformation(org.openid4java.discovery.DiscoveryInformation) ParameterList(org.openid4java.message.ParameterList) AssociationException(org.openid4java.association.AssociationException) DiscoveryException(org.openid4java.discovery.DiscoveryException)

Aggregations

ConsumerManager (org.openid4java.consumer.ConsumerManager)6 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)6 DiscoveryInformation (org.openid4java.discovery.DiscoveryInformation)5 ParameterList (org.openid4java.message.ParameterList)3 VerificationResult (org.openid4java.consumer.VerificationResult)2 DiscoveryException (org.openid4java.discovery.DiscoveryException)2 MessageException (org.openid4java.message.MessageException)2 AssociationException (org.openid4java.association.AssociationException)1 ConsumerException (org.openid4java.consumer.ConsumerException)1 Identifier (org.openid4java.discovery.Identifier)1 AuthRequest (org.openid4java.message.AuthRequest)1 Message (org.openid4java.message.Message)1 AxMessage (org.openid4java.message.ax.AxMessage)1