View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.fit.sra;
20  
21  import static org.junit.jupiter.api.Assertions.assertEquals;
22  import static org.junit.jupiter.api.Assertions.assertNotNull;
23  import static org.junit.jupiter.api.Assertions.fail;
24  import static org.junit.jupiter.api.Assumptions.assumeTrue;
25  
26  import java.io.IOException;
27  import java.io.InputStream;
28  import java.lang.invoke.MethodHandles;
29  import java.util.Properties;
30  import java.util.concurrent.TimeoutException;
31  import org.apache.http.HttpStatus;
32  import org.apache.http.client.methods.CloseableHttpResponse;
33  import org.junit.jupiter.api.BeforeAll;
34  
35  public class OAUTH2SRAITCase extends OIDCSRAITCase {
36  
37      @BeforeAll
38      public static void startSRA() throws IOException, InterruptedException, TimeoutException {
39          assumeTrue(OAUTH2SRAITCase.class.equals(MethodHandles.lookup().lookupClass()));
40  
41          doStartSRA("oauth2");
42      }
43  
44      @BeforeAll
45      public static void clientAppSetup() {
46          assumeTrue(OAUTH2SRAITCase.class.equals(MethodHandles.lookup().lookupClass()));
47  
48          Properties props = new Properties();
49          try (InputStream propStream = OAUTH2SRAITCase.class.getResourceAsStream("/sra-oauth2.properties")) {
50              props.load(propStream);
51          } catch (Exception e) {
52              fail("Could not load /sra-oauth2.properties", e);
53          }
54          SRA_REGISTRATION_ID = "OAUTH2";
55          CLIENT_APP_ID = 2L;
56          CLIENT_ID = props.getProperty("sra.oauth2.client-id");
57          assertNotNull(CLIENT_ID);
58          CLIENT_SECRET = props.getProperty("sra.oauth2.client-secret");
59          assertNotNull(CLIENT_SECRET);
60          TOKEN_URI = props.getProperty("sra.oauth2.tokenUri");
61          assertNotNull(TOKEN_URI);
62  
63          oidcClientAppSetup(
64                  OAUTH2SRAITCase.class.getName(), SRA_REGISTRATION_ID, CLIENT_APP_ID, CLIENT_ID, CLIENT_SECRET);
65      }
66  
67      @Override
68      protected void checkLogout(final CloseableHttpResponse response) {
69          assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatusLine().getStatusCode());
70      }
71  
72      @Override
73      protected boolean checkIdToken() {
74          return false;
75      }
76  }