Search in sources :

Example 1 with AuthenticationMethod

use of org.gluu.oxtrust.api.server.model.AuthenticationMethod in project oxTrust by GluuFederation.

the class AuthenticationMethodWebResource method getCurrentAuthentication.

@GET
@Operation(summary = "Get current authentication methods", description = "Get current authentication methods")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = AuthenticationMethod.class)), description = Constants.RESULT_SUCCESS), @ApiResponse(responseCode = "500", description = "Server error") })
@ProtectedApi(scopes = { READ_ACCESS })
public Response getCurrentAuthentication() {
    log(logger, "Processing getCurrentAuthentication()");
    try {
        GluuConfiguration configuration = configurationService.getConfiguration();
        AuthenticationMethod method = new AuthenticationMethod();
        method.setDefaultAcr(configuration.getAuthenticationMode());
        method.setOxtrustAcr(configuration.getOxTrustAuthenticationMode());
        return Response.ok(method).build();
    } catch (Exception e) {
        log(logger, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : AuthenticationMethod(org.gluu.oxtrust.api.server.model.AuthenticationMethod) GluuConfiguration(org.gluu.oxtrust.model.GluuConfiguration) GET(javax.ws.rs.GET) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 2 with AuthenticationMethod

use of org.gluu.oxtrust.api.server.model.AuthenticationMethod in project oxTrust by GluuFederation.

the class AuthenticationMethodWebResourceTest method updateAuthenticationMethodTest.

@Test
public void updateAuthenticationMethodTest() {
    HttpPut request = new HttpPut(BASE_URL + ApiConstants.BASE_API_URL + ApiConstants.ACRS);
    AuthenticationMethod method = new AuthenticationMethod();
    String defaultAcr = "auth_ldap_server";
    method.setDefaultAcr(defaultAcr);
    method.setOxtrustAcr(defaultAcr);
    try {
        String json = mapper.writeValueAsString(method);
        HttpEntity entity = new ByteArrayEntity(json.toString().getBytes("UTF-8"));
        request.setEntity(entity);
        request.setHeader("Content-Type", MediaType.APPLICATION_JSON);
        HttpResponse response = handle(request);
        Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
        HttpEntity result = response.getEntity();
        AuthenticationMethod value = mapper.readValue(EntityUtils.toString(result), AuthenticationMethod.class);
        Assert.assertEquals(value.getOxtrustAcr(), defaultAcr);
        Assert.assertEquals(value.getDefaultAcr(), defaultAcr);
    } catch (ParseException | IOException e) {
        e.printStackTrace();
        Assert.assertTrue(false);
    }
}
Also used : HttpEntity(org.apache.http.HttpEntity) ByteArrayEntity(org.apache.http.entity.ByteArrayEntity) HttpResponse(org.apache.http.HttpResponse) AuthenticationMethod(org.gluu.oxtrust.api.server.model.AuthenticationMethod) ParseException(org.apache.http.ParseException) IOException(java.io.IOException) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 3 with AuthenticationMethod

use of org.gluu.oxtrust.api.server.model.AuthenticationMethod in project oxTrust by GluuFederation.

the class AuthenticationMethodWebResourceTest method getCurrentAuthenticationTest.

@Test
public void getCurrentAuthenticationTest() {
    HttpUriRequest request = new HttpGet(BASE_URL + ApiConstants.BASE_API_URL + ApiConstants.ACRS);
    try {
        HttpResponse response = handle(request);
        Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
        HttpEntity result = response.getEntity();
        AuthenticationMethod method = mapper.readValue(EntityUtils.toString(result), AuthenticationMethod.class);
        Assert.assertNotNull(method.getDefaultAcr());
        Assert.assertNotNull(method.getOxtrustAcr());
    } catch (ParseException | IOException e) {
        e.printStackTrace();
        Assert.assertTrue(false);
    }
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) HttpEntity(org.apache.http.HttpEntity) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) AuthenticationMethod(org.gluu.oxtrust.api.server.model.AuthenticationMethod) ParseException(org.apache.http.ParseException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

AuthenticationMethod (org.gluu.oxtrust.api.server.model.AuthenticationMethod)3 IOException (java.io.IOException)2 HttpEntity (org.apache.http.HttpEntity)2 HttpResponse (org.apache.http.HttpResponse)2 ParseException (org.apache.http.ParseException)2 Test (org.junit.Test)2 Operation (io.swagger.v3.oas.annotations.Operation)1 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)1 GET (javax.ws.rs.GET)1 HttpGet (org.apache.http.client.methods.HttpGet)1 HttpPut (org.apache.http.client.methods.HttpPut)1 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)1 ByteArrayEntity (org.apache.http.entity.ByteArrayEntity)1 GluuConfiguration (org.gluu.oxtrust.model.GluuConfiguration)1 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)1