Search in sources :

Example 21 with Scope

use of com.auth0.json.mgmt.Scope in project ddf by codice.

the class TestOidc method testCodeFlowLogin.

// --------------------------Code Flow Tests--------------------------//
@Test
public void testCodeFlowLogin() throws Exception {
    Map<String, String> initialResponseParams = sendInitialRequest(CODE);
    assertThat(initialResponseParams.get(SCOPE), is(DDF_SCOPE));
    assertThat(initialResponseParams.get(RESPONSE_TYPE), is(CODE));
    assertThat(initialResponseParams.get(CLIENT_ID), is(DDF_CLIENT_ID));
    assertTrue(initialResponseParams.containsKey(REDIRECT_URI));
    // recommended by spec
    assertTrue(initialResponseParams.containsKey(STATE));
    // optional but sent in DDF
    assertTrue(initialResponseParams.containsKey(RESPONSE_MODE));
    // optional but sent in DDF
    assertTrue(initialResponseParams.containsKey(NONCE));
    // Add token endpoint information to stub server
    String basicAuthHeader = "Basic " + java.util.Base64.getEncoder().encodeToString((DDF_CLIENT_ID + ":" + DDF_CLIENT_SECRET).getBytes(StandardCharsets.UTF_8));
    String validIdToken = getBaseIdTokenBuilder().withClaim(NONCE, initialResponseParams.get(NONCE)).sign(validAlgorithm);
    String validAccessToken = createAccessToken(true);
    String tokenEndpointResponse = createTokenEndpointResponse(validIdToken, validAccessToken);
    whenHttp(server).match(post(TOKEN_ENDPOINT_PATH), parameter(CODE, TEMPORARY_CODE), parameter("grant_type", "authorization_code"), withHeader(AUTHORIZATION, basicAuthHeader)).then(ok(), contentType(APPLICATION_JSON), bytesContent(tokenEndpointResponse.getBytes()));
    // Respond to request after user logged in with the temporary code
    Response searchResponse = given().cookie(JSESSIONID, initialResponseParams.get(JSESSIONID)).header(USER_AGENT, BROWSER_USER_AGENT).header(HOST, "localhost:" + HTTPS_PORT.getPort()).header("Origin", URL_START.toString()).param(CODE, TEMPORARY_CODE).param(STATE, initialResponseParams.get(STATE)).redirects().follow(false).expect().statusCode(200).when().post(initialResponseParams.get(REDIRECT_URI));
    // Verify that the stub server was hit
    List<Call> tokenEndpointCalls = server.getCalls().stream().filter(call -> call.getUrl().equals(URL_START + TOKEN_ENDPOINT_PATH)).collect(Collectors.toList());
    assertThat(tokenEndpointCalls.size(), is(1));
    // Verify that we're logged in as admin
    Map<String, Object> userInfoList = getUserInfo(initialResponseParams.get(JSESSIONID));
    assertThat(userInfoList.get("name"), is(ADMIN));
    logout(initialResponseParams.get(JSESSIONID));
}
Also used : Response(io.restassured.response.Response) KeyPair(java.security.KeyPair) Arrays(java.util.Arrays) StubServer(com.xebialabs.restito.server.StubServer) GET(javax.ws.rs.HttpMethod.GET) Enumeration(java.util.Enumeration) Date(java.util.Date) PREFERRED_USERNAME(org.pac4j.oidc.profile.OidcProfileDefinition.PREFERRED_USERNAME) HttpStatus(org.apache.http.HttpStatus) GsonBuilder(com.google.gson.GsonBuilder) Algorithm(com.auth0.jwt.algorithms.Algorithm) NONCE(org.pac4j.oidc.profile.OidcProfileDefinition.NONCE) RSAPublicKey(java.security.interfaces.RSAPublicKey) Gson(com.google.gson.Gson) Duration(java.time.Duration) Map(java.util.Map) Base64URL(com.nimbusds.jose.util.Base64URL) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest) URI(java.net.URI) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) KeyPairGenerator(java.security.KeyPairGenerator) Awaitility.await(org.awaitility.Awaitility.await) ImmutableMap(com.google.common.collect.ImmutableMap) JWTCreator(com.auth0.jwt.JWTCreator) RSAPrivateKey(java.security.interfaces.RSAPrivateKey) Condition.parameter(com.xebialabs.restito.semantics.Condition.parameter) UUID(java.util.UUID) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) JWK(com.nimbusds.jose.jwk.JWK) StandardCharsets(java.nio.charset.StandardCharsets) HOST(javax.ws.rs.core.HttpHeaders.HOST) PerSuite(org.ops4j.pax.exam.spi.reactors.PerSuite) List(java.util.List) JSONObject(org.json.simple.JSONObject) Action.bytesContent(com.xebialabs.restito.semantics.Action.bytesContent) KeyUse(com.nimbusds.jose.jwk.KeyUse) URLEncodedUtils(org.apache.http.client.utils.URLEncodedUtils) SECURE_ROOT(org.codice.ddf.itests.common.AbstractIntegrationTest.DynamicUrl.SECURE_ROOT) Action.ok(com.xebialabs.restito.semantics.Action.ok) RestAssured.given(io.restassured.RestAssured.given) Matchers.is(org.hamcrest.Matchers.is) Condition.withHeader(com.xebialabs.restito.semantics.Condition.withHeader) AfterExam(org.codice.ddf.test.common.annotations.AfterExam) NameValuePair(org.apache.http.NameValuePair) Dictionary(java.util.Dictionary) StubHttp.whenHttp(com.xebialabs.restito.builder.stub.StubHttp.whenHttp) PaxExam(org.ops4j.pax.exam.junit.PaxExam) JWT(com.auth0.jwt.JWT) Call(com.xebialabs.restito.semantics.Call) MessageDigest(java.security.MessageDigest) RunWith(org.junit.runner.RunWith) BeforeExam(org.codice.ddf.test.common.annotations.BeforeExam) AZP(org.pac4j.oidc.profile.OidcProfileDefinition.AZP) REFRESH_TOKEN(org.pac4j.oidc.profile.OidcProfileDefinition.REFRESH_TOKEN) LOCATION(javax.ws.rs.core.HttpHeaders.LOCATION) Condition.post(com.xebialabs.restito.semantics.Condition.post) ImmutableList(com.google.common.collect.ImmutableList) Configuration(org.osgi.service.cm.Configuration) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Condition.get(com.xebialabs.restito.semantics.Condition.get) AUTHORIZATION(javax.ws.rs.core.HttpHeaders.AUTHORIZATION) GsonTypeAdapters(org.codice.gsonsupport.GsonTypeAdapters) Hashtable(java.util.Hashtable) Before(org.junit.Before) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) PublicClaims(com.auth0.jwt.impl.PublicClaims) Assert.assertTrue(org.junit.Assert.assertTrue) AUTH_TIME(org.pac4j.oidc.profile.OidcProfileDefinition.AUTH_TIME) Test(org.junit.Test) USER_AGENT(javax.ws.rs.core.HttpHeaders.USER_AGENT) EMAIL_VERIFIED(org.pac4j.oidc.profile.OidcProfileDefinition.EMAIL_VERIFIED) TimeUnit(java.util.concurrent.TimeUnit) ExamReactorStrategy(org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy) RSAKey(com.nimbusds.jose.jwk.RSAKey) Response(io.restassured.response.Response) Action.contentType(com.xebialabs.restito.semantics.Action.contentType) ACCESS_TOKEN(org.pac4j.oidc.profile.OidcProfileDefinition.ACCESS_TOKEN) LoggingUtils(org.codice.ddf.test.common.LoggingUtils) Call(com.xebialabs.restito.semantics.Call) JSONObject(org.json.simple.JSONObject) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest) Test(org.junit.Test)

