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.core.persistence.jpa.inner;
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.assertNull;
24  
25  import java.util.UUID;
26  import org.apache.syncope.common.lib.types.OIDCGrantType;
27  import org.apache.syncope.common.lib.types.OIDCResponseType;
28  import org.apache.syncope.common.lib.types.OIDCSubjectType;
29  import org.apache.syncope.core.persistence.api.dao.OIDCRPClientAppDAO;
30  import org.apache.syncope.core.persistence.api.entity.am.OIDCRPClientApp;
31  import org.apache.syncope.core.persistence.api.entity.policy.AccessPolicy;
32  import org.apache.syncope.core.persistence.api.entity.policy.AuthPolicy;
33  import org.junit.jupiter.api.Test;
34  import org.springframework.beans.factory.annotation.Autowired;
35  import org.springframework.transaction.annotation.Transactional;
36  
37  @Transactional("Master")
38  public class OIDCRPTest extends AbstractClientAppTest {
39  
40      @Autowired
41      private OIDCRPClientAppDAO oidcrpDAO;
42  
43      @Test
44      public void find() {
45          int beforeCount = oidcrpDAO.findAll().size();
46  
47          OIDCRPClientApp rp = entityFactory.newEntity(OIDCRPClientApp.class);
48          rp.setName("OIDC");
49          rp.setClientAppId(UUID.randomUUID().getMostSignificantBits() & Long.MAX_VALUE);
50          rp.setDescription("This is a sample OIDC RP");
51          rp.setClientId("clientid");
52          rp.setClientSecret("secret");
53          rp.setSubjectType(OIDCSubjectType.PUBLIC);
54          rp.getSupportedGrantTypes().add(OIDCGrantType.password);
55          rp.getSupportedResponseTypes().add(OIDCResponseType.CODE);
56  
57          AccessPolicy accessPolicy = buildAndSaveAccessPolicy();
58          rp.setAccessPolicy(accessPolicy);
59  
60          AuthPolicy authPolicy = buildAndSaveAuthPolicy();
61          rp.setAuthPolicy(authPolicy);
62  
63          oidcrpDAO.save(rp);
64  
65          assertNotNull(rp);
66          assertNotNull(rp.getKey());
67  
68          int afterCount = oidcrpDAO.findAll().size();
69          assertEquals(afterCount, beforeCount + 1);
70  
71          rp = oidcrpDAO.findByClientId("clientid");
72          assertNotNull(rp);
73          assertNotNull(rp.getAuthPolicy());
74  
75          rp = oidcrpDAO.findByName("OIDC");
76          assertNotNull(rp);
77  
78          rp = oidcrpDAO.findByClientAppId(rp.getClientAppId());
79          assertNotNull(rp);
80  
81          oidcrpDAO.deleteByClientId("clientid");
82          assertNull(oidcrpDAO.findByName("OIDC"));
83      }
84  }