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.common.lib.saml2;
20  
21  import com.fasterxml.jackson.annotation.JsonIgnore;
22  import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
23  import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
24  import java.io.Serializable;
25  import java.time.OffsetDateTime;
26  import java.util.Date;
27  import java.util.HashSet;
28  import java.util.Optional;
29  import java.util.Set;
30  import org.apache.syncope.common.lib.Attr;
31  
32  public class SAML2LoginResponse implements Serializable {
33  
34      private static final long serialVersionUID = 794772343787258010L;
35  
36      private String nameID;
37  
38      private String sessionIndex;
39  
40      private Date notOnOrAfter;
41  
42      private String accessToken;
43  
44      private OffsetDateTime accessTokenExpiryTime;
45  
46      private String username;
47  
48      private final Set<Attr> attrs = new HashSet<>();
49  
50      private String idp;
51  
52      private boolean sloSupported;
53  
54      private boolean selfReg;
55  
56      public String getNameID() {
57          return nameID;
58      }
59  
60      public void setNameID(final String nameID) {
61          this.nameID = nameID;
62      }
63  
64      public String getSessionIndex() {
65          return sessionIndex;
66      }
67  
68      public void setSessionIndex(final String sessionIndex) {
69          this.sessionIndex = sessionIndex;
70      }
71  
72      public Date getNotOnOrAfter() {
73          return Optional.ofNullable(notOnOrAfter).map(date -> new Date(date.getTime())).orElse(null);
74      }
75  
76      public void setNotOnOrAfter(final Date notOnOrAfter) {
77          this.notOnOrAfter = Optional.ofNullable(notOnOrAfter).
78                  map(date -> new Date(date.getTime())).orElse(null);
79      }
80  
81      public String getAccessToken() {
82          return accessToken;
83      }
84  
85      public void setAccessToken(final String accessToken) {
86          this.accessToken = accessToken;
87      }
88  
89      public OffsetDateTime getAccessTokenExpiryTime() {
90          return accessTokenExpiryTime;
91      }
92  
93      public void setAccessTokenExpiryTime(final OffsetDateTime accessTokenExpiryTime) {
94          this.accessTokenExpiryTime = accessTokenExpiryTime;
95      }
96  
97      public String getUsername() {
98          return username;
99      }
100 
101     public void setUsername(final String username) {
102         this.username = username;
103     }
104 
105     @JsonIgnore
106     public Optional<Attr> getAttr(final String schema) {
107         return attrs.stream().filter(attr -> attr.getSchema().equals(schema)).findFirst();
108     }
109 
110     @JacksonXmlElementWrapper(localName = "attrs")
111     @JacksonXmlProperty(localName = "attr")
112     public Set<Attr> getAttrs() {
113         return attrs;
114     }
115 
116     public String getIdp() {
117         return idp;
118     }
119 
120     public void setIdp(final String idp) {
121         this.idp = idp;
122     }
123 
124     public boolean isSloSupported() {
125         return sloSupported;
126     }
127 
128     public void setSloSupported(final boolean sloSupported) {
129         this.sloSupported = sloSupported;
130     }
131 
132     public boolean isSelfReg() {
133         return selfReg;
134     }
135 
136     public void setSelfReg(final boolean selfReg) {
137         this.selfReg = selfReg;
138     }
139 }