Search in sources :

Example 1 with StringHolder

use of javax.xml.rpc.holders.StringHolder in project mobileid by codeborne.

the class MobileIDAuthenticatorTest method mockStatus.

private DigiDocServicePortType mockStatus(final Code status) throws RemoteException {
    DigiDocServicePortType service = mock(DigiDocServicePortType.class);
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            ((StringHolder) invocation.getArguments()[2]).value = status.toString();
            return null;
        }
    }).when(service).getMobileAuthenticateStatus(anyInt(), eq(false), any(StringHolder.class), any(StringHolder.class));
    return service;
}
Also used : StringHolder(javax.xml.rpc.holders.StringHolder) DigiDocServicePortType(com.codeborne.security.digidoc.DigiDocServicePortType) InvocationOnMock(org.mockito.invocation.InvocationOnMock)

Example 2 with StringHolder

use of javax.xml.rpc.holders.StringHolder in project mobileid by codeborne.

the class MobileIDAuthenticatorTest method mockAuthentication.

private DigiDocServicePortType mockAuthentication(String result, String firstName, String lastName, String personalCode, String challenge, int sessCode) throws RemoteException {
    DigiDocServicePortType service = mock(DigiDocServicePortType.class);
    doAnswer((Answer<Object>) invocation -> {
        ((IntHolder) invocation.getArguments()[11]).value = sessCode;
        ((StringHolder) invocation.getArguments()[12]).value = result;
        ((StringHolder) invocation.getArguments()[13]).value = personalCode;
        ((StringHolder) invocation.getArguments()[14]).value = firstName;
        ((StringHolder) invocation.getArguments()[15]).value = lastName;
        ((StringHolder) invocation.getArguments()[19]).value = challenge;
        return null;
    }).when(service).mobileAuthenticate(anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyInt(), anyBoolean(), anyBoolean(), any(IntHolder.class), any(StringHolder.class), any(StringHolder.class), any(StringHolder.class), any(StringHolder.class), any(StringHolder.class), any(StringHolder.class), any(StringHolder.class), any(StringHolder.class), any(StringHolder.class), any(StringHolder.class));
    return service;
}
Also used : DigiDocServicePortType(com.codeborne.security.digidoc.DigiDocServicePortType) IntHolder(javax.xml.rpc.holders.IntHolder) StringHolder(javax.xml.rpc.holders.StringHolder) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Matchers(org.mockito.Matchers) Test(org.junit.Test) RemoteException(java.rmi.RemoteException) Answer(org.mockito.stubbing.Answer) Mockito(org.mockito.Mockito) InvocationOnMock(org.mockito.invocation.InvocationOnMock) String.valueOf(java.lang.String.valueOf) Code(com.codeborne.security.AuthenticationException.Code) AuthenticationException(com.codeborne.security.AuthenticationException) Assert(org.junit.Assert) Before(org.junit.Before) StringHolder(javax.xml.rpc.holders.StringHolder) DigiDocServicePortType(com.codeborne.security.digidoc.DigiDocServicePortType) IntHolder(javax.xml.rpc.holders.IntHolder)

Example 3 with StringHolder

use of javax.xml.rpc.holders.StringHolder in project mobileid by codeborne.

the class MobileIDAuthenticator method startLogin.

protected MobileIDSession startLogin(String personalCode, String countryCode, String phone) {
    if (service == null) {
        throw new IllegalStateException("digidocServiceURL is not initialized");
    }
    if (phone != null) {
        if (phone.startsWith("+"))
            phone = phone.substring(1);
        if (!phone.startsWith("372"))
            phone = "372" + phone;
    }
    IntHolder sessCode = new IntHolder();
    StringHolder result = new StringHolder();
    StringHolder firstName = new StringHolder();
    StringHolder lastName = new StringHolder();
    StringHolder personalCodeHolder = new StringHolder();
    StringHolder challenge = new StringHolder();
    try {
        service.mobileAuthenticate(personalCode, countryCode, phone, language, serviceName, loginMessage, generateSPChallenge(), messagingMode, 0, false, false, sessCode, result, personalCodeHolder, firstName, lastName, new StringHolder(), new StringHolder(), new StringHolder(), challenge, new StringHolder(), new StringHolder());
    } catch (RemoteException e) {
        throw new AuthenticationException(e);
    }
    if (!"OK".equals(result.value))
        throw new AuthenticationException(valueOf(result.value));
    return new MobileIDSession(sessCode.value, challenge.value, firstName.value, lastName.value, personalCodeHolder.value);
}
Also used : StringHolder(javax.xml.rpc.holders.StringHolder) AuthenticationException(com.codeborne.security.AuthenticationException) IntHolder(javax.xml.rpc.holders.IntHolder) RemoteException(java.rmi.RemoteException)

Aggregations

StringHolder (javax.xml.rpc.holders.StringHolder)3 AuthenticationException (com.codeborne.security.AuthenticationException)2 DigiDocServicePortType (com.codeborne.security.digidoc.DigiDocServicePortType)2 RemoteException (java.rmi.RemoteException)2 IntHolder (javax.xml.rpc.holders.IntHolder)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Code (com.codeborne.security.AuthenticationException.Code)1 String.valueOf (java.lang.String.valueOf)1 CoreMatchers.equalTo (org.hamcrest.CoreMatchers.equalTo)1 Assert (org.junit.Assert)1 Before (org.junit.Before)1 Test (org.junit.Test)1 Matchers (org.mockito.Matchers)1 Mockito (org.mockito.Mockito)1 Answer (org.mockito.stubbing.Answer)1