Search in sources :

Example 11 with AuthenticationVO

use of org.olat.restapi.support.vo.AuthenticationVO in project openolat by klemens.

the class ObjectFactory method get.

public static AuthenticationVO get(Authentication authentication, boolean withCred) {
    AuthenticationVO vo = new AuthenticationVO();
    vo.setKey(authentication.getKey());
    vo.setIdentityKey(authentication.getIdentity().getKey());
    vo.setAuthUsername(authentication.getAuthusername());
    vo.setProvider(authentication.getProvider());
    if (withCred) {
        vo.setCredential(authentication.getCredential());
    }
    return vo;
}
Also used : AuthenticationVO(org.olat.restapi.support.vo.AuthenticationVO)

Example 12 with AuthenticationVO

use of org.olat.restapi.support.vo.AuthenticationVO in project openolat by klemens.

the class UserAuthenticationMgmtTest method createAuthentications_checkDuplicate.

/**
 * Check if the REST call return a specific error if the pair authentication user name and provider
 * is already used.
 */
@Test
public void createAuthentications_checkDuplicate() throws IOException, URISyntaxException {
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("check-auth-1");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("check-auth-2");
    String authUsername = UUID.randomUUID().toString();
    dbInstance.commitAndCloseSession();
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    // set the first authentication
    AuthenticationVO vo1 = new AuthenticationVO();
    vo1.setAuthUsername(authUsername);
    vo1.setIdentityKey(id1.getKey());
    vo1.setProvider("REST-API");
    vo1.setCredential("credentials");
    URI request1 = UriBuilder.fromUri(getContextURI()).path("/users/" + id1.getName() + "/auth").build();
    HttpPut method1 = conn.createPut(request1, MediaType.APPLICATION_JSON, true);
    conn.addJsonEntity(method1, vo1);
    HttpResponse response1 = conn.execute(method1);
    Assert.assertEquals(200, response1.getStatusLine().getStatusCode());
    conn.parse(response1, AuthenticationVO.class);
    Authentication refAuth1 = securityManager.findAuthentication(id1, "REST-API");
    Assert.assertNotNull(refAuth1);
    Assert.assertEquals(id1, refAuth1.getIdentity());
    // set the second which duplicates the first
    AuthenticationVO vo2 = new AuthenticationVO();
    vo2.setAuthUsername(authUsername);
    vo2.setIdentityKey(id2.getKey());
    vo2.setProvider("REST-API");
    vo2.setCredential("credentials");
    URI request2 = UriBuilder.fromUri(getContextURI()).path("/users/" + id2.getName() + "/auth").build();
    HttpPut method2 = conn.createPut(request2, MediaType.APPLICATION_JSON, true);
    conn.addJsonEntity(method2, vo2);
    HttpResponse response2 = conn.execute(method2);
    Assert.assertEquals(409, response2.getStatusLine().getStatusCode());
    ErrorVO error = conn.parse(response2, ErrorVO.class);
    Assert.assertNotNull(error);
    conn.shutdown();
}
Also used : ErrorVO(org.olat.restapi.support.vo.ErrorVO) Authentication(org.olat.basesecurity.Authentication) HttpResponse(org.apache.http.HttpResponse) Identity(org.olat.core.id.Identity) AuthenticationVO(org.olat.restapi.support.vo.AuthenticationVO) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Aggregations

AuthenticationVO (org.olat.restapi.support.vo.AuthenticationVO)12 Authentication (org.olat.basesecurity.Authentication)8 Identity (org.olat.core.id.Identity)8 URI (java.net.URI)6 HttpResponse (org.apache.http.HttpResponse)6 Test (org.junit.Test)6 Produces (javax.ws.rs.Produces)4 HttpPut (org.apache.http.client.methods.HttpPut)4 BaseSecurity (org.olat.basesecurity.BaseSecurity)4 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)4 ErrorVO (org.olat.restapi.support.vo.ErrorVO)4 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 URISyntaxException (java.net.URISyntaxException)2 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 PUT (javax.ws.rs.PUT)2 HttpGet (org.apache.http.client.methods.HttpGet)2