Example 22 with Scope

use of com.auth0.json.mgmt.Scope in project auth0-java by auth0.

the class OrganizationsEntity method deleteRoles.

/**
 * Delete roles from a member of an organization. A token with {@code delete:organization_member_roles} scope is required.
 *
 * @param orgId the ID of the organization
 * @param userId the ID of the user
 * @param roles the roles to delete
 * @return a Request to execute
 *
 * @see <a href="https://auth0.com/docs/api/management/v2#!/Organizations/delete_organization_member_roles">https://auth0.com/docs/api/management/v2#!/Organizations/delete_organization_member_roles</a>
 */
public Request<Void> deleteRoles(String orgId, String userId, Roles roles) {
    Asserts.assertNotNull(orgId, "organization ID");
    Asserts.assertNotNull(userId, "user ID");
    Asserts.assertNotNull(roles, "roles");
    String url = baseUrl.newBuilder().addPathSegments(ORGS_PATH).addPathSegment(orgId).addPathSegment("members").addPathSegment(userId).addPathSegment("roles").build().toString();
    VoidRequest request = new VoidRequest(client, url, "DELETE");
    request.addHeader(AUTHORIZATION_HEADER, "Bearer " + apiToken);
    request.setBody(roles);
    return request;
}
Also used : VoidRequest(com.auth0.net.VoidRequest)

