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.core.wa;
20  
21  import static org.junit.jupiter.api.Assertions.assertEquals;
22  import static org.junit.jupiter.api.Assertions.assertFalse;
23  import static org.junit.jupiter.api.Assertions.assertNotNull;
24  import static org.junit.jupiter.api.Assertions.assertTrue;
25  import static org.junit.jupiter.api.Assumptions.assumeTrue;
26  
27  import java.util.List;
28  import org.apache.syncope.client.lib.SyncopeClientFactoryBean;
29  import org.apache.syncope.common.lib.policy.AccessPolicyTO;
30  import org.apache.syncope.common.lib.policy.AttrReleasePolicyTO;
31  import org.apache.syncope.common.lib.policy.AuthPolicyTO;
32  import org.apache.syncope.common.lib.policy.DefaultAttrReleasePolicyConf;
33  import org.apache.syncope.common.lib.policy.DefaultTicketExpirationPolicyConf;
34  import org.apache.syncope.common.lib.policy.TicketExpirationPolicyTO;
35  import org.apache.syncope.common.lib.to.OIDCRPClientAppTO;
36  import org.apache.syncope.common.lib.to.SAML2SPClientAppTO;
37  import org.apache.syncope.common.lib.types.ClientAppType;
38  import org.apache.syncope.common.lib.types.PolicyType;
39  import org.apache.syncope.common.lib.wa.WAClientApp;
40  import org.apache.syncope.common.rest.api.service.wa.WAClientAppService;
41  import org.apache.syncope.fit.AbstractITCase;
42  import org.junit.jupiter.api.BeforeAll;
43  import org.junit.jupiter.api.Test;
44  
45  public class WAClientAppITCase extends AbstractITCase {
46  
47      private static final String AUTH_MODULE = "DefaultJDBCAuthModule";
48  
49      private static WAClientAppService WA_CLIENT_APP_SERVICE;
50  
51      @BeforeAll
52      public static void setup() {
53          assumeTrue(CLIENT_FACTORY.getContentType() == SyncopeClientFactoryBean.ContentType.JSON);
54  
55          WA_CLIENT_APP_SERVICE = ANONYMOUS_CLIENT.getService(WAClientAppService.class);
56      }
57  
58      @Test
59      public void list() {
60          createClientApp(ClientAppType.OIDCRP, buildOIDCRP());
61  
62          List<WAClientApp> list = WA_CLIENT_APP_SERVICE.list();
63          assertFalse(list.isEmpty());
64      }
65  
66      @Test
67      public void read() {
68          OIDCRPClientAppTO oidcrpto = createClientApp(ClientAppType.OIDCRP, buildOIDCRP());
69          WAClientApp waClientApp = WA_CLIENT_APP_SERVICE.read(oidcrpto.getClientAppId(), null);
70          assertNotNull(waClientApp);
71  
72          waClientApp = WA_CLIENT_APP_SERVICE.read(oidcrpto.getClientAppId(), ClientAppType.OIDCRP);
73          assertNotNull(waClientApp);
74  
75          waClientApp = WA_CLIENT_APP_SERVICE.read(oidcrpto.getName(), null);
76          assertNotNull(waClientApp);
77  
78          waClientApp = WA_CLIENT_APP_SERVICE.read(oidcrpto.getName(), ClientAppType.OIDCRP);
79          assertNotNull(waClientApp);
80  
81          SAML2SPClientAppTO samlspto = createClientApp(ClientAppType.SAML2SP, buildSAML2SP());
82          WAClientApp registeredSamlClientApp = WA_CLIENT_APP_SERVICE.read(samlspto.getClientAppId(), null);
83          assertNotNull(registeredSamlClientApp);
84  
85          registeredSamlClientApp = WA_CLIENT_APP_SERVICE.read(samlspto.getClientAppId(), ClientAppType.SAML2SP);
86          assertNotNull(registeredSamlClientApp);
87  
88          registeredSamlClientApp = WA_CLIENT_APP_SERVICE.read(samlspto.getName(), null);
89          assertNotNull(registeredSamlClientApp);
90  
91          registeredSamlClientApp = WA_CLIENT_APP_SERVICE.read(samlspto.getName(), ClientAppType.SAML2SP);
92          assertNotNull(registeredSamlClientApp);
93      }
94  
95      @Test
96      public void readWithPolicies() {
97          OIDCRPClientAppTO oidcrpto = buildOIDCRP();
98  
99          AuthPolicyTO authPolicyTO = createPolicy(PolicyType.AUTH, buildAuthPolicyTO(AUTH_MODULE));
100 
101         AccessPolicyTO accessPolicyTO = createPolicy(PolicyType.ACCESS, buildAccessPolicyTO());
102 
103         AttrReleasePolicyTO attrReleasePolicyTO = createPolicy(PolicyType.ATTR_RELEASE, buildAttrReleasePolicyTO());
104 
105         TicketExpirationPolicyTO ticketExpirationPolicyTO =
106                 createPolicy(PolicyType.TICKET_EXPIRATION, buildTicketExpirationPolicyTO());
107 
108         oidcrpto.setAuthPolicy(authPolicyTO.getKey());
109         oidcrpto.setAccessPolicy(accessPolicyTO.getKey());
110         oidcrpto.setAttrReleasePolicy(attrReleasePolicyTO.getKey());
111         oidcrpto.setTicketExpirationPolicy(ticketExpirationPolicyTO.getKey());
112 
113         oidcrpto = createClientApp(ClientAppType.OIDCRP, oidcrpto);
114 
115         WAClientApp waClientApp = WA_CLIENT_APP_SERVICE.read(oidcrpto.getClientAppId(), null);
116         assertNotNull(waClientApp);
117         assertTrue(waClientApp.getAttrReleasePolicy().getConf() instanceof DefaultAttrReleasePolicyConf);
118         assertTrue(waClientApp.getTicketExpirationPolicy().getConf() instanceof DefaultTicketExpirationPolicyConf);
119 
120         DefaultAttrReleasePolicyConf attrReleasePolicyConf =
121                 (DefaultAttrReleasePolicyConf) waClientApp.getAttrReleasePolicy().getConf();
122         assertFalse(attrReleasePolicyConf.getReleaseAttrs().isEmpty());
123         assertEquals("username", attrReleasePolicyConf.getReleaseAttrs().get("uid"));
124         assertEquals("fullname", attrReleasePolicyConf.getReleaseAttrs().get("cn"));
125 
126         DefaultTicketExpirationPolicyConf ticketExpirationPolicyConf =
127                 (DefaultTicketExpirationPolicyConf) waClientApp.getTicketExpirationPolicy().getConf();
128         assertEquals(110, ticketExpirationPolicyConf.getTgtConf().getMaxTimeToLiveInSeconds());
129     }
130 }