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.entity;
20  
21  import java.net.URI;
22  import java.util.List;
23  import java.util.Optional;
24  import javax.persistence.Column;
25  import javax.persistence.Entity;
26  import javax.persistence.EnumType;
27  import javax.persistence.Enumerated;
28  import javax.persistence.Lob;
29  import javax.persistence.Table;
30  import javax.validation.constraints.NotNull;
31  import org.apache.commons.lang3.BooleanUtils;
32  import org.apache.syncope.common.lib.types.SRARouteFilter;
33  import org.apache.syncope.common.lib.types.SRARoutePredicate;
34  import org.apache.syncope.common.lib.types.SRARouteType;
35  import org.apache.syncope.core.persistence.api.entity.SRARoute;
36  import org.apache.syncope.core.persistence.jpa.validation.entity.SRARouteCheck;
37  import org.apache.syncope.core.provisioning.api.serialization.POJOHelper;
38  
39  @Entity
40  @Table(name = JPASRARoute.TABLE)
41  @SRARouteCheck
42  public class JPASRARoute extends AbstractGeneratedKeyEntity implements SRARoute {
43  
44      private static final long serialVersionUID = -8718852361106840530L;
45  
46      public static final String TABLE = "SRARoute";
47  
48      @Column(unique = true, nullable = false)
49      private String name;
50  
51      @NotNull
52      private String target;
53  
54      private String error;
55  
56      @NotNull
57      @Enumerated(EnumType.STRING)
58      private SRARouteType routeType;
59  
60      @NotNull
61      private Boolean logout = false;
62  
63      private String postLogout;
64  
65      @NotNull
66      private Boolean csrf = true;
67  
68      private Integer routeOrder;
69  
70      @Lob
71      private String predicates;
72  
73      @Lob
74      private String filters;
75  
76      @Override
77      public String getName() {
78          return name;
79      }
80  
81      @Override
82      public void setName(final String name) {
83          this.name = name;
84      }
85  
86      @Override
87      public URI getTarget() {
88          return Optional.ofNullable(target).map(URI::create).orElse(null);
89      }
90  
91      @Override
92      public void setTarget(final URI target) {
93          this.target = Optional.ofNullable(target).map(URI::toASCIIString).orElse(null);
94      }
95  
96      @Override
97      public URI getError() {
98          return Optional.ofNullable(error).map(URI::create).orElse(null);
99      }
100 
101     @Override
102     public void setError(final URI error) {
103         this.error = Optional.ofNullable(error).map(URI::toASCIIString).orElse(null);
104     }
105 
106     @Override
107     public SRARouteType getType() {
108         return routeType;
109     }
110 
111     @Override
112     public void setType(final SRARouteType type) {
113         this.routeType = type;
114     }
115 
116     @Override
117     public boolean isLogout() {
118         return BooleanUtils.isNotFalse(logout);
119     }
120 
121     @Override
122     public void setLogout(final boolean logout) {
123         this.logout = logout;
124     }
125 
126     @Override
127     public URI getPostLogout() {
128         return Optional.ofNullable(postLogout).map(URI::create).orElse(null);
129     }
130 
131     @Override
132     public void setPostLogout(final URI postLogout) {
133         this.postLogout = Optional.ofNullable(postLogout).map(URI::toASCIIString).orElse(null);
134     }
135 
136     @Override
137     public boolean isCsrf() {
138         return csrf;
139     }
140 
141     @Override
142     public void setCsrf(final boolean csrf) {
143         this.csrf = csrf;
144     }
145 
146     @Override
147     public int getOrder() {
148         return Optional.ofNullable(routeOrder).orElse(0);
149     }
150 
151     @Override
152     public void setOrder(final int order) {
153         this.routeOrder = order;
154     }
155 
156     @Override
157     public List<SRARouteFilter> getFilters() {
158         return filters == null
159                 ? List.of()
160                 : List.of(POJOHelper.deserialize(filters, SRARouteFilter[].class));
161     }
162 
163     @Override
164     public void setFilters(final List<SRARouteFilter> filters) {
165         this.filters = POJOHelper.serialize(filters);
166     }
167 
168     @Override
169     public List<SRARoutePredicate> getPredicates() {
170         return predicates == null
171                 ? List.of()
172                 : List.of(POJOHelper.deserialize(predicates, SRARoutePredicate[].class));
173     }
174 
175     @Override
176     public void setPredicates(final List<SRARoutePredicate> predicates) {
177         this.predicates = POJOHelper.serialize(predicates);
178     }
179 }