View Javadoc
1   /*
2    * Copyright 2011 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5    * the License. You may obtain a copy of the License at
6    *
7    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10   * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11   * specific language governing permissions and limitations under the License.
12   */
13  package org.springframework.security.oauth2.http.converter.jaxb;
14  
15  import java.util.Date;
16  
17  import javax.xml.bind.annotation.XmlElement;
18  import javax.xml.bind.annotation.XmlRootElement;
19  import javax.xml.bind.annotation.XmlTransient;
20  
21  @XmlRootElement(name = "oauth")
22  class JaxbOAuth2AccessToken {
23  	private String accessToken;
24  
25  	private Long expiresIn;
26  
27  	private String refreshToken;
28  
29  	@XmlElement(name = "access_token")
30  	public String getAccessToken() {
31  		return accessToken;
32  	}
33  
34  	public void setAccessToken(String accessToken) {
35  		this.accessToken = accessToken;
36  	}
37  
38  	@XmlElement(name = "expires_in")
39  	public Long getExpiresIn() {
40  		return expiresIn;
41  	}
42  
43  	public void setExpiresIn(Long expiresIn) {
44  		this.expiresIn = expiresIn;
45  	}
46  
47  	public void setExpriation(Date expiration) {
48  		if(expiration == null) {
49  			setExpiresIn(null);
50  			return;
51  		}
52  		long now = System.currentTimeMillis();
53  		setExpiresIn((expiration.getTime() - now) / 1000);
54  	}
55  
56  	@XmlTransient
57  	public Date getExpiration() {
58  		if(expiresIn == null) {
59  			return null;
60  		}
61  		long now = System.currentTimeMillis();
62  		return new Date(now + (expiresIn * 1000));
63  	}
64  
65  	@XmlElement(name = "refresh_token")
66  	public String getRefreshToken() {
67  		return refreshToken;
68  	}
69  
70  	public void setRefreshToken(String refreshToken) {
71  		this.refreshToken = refreshToken;
72  	}
73  
74  }