Example 23 with Scope

use of com.auth0.json.mgmt.Scope in project auth0-java by auth0.

the class OrganizationsEntity method delete.

/**
 * Delete an organization. A token with {@code delete:organizations} scope is required.
 *
 * @param orgId the ID of the organization to delete
 * @return a Request to execute
 *
 * @see <a href="https://auth0.com/docs/api/management/v2#!/Organizations/delete_organizations_by_id">https://auth0.com/docs/api/management/v2#!/Organizations/delete_organizations_by_id</a>
 */
public Request<Void> delete(String orgId) {
    Asserts.assertNotNull(orgId, "organization ID");
    String url = baseUrl.newBuilder().addPathSegments(ORGS_PATH).addPathSegment(orgId).build().toString();
    VoidRequest voidRequest = new VoidRequest(client, url, "DELETE");
    voidRequest.addHeader(AUTHORIZATION_HEADER, "Bearer " + apiToken);
    return voidRequest;
}
Also used : VoidRequest(com.auth0.net.VoidRequest)

Example 24 with Scope

use of com.auth0.json.mgmt.Scope in project auth0-java by auth0.

the class OrganizationsEntity method addRoles.

/**
 * Add roles for a member of an organization. A token with {@code create:organization_member_roles} scope is required.
 *
 * @param orgId the ID of the organization
 * @param userId the ID of the user
 * @param roles the roles to add
 * @return a Request to execute
 *
 * @see <a href="https://auth0.com/docs/api/management/v2#!/Organizations/post_organization_member_roles">https://auth0.com/docs/api/management/v2#!/Organizations/post_organization_member_roles</a>
 */
public Request<Void> addRoles(String orgId, String userId, Roles roles) {
    Asserts.assertNotNull(orgId, "organization ID");
    Asserts.assertNotNull(userId, "user ID");
    Asserts.assertNotNull(roles, "roles");
    String url = baseUrl.newBuilder().addPathSegments(ORGS_PATH).addPathSegment(orgId).addPathSegment("members").addPathSegment(userId).addPathSegment("roles").build().toString();
    VoidRequest request = new VoidRequest(client, url, "POST");
    request.addHeader(AUTHORIZATION_HEADER, "Bearer " + apiToken);
    request.setBody(roles);
    return request;
}
Also used : VoidRequest(com.auth0.net.VoidRequest)

Example 25 with Scope

use of com.auth0.json.mgmt.Scope in project auth0-java by auth0.

the class RolesEntity method delete.

/**
 * Delete an existing Role.
 * A token with scope delete:roles is needed.
 * See https://auth0.com/docs/api/management/v2#!/Roles/delete_roles_by_id
 *
 * @param roleId The id of the role to delete.
 * @return a Request to execute.
 */
public Request<Void> delete(String roleId) {
    Asserts.assertNotNull(roleId, "role id");
    final String url = baseUrl.newBuilder().addEncodedPathSegments("api/v2/roles").addEncodedPathSegments(roleId).build().toString();
    VoidRequest request = new VoidRequest(this.client, url, "DELETE");
    request.addHeader("Authorization", "Bearer " + apiToken);
    return request;
}
Also used : VoidRequest(com.auth0.net.VoidRequest)

Aggregations

VoidRequest (com.auth0.net.VoidRequest)24 Test (org.junit.Test)4 AuthAPI (com.auth0.client.auth.AuthAPI)3 Date (java.util.Date)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 Test (org.junit.jupiter.api.Test)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 ClientGrant (com.auth0.json.mgmt.ClientGrant)2 JWT (com.auth0.jwt.JWT)2 JWTCreator (com.auth0.jwt.JWTCreator)2 Algorithm (com.auth0.jwt.algorithms.Algorithm)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 JSONObject (org.json.simple.JSONObject)2 ResourceServer (com.auth0.json.mgmt.ResourceServer)1 Scope (com.auth0.json.mgmt.Scope)1 JwkProvider (com.auth0.jwk.JwkProvider)1 JwkProviderBuilder (com.auth0.jwk.JwkProviderBuilder)1