removed DateUtil
parent
0dc7cb05e7
commit
db2574ab53
|
@ -0,0 +1,37 @@
|
||||||
|
package org.mitre.openid.connect.service.impl;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat.ISO;
|
||||||
|
import org.springframework.format.datetime.DateFormatter;
|
||||||
|
|
||||||
|
public abstract class MITREidDataServiceSupport {
|
||||||
|
private final DateFormatter dateFormatter;
|
||||||
|
private final static Logger logger = LoggerFactory.getLogger(MITREidDataService_1_2.class);
|
||||||
|
|
||||||
|
public MITREidDataServiceSupport() {
|
||||||
|
dateFormatter = new DateFormatter();
|
||||||
|
dateFormatter.setIso(ISO.DATE_TIME);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Date utcToDate(String value) {
|
||||||
|
try {
|
||||||
|
return dateFormatter.parse(value, Locale.ENGLISH);
|
||||||
|
} catch (ParseException ex) {
|
||||||
|
logger.error("Unable to parse datetime {}", value, ex);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String toUTCString(Date value) {
|
||||||
|
if (value == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return dateFormatter.print(value, Locale.ENGLISH);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -52,7 +52,6 @@ import org.mitre.openid.connect.repository.ApprovedSiteRepository;
|
||||||
import org.mitre.openid.connect.repository.BlacklistedSiteRepository;
|
import org.mitre.openid.connect.repository.BlacklistedSiteRepository;
|
||||||
import org.mitre.openid.connect.repository.WhitelistedSiteRepository;
|
import org.mitre.openid.connect.repository.WhitelistedSiteRepository;
|
||||||
import org.mitre.openid.connect.service.MITREidDataService;
|
import org.mitre.openid.connect.service.MITREidDataService;
|
||||||
import org.mitre.openid.connect.util.DateUtil;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -76,7 +75,7 @@ import com.google.gson.stream.JsonWriter;
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@SuppressWarnings(value = {"unchecked"})
|
@SuppressWarnings(value = {"unchecked"})
|
||||||
public class MITREidDataService_1_0 implements MITREidDataService {
|
public class MITREidDataService_1_0 extends MITREidDataServiceSupport implements MITREidDataService {
|
||||||
|
|
||||||
private final static Logger logger = LoggerFactory.getLogger(MITREidDataService_1_0.class);
|
private final static Logger logger = LoggerFactory.getLogger(MITREidDataService_1_0.class);
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -93,6 +92,7 @@ public class MITREidDataService_1_0 implements MITREidDataService {
|
||||||
private OAuth2TokenRepository tokenRepository;
|
private OAuth2TokenRepository tokenRepository;
|
||||||
@Autowired
|
@Autowired
|
||||||
private SystemScopeRepository sysScopeRepository;
|
private SystemScopeRepository sysScopeRepository;
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.mitre.openid.connect.service.MITREidDataService#export(com.google.gson.stream.JsonWriter)
|
* @see org.mitre.openid.connect.service.MITREidDataService#export(com.google.gson.stream.JsonWriter)
|
||||||
*/
|
*/
|
||||||
|
@ -179,7 +179,7 @@ public class MITREidDataService_1_0 implements MITREidDataService {
|
||||||
} else if (name.equals("id")) {
|
} else if (name.equals("id")) {
|
||||||
currentId = reader.nextLong();
|
currentId = reader.nextLong();
|
||||||
} else if (name.equals("expiration")) {
|
} else if (name.equals("expiration")) {
|
||||||
Date date = DateUtil.utcToDate(reader.nextString());
|
Date date = utcToDate(reader.nextString());
|
||||||
token.setExpiration(date);
|
token.setExpiration(date);
|
||||||
} else if (name.equals("value")) {
|
} else if (name.equals("value")) {
|
||||||
String value = reader.nextString();
|
String value = reader.nextString();
|
||||||
|
@ -248,7 +248,7 @@ public class MITREidDataService_1_0 implements MITREidDataService {
|
||||||
} else if (name.equals("id")) {
|
} else if (name.equals("id")) {
|
||||||
currentId = reader.nextLong();
|
currentId = reader.nextLong();
|
||||||
} else if (name.equals("expiration")) {
|
} else if (name.equals("expiration")) {
|
||||||
Date date = DateUtil.utcToDate(reader.nextString());
|
Date date = utcToDate(reader.nextString());
|
||||||
token.setExpiration(date);
|
token.setExpiration(date);
|
||||||
} else if (name.equals("value")) {
|
} else if (name.equals("value")) {
|
||||||
String value = reader.nextString();
|
String value = reader.nextString();
|
||||||
|
@ -461,15 +461,15 @@ public class MITREidDataService_1_0 implements MITREidDataService {
|
||||||
} else if (name.equals("id")) {
|
} else if (name.equals("id")) {
|
||||||
currentId = reader.nextLong();
|
currentId = reader.nextLong();
|
||||||
} else if (name.equals("accessDate")) {
|
} else if (name.equals("accessDate")) {
|
||||||
Date date = DateUtil.utcToDate(reader.nextString());
|
Date date = utcToDate(reader.nextString());
|
||||||
site.setAccessDate(date);
|
site.setAccessDate(date);
|
||||||
} else if (name.equals("clientId")) {
|
} else if (name.equals("clientId")) {
|
||||||
site.setClientId(reader.nextString());
|
site.setClientId(reader.nextString());
|
||||||
} else if (name.equals("creationDate")) {
|
} else if (name.equals("creationDate")) {
|
||||||
Date date = DateUtil.utcToDate(reader.nextString());
|
Date date = utcToDate(reader.nextString());
|
||||||
site.setCreationDate(date);
|
site.setCreationDate(date);
|
||||||
} else if (name.equals("timeoutDate")) {
|
} else if (name.equals("timeoutDate")) {
|
||||||
Date date = DateUtil.utcToDate(reader.nextString());
|
Date date = utcToDate(reader.nextString());
|
||||||
site.setTimeoutDate(date);
|
site.setTimeoutDate(date);
|
||||||
} else if (name.equals("userId")) {
|
} else if (name.equals("userId")) {
|
||||||
site.setUserId(reader.nextString());
|
site.setUserId(reader.nextString());
|
||||||
|
@ -848,4 +848,5 @@ public class MITREidDataService_1_0 implements MITREidDataService {
|
||||||
accessTokenOldToNewIdMap.clear();
|
accessTokenOldToNewIdMap.clear();
|
||||||
grantOldToNewIdMap.clear();
|
grantOldToNewIdMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,6 @@ import org.mitre.openid.connect.repository.ApprovedSiteRepository;
|
||||||
import org.mitre.openid.connect.repository.BlacklistedSiteRepository;
|
import org.mitre.openid.connect.repository.BlacklistedSiteRepository;
|
||||||
import org.mitre.openid.connect.repository.WhitelistedSiteRepository;
|
import org.mitre.openid.connect.repository.WhitelistedSiteRepository;
|
||||||
import org.mitre.openid.connect.service.MITREidDataService;
|
import org.mitre.openid.connect.service.MITREidDataService;
|
||||||
import org.mitre.openid.connect.util.DateUtil;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -79,7 +78,7 @@ import com.google.gson.stream.JsonWriter;
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@SuppressWarnings(value = {"unchecked"})
|
@SuppressWarnings(value = {"unchecked"})
|
||||||
public class MITREidDataService_1_1 implements MITREidDataService {
|
public class MITREidDataService_1_1 extends MITREidDataServiceSupport implements MITREidDataService {
|
||||||
|
|
||||||
private final static Logger logger = LoggerFactory.getLogger(MITREidDataService_1_1.class);
|
private final static Logger logger = LoggerFactory.getLogger(MITREidDataService_1_1.class);
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -97,7 +96,6 @@ public class MITREidDataService_1_1 implements MITREidDataService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private SystemScopeRepository sysScopeRepository;
|
private SystemScopeRepository sysScopeRepository;
|
||||||
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.mitre.openid.connect.service.MITREidDataService#export(com.google.gson.stream.JsonWriter)
|
* @see org.mitre.openid.connect.service.MITREidDataService#export(com.google.gson.stream.JsonWriter)
|
||||||
*/
|
*/
|
||||||
|
@ -183,7 +181,7 @@ public class MITREidDataService_1_1 implements MITREidDataService {
|
||||||
} else if (name.equals("id")) {
|
} else if (name.equals("id")) {
|
||||||
currentId = reader.nextLong();
|
currentId = reader.nextLong();
|
||||||
} else if (name.equals("expiration")) {
|
} else if (name.equals("expiration")) {
|
||||||
Date date = DateUtil.utcToDate(reader.nextString());
|
Date date = utcToDate(reader.nextString());
|
||||||
token.setExpiration(date);
|
token.setExpiration(date);
|
||||||
} else if (name.equals("value")) {
|
} else if (name.equals("value")) {
|
||||||
String value = reader.nextString();
|
String value = reader.nextString();
|
||||||
|
@ -252,7 +250,7 @@ public class MITREidDataService_1_1 implements MITREidDataService {
|
||||||
} else if (name.equals("id")) {
|
} else if (name.equals("id")) {
|
||||||
currentId = reader.nextLong();
|
currentId = reader.nextLong();
|
||||||
} else if (name.equals("expiration")) {
|
} else if (name.equals("expiration")) {
|
||||||
Date date = DateUtil.utcToDate(reader.nextString());
|
Date date = utcToDate(reader.nextString());
|
||||||
token.setExpiration(date);
|
token.setExpiration(date);
|
||||||
} else if (name.equals("value")) {
|
} else if (name.equals("value")) {
|
||||||
String value = reader.nextString();
|
String value = reader.nextString();
|
||||||
|
@ -471,15 +469,15 @@ public class MITREidDataService_1_1 implements MITREidDataService {
|
||||||
} else if (name.equals("id")) {
|
} else if (name.equals("id")) {
|
||||||
currentId = reader.nextLong();
|
currentId = reader.nextLong();
|
||||||
} else if (name.equals("accessDate")) {
|
} else if (name.equals("accessDate")) {
|
||||||
Date date = DateUtil.utcToDate(reader.nextString());
|
Date date = utcToDate(reader.nextString());
|
||||||
site.setAccessDate(date);
|
site.setAccessDate(date);
|
||||||
} else if (name.equals("clientId")) {
|
} else if (name.equals("clientId")) {
|
||||||
site.setClientId(reader.nextString());
|
site.setClientId(reader.nextString());
|
||||||
} else if (name.equals("creationDate")) {
|
} else if (name.equals("creationDate")) {
|
||||||
Date date = DateUtil.utcToDate(reader.nextString());
|
Date date = utcToDate(reader.nextString());
|
||||||
site.setCreationDate(date);
|
site.setCreationDate(date);
|
||||||
} else if (name.equals("timeoutDate")) {
|
} else if (name.equals("timeoutDate")) {
|
||||||
Date date = DateUtil.utcToDate(reader.nextString());
|
Date date = utcToDate(reader.nextString());
|
||||||
site.setTimeoutDate(date);
|
site.setTimeoutDate(date);
|
||||||
} else if (name.equals("userId")) {
|
} else if (name.equals("userId")) {
|
||||||
site.setUserId(reader.nextString());
|
site.setUserId(reader.nextString());
|
||||||
|
@ -861,4 +859,5 @@ public class MITREidDataService_1_1 implements MITREidDataService {
|
||||||
accessTokenOldToNewIdMap.clear();
|
accessTokenOldToNewIdMap.clear();
|
||||||
grantOldToNewIdMap.clear();
|
grantOldToNewIdMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,6 @@ import org.mitre.openid.connect.repository.ApprovedSiteRepository;
|
||||||
import org.mitre.openid.connect.repository.BlacklistedSiteRepository;
|
import org.mitre.openid.connect.repository.BlacklistedSiteRepository;
|
||||||
import org.mitre.openid.connect.repository.WhitelistedSiteRepository;
|
import org.mitre.openid.connect.repository.WhitelistedSiteRepository;
|
||||||
import org.mitre.openid.connect.service.MITREidDataService;
|
import org.mitre.openid.connect.service.MITREidDataService;
|
||||||
import org.mitre.openid.connect.util.DateUtil;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -81,7 +80,7 @@ import com.google.gson.stream.JsonWriter;
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@SuppressWarnings(value = {"unchecked"})
|
@SuppressWarnings(value = {"unchecked"})
|
||||||
public class MITREidDataService_1_2 implements MITREidDataService {
|
public class MITREidDataService_1_2 extends MITREidDataServiceSupport implements MITREidDataService {
|
||||||
|
|
||||||
private final static Logger logger = LoggerFactory.getLogger(MITREidDataService_1_2.class);
|
private final static Logger logger = LoggerFactory.getLogger(MITREidDataService_1_2.class);
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -99,7 +98,6 @@ public class MITREidDataService_1_2 implements MITREidDataService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private SystemScopeRepository sysScopeRepository;
|
private SystemScopeRepository sysScopeRepository;
|
||||||
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.mitre.openid.connect.service.MITREidDataService#export(com.google.gson.stream.JsonWriter)
|
* @see org.mitre.openid.connect.service.MITREidDataService#export(com.google.gson.stream.JsonWriter)
|
||||||
*/
|
*/
|
||||||
|
@ -162,7 +160,7 @@ public class MITREidDataService_1_2 implements MITREidDataService {
|
||||||
for (OAuth2RefreshTokenEntity token : tokenRepository.getAllRefreshTokens()) {
|
for (OAuth2RefreshTokenEntity token : tokenRepository.getAllRefreshTokens()) {
|
||||||
writer.beginObject();
|
writer.beginObject();
|
||||||
writer.name("id").value(token.getId());
|
writer.name("id").value(token.getId());
|
||||||
writer.name("expiration").value(DateUtil.toUTCString(token.getExpiration()));
|
writer.name("expiration").value(toUTCString(token.getExpiration()));
|
||||||
writer.name("clientId")
|
writer.name("clientId")
|
||||||
.value((token.getClient() != null) ? token.getClient().getClientId() : null);
|
.value((token.getClient() != null) ? token.getClient().getClientId() : null);
|
||||||
writer.name("authenticationHolderId")
|
writer.name("authenticationHolderId")
|
||||||
|
@ -181,7 +179,7 @@ public class MITREidDataService_1_2 implements MITREidDataService {
|
||||||
for (OAuth2AccessTokenEntity token : tokenRepository.getAllAccessTokens()) {
|
for (OAuth2AccessTokenEntity token : tokenRepository.getAllAccessTokens()) {
|
||||||
writer.beginObject();
|
writer.beginObject();
|
||||||
writer.name("id").value(token.getId());
|
writer.name("id").value(token.getId());
|
||||||
writer.name("expiration").value(DateUtil.toUTCString(token.getExpiration()));
|
writer.name("expiration").value(toUTCString(token.getExpiration()));
|
||||||
writer.name("clientId")
|
writer.name("clientId")
|
||||||
.value((token.getClient() != null) ? token.getClient().getClientId() : null);
|
.value((token.getClient() != null) ? token.getClient().getClientId() : null);
|
||||||
writer.name("authenticationHolderId")
|
writer.name("authenticationHolderId")
|
||||||
|
@ -280,10 +278,10 @@ public class MITREidDataService_1_2 implements MITREidDataService {
|
||||||
for (ApprovedSite site : approvedSiteRepository.getAll()) {
|
for (ApprovedSite site : approvedSiteRepository.getAll()) {
|
||||||
writer.beginObject();
|
writer.beginObject();
|
||||||
writer.name("id").value(site.getId());
|
writer.name("id").value(site.getId());
|
||||||
writer.name("accessDate").value(DateUtil.toUTCString(site.getAccessDate()));
|
writer.name("accessDate").value(toUTCString(site.getAccessDate()));
|
||||||
writer.name("clientId").value(site.getClientId());
|
writer.name("clientId").value(site.getClientId());
|
||||||
writer.name("creationDate").value(DateUtil.toUTCString(site.getCreationDate()));
|
writer.name("creationDate").value(toUTCString(site.getCreationDate()));
|
||||||
writer.name("timeoutDate").value(DateUtil.toUTCString(site.getTimeoutDate()));
|
writer.name("timeoutDate").value(toUTCString(site.getTimeoutDate()));
|
||||||
writer.name("userId").value(site.getUserId());
|
writer.name("userId").value(site.getUserId());
|
||||||
writer.name("allowedScopes");
|
writer.name("allowedScopes");
|
||||||
writeNullSafeArray(writer, site.getAllowedScopes());
|
writeNullSafeArray(writer, site.getAllowedScopes());
|
||||||
|
@ -523,7 +521,7 @@ public class MITREidDataService_1_2 implements MITREidDataService {
|
||||||
} else if (name.equals("id")) {
|
} else if (name.equals("id")) {
|
||||||
currentId = reader.nextLong();
|
currentId = reader.nextLong();
|
||||||
} else if (name.equals("expiration")) {
|
} else if (name.equals("expiration")) {
|
||||||
Date date = DateUtil.utcToDate(reader.nextString());
|
Date date = utcToDate(reader.nextString());
|
||||||
token.setExpiration(date);
|
token.setExpiration(date);
|
||||||
} else if (name.equals("value")) {
|
} else if (name.equals("value")) {
|
||||||
String value = reader.nextString();
|
String value = reader.nextString();
|
||||||
|
@ -592,7 +590,7 @@ public class MITREidDataService_1_2 implements MITREidDataService {
|
||||||
} else if (name.equals("id")) {
|
} else if (name.equals("id")) {
|
||||||
currentId = reader.nextLong();
|
currentId = reader.nextLong();
|
||||||
} else if (name.equals("expiration")) {
|
} else if (name.equals("expiration")) {
|
||||||
Date date = DateUtil.utcToDate(reader.nextString());
|
Date date = utcToDate(reader.nextString());
|
||||||
token.setExpiration(date);
|
token.setExpiration(date);
|
||||||
} else if (name.equals("value")) {
|
} else if (name.equals("value")) {
|
||||||
String value = reader.nextString();
|
String value = reader.nextString();
|
||||||
|
@ -811,15 +809,15 @@ public class MITREidDataService_1_2 implements MITREidDataService {
|
||||||
} else if (name.equals("id")) {
|
} else if (name.equals("id")) {
|
||||||
currentId = reader.nextLong();
|
currentId = reader.nextLong();
|
||||||
} else if (name.equals("accessDate")) {
|
} else if (name.equals("accessDate")) {
|
||||||
Date date = DateUtil.utcToDate(reader.nextString());
|
Date date = utcToDate(reader.nextString());
|
||||||
site.setAccessDate(date);
|
site.setAccessDate(date);
|
||||||
} else if (name.equals("clientId")) {
|
} else if (name.equals("clientId")) {
|
||||||
site.setClientId(reader.nextString());
|
site.setClientId(reader.nextString());
|
||||||
} else if (name.equals("creationDate")) {
|
} else if (name.equals("creationDate")) {
|
||||||
Date date = DateUtil.utcToDate(reader.nextString());
|
Date date = utcToDate(reader.nextString());
|
||||||
site.setCreationDate(date);
|
site.setCreationDate(date);
|
||||||
} else if (name.equals("timeoutDate")) {
|
} else if (name.equals("timeoutDate")) {
|
||||||
Date date = DateUtil.utcToDate(reader.nextString());
|
Date date = utcToDate(reader.nextString());
|
||||||
site.setTimeoutDate(date);
|
site.setTimeoutDate(date);
|
||||||
} else if (name.equals("userId")) {
|
} else if (name.equals("userId")) {
|
||||||
site.setUserId(reader.nextString());
|
site.setUserId(reader.nextString());
|
||||||
|
@ -1200,4 +1198,5 @@ public class MITREidDataService_1_2 implements MITREidDataService {
|
||||||
accessTokenOldToNewIdMap.clear();
|
accessTokenOldToNewIdMap.clear();
|
||||||
grantOldToNewIdMap.clear();
|
grantOldToNewIdMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,57 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright 2015 The MITRE Corporation
|
|
||||||
* and the MIT Kerberos and Internet Trust Consortium
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.mitre.openid.connect.util;
|
|
||||||
|
|
||||||
import java.text.ParseException;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author arielak
|
|
||||||
*/
|
|
||||||
public class DateUtil {
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(DateUtil.class);
|
|
||||||
private static final String ISO_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
|
|
||||||
private static final SimpleDateFormat sdf = new SimpleDateFormat(ISO_FORMAT);
|
|
||||||
private static final TimeZone utc = TimeZone.getTimeZone("UTC");
|
|
||||||
|
|
||||||
public static String toUTCString(Date date) {
|
|
||||||
if (date == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
sdf.setTimeZone(utc);
|
|
||||||
return sdf.format(date);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Date utcToDate(String s) {
|
|
||||||
if (s == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Date d = null;
|
|
||||||
try {
|
|
||||||
d = sdf.parse(s);
|
|
||||||
} catch(ParseException ex) {
|
|
||||||
log.error("Unable to parse date string {}", s, ex);
|
|
||||||
}
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -40,6 +40,7 @@ import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -61,7 +62,6 @@ import org.mitre.openid.connect.repository.ApprovedSiteRepository;
|
||||||
import org.mitre.openid.connect.repository.BlacklistedSiteRepository;
|
import org.mitre.openid.connect.repository.BlacklistedSiteRepository;
|
||||||
import org.mitre.openid.connect.repository.WhitelistedSiteRepository;
|
import org.mitre.openid.connect.repository.WhitelistedSiteRepository;
|
||||||
import org.mitre.openid.connect.service.MITREidDataService;
|
import org.mitre.openid.connect.service.MITREidDataService;
|
||||||
import org.mitre.openid.connect.util.DateUtil;
|
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Captor;
|
import org.mockito.Captor;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
|
@ -70,6 +70,8 @@ import org.mockito.Mockito;
|
||||||
import org.mockito.invocation.InvocationOnMock;
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
import org.mockito.runners.MockitoJUnitRunner;
|
import org.mockito.runners.MockitoJUnitRunner;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat.ISO;
|
||||||
|
import org.springframework.format.datetime.DateFormatter;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
import org.springframework.security.oauth2.provider.OAuth2Authentication;
|
import org.springframework.security.oauth2.provider.OAuth2Authentication;
|
||||||
|
@ -118,8 +120,12 @@ public class TestMITREidDataService_1_0 {
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
private MITREidDataService_1_0 dataService;
|
private MITREidDataService_1_0 dataService;
|
||||||
|
|
||||||
|
private DateFormatter formatter;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void prepare() {
|
public void prepare() {
|
||||||
|
formatter = new DateFormatter();
|
||||||
|
formatter.setIso(ISO.DATE_TIME);
|
||||||
Mockito.reset(clientRepository, approvedSiteRepository, authHolderRepository, tokenRepository, sysScopeRepository, wlSiteRepository, blSiteRepository);
|
Mockito.reset(clientRepository, approvedSiteRepository, authHolderRepository, tokenRepository, sysScopeRepository, wlSiteRepository, blSiteRepository);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,8 +138,7 @@ public class TestMITREidDataService_1_0 {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testImportRefreshTokens() throws IOException, ParseException {
|
public void testImportRefreshTokens() throws IOException, ParseException {
|
||||||
String expiration1 = "2014-09-10T22:49:44.090+0000";
|
Date expirationDate1 = formatter.parse("2014-09-10T22:49:44.090+0000", Locale.ENGLISH);
|
||||||
Date expirationDate1 = DateUtil.utcToDate(expiration1);
|
|
||||||
|
|
||||||
ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
|
ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
|
||||||
when(mockedClient1.getClientId()).thenReturn("mocked_client_1");
|
when(mockedClient1.getClientId()).thenReturn("mocked_client_1");
|
||||||
|
@ -148,8 +153,7 @@ public class TestMITREidDataService_1_0 {
|
||||||
token1.setValue("eyJhbGciOiJub25lIn0.eyJqdGkiOiJmOTg4OWQyOS0xMTk1LTQ4ODEtODgwZC1lZjVlYzAwY2Y4NDIifQ.");
|
token1.setValue("eyJhbGciOiJub25lIn0.eyJqdGkiOiJmOTg4OWQyOS0xMTk1LTQ4ODEtODgwZC1lZjVlYzAwY2Y4NDIifQ.");
|
||||||
token1.setAuthenticationHolder(mockedAuthHolder1);
|
token1.setAuthenticationHolder(mockedAuthHolder1);
|
||||||
|
|
||||||
String expiration2 = "2015-01-07T18:31:50.079+0000";
|
Date expirationDate2 = formatter.parse("2015-01-07T18:31:50.079+0000", Locale.ENGLISH);
|
||||||
Date expirationDate2 = DateUtil.utcToDate(expiration2);
|
|
||||||
|
|
||||||
ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
|
ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
|
||||||
when(mockedClient2.getClientId()).thenReturn("mocked_client_2");
|
when(mockedClient2.getClientId()).thenReturn("mocked_client_2");
|
||||||
|
@ -251,8 +255,7 @@ public class TestMITREidDataService_1_0 {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testImportAccessTokens() throws IOException, ParseException {
|
public void testImportAccessTokens() throws IOException, ParseException {
|
||||||
String expiration1 = "2014-09-10T22:49:44.090+0000";
|
Date expirationDate1 = formatter.parse("2014-09-10T22:49:44.090+0000", Locale.ENGLISH);
|
||||||
Date expirationDate1 = DateUtil.utcToDate(expiration1);
|
|
||||||
|
|
||||||
ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
|
ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
|
||||||
when(mockedClient1.getClientId()).thenReturn("mocked_client_1");
|
when(mockedClient1.getClientId()).thenReturn("mocked_client_1");
|
||||||
|
@ -270,7 +273,7 @@ public class TestMITREidDataService_1_0 {
|
||||||
token1.setTokenType("Bearer");
|
token1.setTokenType("Bearer");
|
||||||
|
|
||||||
String expiration2 = "2015-01-07T18:31:50.079+0000";
|
String expiration2 = "2015-01-07T18:31:50.079+0000";
|
||||||
Date expirationDate2 = DateUtil.utcToDate(expiration2);
|
Date expirationDate2 = formatter.parse(expiration2, Locale.ENGLISH);
|
||||||
|
|
||||||
ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
|
ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
|
||||||
when(mockedClient2.getClientId()).thenReturn("mocked_client_2");
|
when(mockedClient2.getClientId()).thenReturn("mocked_client_2");
|
||||||
|
@ -567,9 +570,9 @@ public class TestMITREidDataService_1_0 {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testImportGrants() throws IOException {
|
public void testImportGrants() throws IOException, ParseException {
|
||||||
Date creationDate1 = DateUtil.utcToDate("2014-09-10T22:49:44.090+0000");
|
Date creationDate1 = formatter.parse("2014-09-10T22:49:44.090+0000", Locale.ENGLISH);
|
||||||
Date accessDate1 = DateUtil.utcToDate("2014-09-10T23:49:44.090+0000");
|
Date accessDate1 = formatter.parse("2014-09-10T23:49:44.090+0000", Locale.ENGLISH);
|
||||||
|
|
||||||
WhitelistedSite mockWlSite1 = mock(WhitelistedSite.class);
|
WhitelistedSite mockWlSite1 = mock(WhitelistedSite.class);
|
||||||
when(mockWlSite1.getId()).thenReturn(1L);
|
when(mockWlSite1.getId()).thenReturn(1L);
|
||||||
|
@ -587,9 +590,9 @@ public class TestMITREidDataService_1_0 {
|
||||||
site1.setAllowedScopes(ImmutableSet.of("openid", "phone"));
|
site1.setAllowedScopes(ImmutableSet.of("openid", "phone"));
|
||||||
site1.setApprovedAccessTokens(ImmutableSet.of(mockToken1));
|
site1.setApprovedAccessTokens(ImmutableSet.of(mockToken1));
|
||||||
|
|
||||||
Date creationDate2 = DateUtil.utcToDate("2014-09-11T18:49:44.090+0000");
|
Date creationDate2 = formatter.parse("2014-09-11T18:49:44.090+0000", Locale.ENGLISH);
|
||||||
Date accessDate2 = DateUtil.utcToDate("2014-09-11T20:49:44.090+0000");
|
Date accessDate2 = formatter.parse("2014-09-11T20:49:44.090+0000", Locale.ENGLISH);
|
||||||
Date timeoutDate2 = DateUtil.utcToDate("2014-10-01T20:49:44.090+0000");
|
Date timeoutDate2 = formatter.parse("2014-10-01T20:49:44.090+0000", Locale.ENGLISH);
|
||||||
|
|
||||||
ApprovedSite site2 = new ApprovedSite();
|
ApprovedSite site2 = new ApprovedSite();
|
||||||
site2.setId(2L);
|
site2.setId(2L);
|
||||||
|
@ -831,7 +834,7 @@ public class TestMITREidDataService_1_0 {
|
||||||
@Test
|
@Test
|
||||||
public void testFixRefreshTokenAuthHolderReferencesOnImport() throws IOException, ParseException {
|
public void testFixRefreshTokenAuthHolderReferencesOnImport() throws IOException, ParseException {
|
||||||
String expiration1 = "2014-09-10T22:49:44.090+0000";
|
String expiration1 = "2014-09-10T22:49:44.090+0000";
|
||||||
Date expirationDate1 = DateUtil.utcToDate(expiration1);
|
Date expirationDate1 = formatter.parse(expiration1, Locale.ENGLISH);
|
||||||
|
|
||||||
ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
|
ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
|
||||||
when(mockedClient1.getClientId()).thenReturn("mocked_client_1");
|
when(mockedClient1.getClientId()).thenReturn("mocked_client_1");
|
||||||
|
@ -854,7 +857,7 @@ public class TestMITREidDataService_1_0 {
|
||||||
token1.setAuthenticationHolder(holder1);
|
token1.setAuthenticationHolder(holder1);
|
||||||
|
|
||||||
String expiration2 = "2015-01-07T18:31:50.079+0000";
|
String expiration2 = "2015-01-07T18:31:50.079+0000";
|
||||||
Date expirationDate2 = DateUtil.utcToDate(expiration2);
|
Date expirationDate2 = formatter.parse(expiration2, Locale.ENGLISH);
|
||||||
|
|
||||||
ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
|
ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
|
||||||
when(mockedClient2.getClientId()).thenReturn("mocked_client_2");
|
when(mockedClient2.getClientId()).thenReturn("mocked_client_2");
|
||||||
|
|
|
@ -40,6 +40,7 @@ import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -61,7 +62,6 @@ import org.mitre.openid.connect.repository.ApprovedSiteRepository;
|
||||||
import org.mitre.openid.connect.repository.BlacklistedSiteRepository;
|
import org.mitre.openid.connect.repository.BlacklistedSiteRepository;
|
||||||
import org.mitre.openid.connect.repository.WhitelistedSiteRepository;
|
import org.mitre.openid.connect.repository.WhitelistedSiteRepository;
|
||||||
import org.mitre.openid.connect.service.MITREidDataService;
|
import org.mitre.openid.connect.service.MITREidDataService;
|
||||||
import org.mitre.openid.connect.util.DateUtil;
|
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Captor;
|
import org.mockito.Captor;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
|
@ -70,6 +70,8 @@ import org.mockito.Mockito;
|
||||||
import org.mockito.invocation.InvocationOnMock;
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
import org.mockito.runners.MockitoJUnitRunner;
|
import org.mockito.runners.MockitoJUnitRunner;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat.ISO;
|
||||||
|
import org.springframework.format.datetime.DateFormatter;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
import org.springframework.security.oauth2.provider.OAuth2Authentication;
|
import org.springframework.security.oauth2.provider.OAuth2Authentication;
|
||||||
|
@ -117,9 +119,13 @@ public class TestMITREidDataService_1_1 {
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
private MITREidDataService_1_1 dataService;
|
private MITREidDataService_1_1 dataService;
|
||||||
|
private DateFormatter formatter;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void prepare() {
|
public void prepare() {
|
||||||
|
formatter = new DateFormatter();
|
||||||
|
formatter.setIso(ISO.DATE_TIME);
|
||||||
|
|
||||||
Mockito.reset(clientRepository, approvedSiteRepository, authHolderRepository, tokenRepository, sysScopeRepository, wlSiteRepository, blSiteRepository);
|
Mockito.reset(clientRepository, approvedSiteRepository, authHolderRepository, tokenRepository, sysScopeRepository, wlSiteRepository, blSiteRepository);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +141,7 @@ public class TestMITREidDataService_1_1 {
|
||||||
@Test
|
@Test
|
||||||
public void testImportRefreshTokens() throws IOException, ParseException {
|
public void testImportRefreshTokens() throws IOException, ParseException {
|
||||||
String expiration1 = "2014-09-10T22:49:44.090+0000";
|
String expiration1 = "2014-09-10T22:49:44.090+0000";
|
||||||
Date expirationDate1 = DateUtil.utcToDate(expiration1);
|
Date expirationDate1 = formatter.parse(expiration1, Locale.ENGLISH);
|
||||||
|
|
||||||
ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
|
ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
|
||||||
when(mockedClient1.getClientId()).thenReturn("mocked_client_1");
|
when(mockedClient1.getClientId()).thenReturn("mocked_client_1");
|
||||||
|
@ -151,7 +157,7 @@ public class TestMITREidDataService_1_1 {
|
||||||
token1.setAuthenticationHolder(mockedAuthHolder1);
|
token1.setAuthenticationHolder(mockedAuthHolder1);
|
||||||
|
|
||||||
String expiration2 = "2015-01-07T18:31:50.079+0000";
|
String expiration2 = "2015-01-07T18:31:50.079+0000";
|
||||||
Date expirationDate2 = DateUtil.utcToDate(expiration2);
|
Date expirationDate2 = formatter.parse(expiration2, Locale.ENGLISH);
|
||||||
|
|
||||||
ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
|
ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
|
||||||
when(mockedClient2.getClientId()).thenReturn("mocked_client_2");
|
when(mockedClient2.getClientId()).thenReturn("mocked_client_2");
|
||||||
|
@ -254,7 +260,7 @@ public class TestMITREidDataService_1_1 {
|
||||||
@Test
|
@Test
|
||||||
public void testImportAccessTokens() throws IOException, ParseException {
|
public void testImportAccessTokens() throws IOException, ParseException {
|
||||||
String expiration1 = "2014-09-10T22:49:44.090+0000";
|
String expiration1 = "2014-09-10T22:49:44.090+0000";
|
||||||
Date expirationDate1 = DateUtil.utcToDate(expiration1);
|
Date expirationDate1 = formatter.parse(expiration1, Locale.ENGLISH);
|
||||||
|
|
||||||
ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
|
ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
|
||||||
when(mockedClient1.getClientId()).thenReturn("mocked_client_1");
|
when(mockedClient1.getClientId()).thenReturn("mocked_client_1");
|
||||||
|
@ -272,7 +278,7 @@ public class TestMITREidDataService_1_1 {
|
||||||
token1.setTokenType("Bearer");
|
token1.setTokenType("Bearer");
|
||||||
|
|
||||||
String expiration2 = "2015-01-07T18:31:50.079+0000";
|
String expiration2 = "2015-01-07T18:31:50.079+0000";
|
||||||
Date expirationDate2 = DateUtil.utcToDate(expiration2);
|
Date expirationDate2 = formatter.parse(expiration2, Locale.ENGLISH);
|
||||||
|
|
||||||
ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
|
ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
|
||||||
when(mockedClient2.getClientId()).thenReturn("mocked_client_2");
|
when(mockedClient2.getClientId()).thenReturn("mocked_client_2");
|
||||||
|
@ -568,9 +574,9 @@ public class TestMITREidDataService_1_1 {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testImportGrants() throws IOException {
|
public void testImportGrants() throws IOException, ParseException {
|
||||||
Date creationDate1 = DateUtil.utcToDate("2014-09-10T22:49:44.090+0000");
|
Date creationDate1 = formatter.parse("2014-09-10T22:49:44.090+0000", Locale.ENGLISH);
|
||||||
Date accessDate1 = DateUtil.utcToDate("2014-09-10T23:49:44.090+0000");
|
Date accessDate1 = formatter.parse("2014-09-10T23:49:44.090+0000", Locale.ENGLISH);
|
||||||
|
|
||||||
WhitelistedSite mockWlSite1 = mock(WhitelistedSite.class);
|
WhitelistedSite mockWlSite1 = mock(WhitelistedSite.class);
|
||||||
when(mockWlSite1.getId()).thenReturn(1L);
|
when(mockWlSite1.getId()).thenReturn(1L);
|
||||||
|
@ -588,9 +594,9 @@ public class TestMITREidDataService_1_1 {
|
||||||
site1.setAllowedScopes(ImmutableSet.of("openid", "phone"));
|
site1.setAllowedScopes(ImmutableSet.of("openid", "phone"));
|
||||||
site1.setApprovedAccessTokens(ImmutableSet.of(mockToken1));
|
site1.setApprovedAccessTokens(ImmutableSet.of(mockToken1));
|
||||||
|
|
||||||
Date creationDate2 = DateUtil.utcToDate("2014-09-11T18:49:44.090+0000");
|
Date creationDate2 = formatter.parse("2014-09-11T18:49:44.090+0000", Locale.ENGLISH);
|
||||||
Date accessDate2 = DateUtil.utcToDate("2014-09-11T20:49:44.090+0000");
|
Date accessDate2 = formatter.parse("2014-09-11T20:49:44.090+0000", Locale.ENGLISH);
|
||||||
Date timeoutDate2 = DateUtil.utcToDate("2014-10-01T20:49:44.090+0000");
|
Date timeoutDate2 = formatter.parse("2014-10-01T20:49:44.090+0000", Locale.ENGLISH);
|
||||||
|
|
||||||
ApprovedSite site2 = new ApprovedSite();
|
ApprovedSite site2 = new ApprovedSite();
|
||||||
site2.setId(2L);
|
site2.setId(2L);
|
||||||
|
@ -840,7 +846,7 @@ public class TestMITREidDataService_1_1 {
|
||||||
@Test
|
@Test
|
||||||
public void testFixRefreshTokenAuthHolderReferencesOnImport() throws IOException, ParseException {
|
public void testFixRefreshTokenAuthHolderReferencesOnImport() throws IOException, ParseException {
|
||||||
String expiration1 = "2014-09-10T22:49:44.090+0000";
|
String expiration1 = "2014-09-10T22:49:44.090+0000";
|
||||||
Date expirationDate1 = DateUtil.utcToDate(expiration1);
|
Date expirationDate1 = formatter.parse(expiration1, Locale.ENGLISH);
|
||||||
|
|
||||||
ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
|
ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
|
||||||
when(mockedClient1.getClientId()).thenReturn("mocked_client_1");
|
when(mockedClient1.getClientId()).thenReturn("mocked_client_1");
|
||||||
|
@ -863,7 +869,7 @@ public class TestMITREidDataService_1_1 {
|
||||||
token1.setAuthenticationHolder(holder1);
|
token1.setAuthenticationHolder(holder1);
|
||||||
|
|
||||||
String expiration2 = "2015-01-07T18:31:50.079+0000";
|
String expiration2 = "2015-01-07T18:31:50.079+0000";
|
||||||
Date expirationDate2 = DateUtil.utcToDate(expiration2);
|
Date expirationDate2 = formatter.parse(expiration2, Locale.ENGLISH);
|
||||||
|
|
||||||
ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
|
ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
|
||||||
when(mockedClient2.getClientId()).thenReturn("mocked_client_2");
|
when(mockedClient2.getClientId()).thenReturn("mocked_client_2");
|
||||||
|
|
|
@ -44,6 +44,7 @@ import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -66,7 +67,6 @@ import org.mitre.openid.connect.repository.ApprovedSiteRepository;
|
||||||
import org.mitre.openid.connect.repository.BlacklistedSiteRepository;
|
import org.mitre.openid.connect.repository.BlacklistedSiteRepository;
|
||||||
import org.mitre.openid.connect.repository.WhitelistedSiteRepository;
|
import org.mitre.openid.connect.repository.WhitelistedSiteRepository;
|
||||||
import org.mitre.openid.connect.service.MITREidDataService;
|
import org.mitre.openid.connect.service.MITREidDataService;
|
||||||
import org.mitre.openid.connect.util.DateUtil;
|
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Captor;
|
import org.mockito.Captor;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
|
@ -75,6 +75,8 @@ import org.mockito.Mockito;
|
||||||
import org.mockito.invocation.InvocationOnMock;
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
import org.mockito.runners.MockitoJUnitRunner;
|
import org.mockito.runners.MockitoJUnitRunner;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat.ISO;
|
||||||
|
import org.springframework.format.datetime.DateFormatter;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
import org.springframework.security.oauth2.provider.OAuth2Authentication;
|
import org.springframework.security.oauth2.provider.OAuth2Authentication;
|
||||||
|
@ -127,16 +129,20 @@ public class TestMITREidDataService_1_2 {
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
private MITREidDataService_1_2 dataService;
|
private MITREidDataService_1_2 dataService;
|
||||||
|
private DateFormatter formatter;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void prepare() {
|
public void prepare() {
|
||||||
|
formatter = new DateFormatter();
|
||||||
|
formatter.setIso(ISO.DATE_TIME);
|
||||||
|
|
||||||
Mockito.reset(clientRepository, approvedSiteRepository, authHolderRepository, tokenRepository, sysScopeRepository, wlSiteRepository, blSiteRepository);
|
Mockito.reset(clientRepository, approvedSiteRepository, authHolderRepository, tokenRepository, sysScopeRepository, wlSiteRepository, blSiteRepository);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExportRefreshTokens() throws IOException, ParseException {
|
public void testExportRefreshTokens() throws IOException, ParseException {
|
||||||
String expiration1 = "2014-09-10T22:49:44.090+0000";
|
String expiration1 = "2014-09-10T22:49:44.090+0000";
|
||||||
Date expirationDate1 = DateUtil.utcToDate(expiration1);
|
Date expirationDate1 = formatter.parse(expiration1, Locale.ENGLISH);
|
||||||
|
|
||||||
ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
|
ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
|
||||||
when(mockedClient1.getClientId()).thenReturn("mocked_client_1");
|
when(mockedClient1.getClientId()).thenReturn("mocked_client_1");
|
||||||
|
@ -152,7 +158,7 @@ public class TestMITREidDataService_1_2 {
|
||||||
token1.setAuthenticationHolder(mockedAuthHolder1);
|
token1.setAuthenticationHolder(mockedAuthHolder1);
|
||||||
|
|
||||||
String expiration2 = "2015-01-07T18:31:50.079+0000";
|
String expiration2 = "2015-01-07T18:31:50.079+0000";
|
||||||
Date expirationDate2 = DateUtil.utcToDate(expiration2);
|
Date expirationDate2 = formatter.parse(expiration2, Locale.ENGLISH);
|
||||||
|
|
||||||
ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
|
ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
|
||||||
when(mockedClient2.getClientId()).thenReturn("mocked_client_2");
|
when(mockedClient2.getClientId()).thenReturn("mocked_client_2");
|
||||||
|
@ -238,7 +244,7 @@ public class TestMITREidDataService_1_2 {
|
||||||
} else {
|
} else {
|
||||||
assertThat(token.get("id").getAsLong(), equalTo(compare.getId()));
|
assertThat(token.get("id").getAsLong(), equalTo(compare.getId()));
|
||||||
assertThat(token.get("clientId").getAsString(), equalTo(compare.getClient().getClientId()));
|
assertThat(token.get("clientId").getAsString(), equalTo(compare.getClient().getClientId()));
|
||||||
assertThat(token.get("expiration").getAsString(), equalTo(DateUtil.toUTCString(compare.getExpiration())));
|
assertThat(token.get("expiration").getAsString(), equalTo(formatter.print(compare.getExpiration(), Locale.ENGLISH)));
|
||||||
assertThat(token.get("value").getAsString(), equalTo(compare.getValue()));
|
assertThat(token.get("value").getAsString(), equalTo(compare.getValue()));
|
||||||
assertThat(token.get("authenticationHolderId").getAsLong(), equalTo(compare.getAuthenticationHolder().getId()));
|
assertThat(token.get("authenticationHolderId").getAsLong(), equalTo(compare.getAuthenticationHolder().getId()));
|
||||||
checked.add(compare);
|
checked.add(compare);
|
||||||
|
@ -259,7 +265,7 @@ public class TestMITREidDataService_1_2 {
|
||||||
@Test
|
@Test
|
||||||
public void testImportRefreshTokens() throws IOException, ParseException {
|
public void testImportRefreshTokens() throws IOException, ParseException {
|
||||||
String expiration1 = "2014-09-10T22:49:44.090+0000";
|
String expiration1 = "2014-09-10T22:49:44.090+0000";
|
||||||
Date expirationDate1 = DateUtil.utcToDate(expiration1);
|
Date expirationDate1 = formatter.parse(expiration1, Locale.ENGLISH);
|
||||||
|
|
||||||
ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
|
ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
|
||||||
when(mockedClient1.getClientId()).thenReturn("mocked_client_1");
|
when(mockedClient1.getClientId()).thenReturn("mocked_client_1");
|
||||||
|
@ -275,7 +281,7 @@ public class TestMITREidDataService_1_2 {
|
||||||
token1.setAuthenticationHolder(mockedAuthHolder1);
|
token1.setAuthenticationHolder(mockedAuthHolder1);
|
||||||
|
|
||||||
String expiration2 = "2015-01-07T18:31:50.079+0000";
|
String expiration2 = "2015-01-07T18:31:50.079+0000";
|
||||||
Date expirationDate2 = DateUtil.utcToDate(expiration2);
|
Date expirationDate2 = formatter.parse(expiration2, Locale.ENGLISH);
|
||||||
|
|
||||||
ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
|
ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
|
||||||
when(mockedClient2.getClientId()).thenReturn("mocked_client_2");
|
when(mockedClient2.getClientId()).thenReturn("mocked_client_2");
|
||||||
|
@ -371,7 +377,7 @@ public class TestMITREidDataService_1_2 {
|
||||||
@Test
|
@Test
|
||||||
public void testExportAccessTokens() throws IOException, ParseException {
|
public void testExportAccessTokens() throws IOException, ParseException {
|
||||||
String expiration1 = "2014-09-10T22:49:44.090+0000";
|
String expiration1 = "2014-09-10T22:49:44.090+0000";
|
||||||
Date expirationDate1 = DateUtil.utcToDate(expiration1);
|
Date expirationDate1 = formatter.parse(expiration1, Locale.ENGLISH);
|
||||||
|
|
||||||
ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
|
ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
|
||||||
when(mockedClient1.getClientId()).thenReturn("mocked_client_1");
|
when(mockedClient1.getClientId()).thenReturn("mocked_client_1");
|
||||||
|
@ -389,7 +395,7 @@ public class TestMITREidDataService_1_2 {
|
||||||
token1.setTokenType("Bearer");
|
token1.setTokenType("Bearer");
|
||||||
|
|
||||||
String expiration2 = "2015-01-07T18:31:50.079+0000";
|
String expiration2 = "2015-01-07T18:31:50.079+0000";
|
||||||
Date expirationDate2 = DateUtil.utcToDate(expiration2);
|
Date expirationDate2 = formatter.parse(expiration2, Locale.ENGLISH);
|
||||||
|
|
||||||
ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
|
ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
|
||||||
when(mockedClient2.getClientId()).thenReturn("mocked_client_2");
|
when(mockedClient2.getClientId()).thenReturn("mocked_client_2");
|
||||||
|
@ -482,7 +488,7 @@ public class TestMITREidDataService_1_2 {
|
||||||
} else {
|
} else {
|
||||||
assertThat(token.get("id").getAsLong(), equalTo(compare.getId()));
|
assertThat(token.get("id").getAsLong(), equalTo(compare.getId()));
|
||||||
assertThat(token.get("clientId").getAsString(), equalTo(compare.getClient().getClientId()));
|
assertThat(token.get("clientId").getAsString(), equalTo(compare.getClient().getClientId()));
|
||||||
assertThat(token.get("expiration").getAsString(), equalTo(DateUtil.toUTCString(compare.getExpiration())));
|
assertThat(token.get("expiration").getAsString(), equalTo(formatter.print(compare.getExpiration(), Locale.ENGLISH)));
|
||||||
assertThat(token.get("value").getAsString(), equalTo(compare.getValue()));
|
assertThat(token.get("value").getAsString(), equalTo(compare.getValue()));
|
||||||
assertThat(token.get("type").getAsString(), equalTo(compare.getTokenType()));
|
assertThat(token.get("type").getAsString(), equalTo(compare.getTokenType()));
|
||||||
assertThat(token.get("authenticationHolderId").getAsLong(), equalTo(compare.getAuthenticationHolder().getId()));
|
assertThat(token.get("authenticationHolderId").getAsLong(), equalTo(compare.getAuthenticationHolder().getId()));
|
||||||
|
@ -515,7 +521,7 @@ public class TestMITREidDataService_1_2 {
|
||||||
@Test
|
@Test
|
||||||
public void testImportAccessTokens() throws IOException, ParseException {
|
public void testImportAccessTokens() throws IOException, ParseException {
|
||||||
String expiration1 = "2014-09-10T22:49:44.090+0000";
|
String expiration1 = "2014-09-10T22:49:44.090+0000";
|
||||||
Date expirationDate1 = DateUtil.utcToDate(expiration1);
|
Date expirationDate1 = formatter.parse(expiration1, Locale.ENGLISH);
|
||||||
|
|
||||||
ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
|
ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
|
||||||
when(mockedClient1.getClientId()).thenReturn("mocked_client_1");
|
when(mockedClient1.getClientId()).thenReturn("mocked_client_1");
|
||||||
|
@ -533,7 +539,7 @@ public class TestMITREidDataService_1_2 {
|
||||||
token1.setTokenType("Bearer");
|
token1.setTokenType("Bearer");
|
||||||
|
|
||||||
String expiration2 = "2015-01-07T18:31:50.079+0000";
|
String expiration2 = "2015-01-07T18:31:50.079+0000";
|
||||||
Date expirationDate2 = DateUtil.utcToDate(expiration2);
|
Date expirationDate2 = formatter.parse(expiration2, Locale.ENGLISH);
|
||||||
|
|
||||||
ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
|
ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
|
||||||
when(mockedClient2.getClientId()).thenReturn("mocked_client_2");
|
when(mockedClient2.getClientId()).thenReturn("mocked_client_2");
|
||||||
|
@ -1120,9 +1126,9 @@ public class TestMITREidDataService_1_2 {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExportGrants() throws IOException {
|
public void testExportGrants() throws IOException, ParseException {
|
||||||
Date creationDate1 = DateUtil.utcToDate("2014-09-10T22:49:44.090+0000");
|
Date creationDate1 = formatter.parse("2014-09-10T22:49:44.090+0000", Locale.ENGLISH);
|
||||||
Date accessDate1 = DateUtil.utcToDate("2014-09-10T23:49:44.090+0000");
|
Date accessDate1 = formatter.parse("2014-09-10T23:49:44.090+0000", Locale.ENGLISH);
|
||||||
|
|
||||||
WhitelistedSite mockWlSite1 = mock(WhitelistedSite.class);
|
WhitelistedSite mockWlSite1 = mock(WhitelistedSite.class);
|
||||||
when(mockWlSite1.getId()).thenReturn(1L);
|
when(mockWlSite1.getId()).thenReturn(1L);
|
||||||
|
@ -1140,9 +1146,9 @@ public class TestMITREidDataService_1_2 {
|
||||||
site1.setAllowedScopes(ImmutableSet.of("openid", "phone"));
|
site1.setAllowedScopes(ImmutableSet.of("openid", "phone"));
|
||||||
site1.setApprovedAccessTokens(ImmutableSet.of(mockToken1));
|
site1.setApprovedAccessTokens(ImmutableSet.of(mockToken1));
|
||||||
|
|
||||||
Date creationDate2 = DateUtil.utcToDate("2014-09-11T18:49:44.090+0000");
|
Date creationDate2 = formatter.parse("2014-09-11T18:49:44.090+0000", Locale.ENGLISH);
|
||||||
Date accessDate2 = DateUtil.utcToDate("2014-09-11T20:49:44.090+0000");
|
Date accessDate2 = formatter.parse("2014-09-11T20:49:44.090+0000", Locale.ENGLISH);
|
||||||
Date timeoutDate2 = DateUtil.utcToDate("2014-10-01T20:49:44.090+0000");
|
Date timeoutDate2 = formatter.parse("2014-10-01T20:49:44.090+0000", Locale.ENGLISH);
|
||||||
|
|
||||||
ApprovedSite site2 = new ApprovedSite();
|
ApprovedSite site2 = new ApprovedSite();
|
||||||
site2.setId(2L);
|
site2.setId(2L);
|
||||||
|
@ -1222,12 +1228,12 @@ public class TestMITREidDataService_1_2 {
|
||||||
fail("Could not find matching whitelisted site id: " + site.get("id").getAsString());
|
fail("Could not find matching whitelisted site id: " + site.get("id").getAsString());
|
||||||
} else {
|
} else {
|
||||||
assertThat(site.get("clientId").getAsString(), equalTo(compare.getClientId()));
|
assertThat(site.get("clientId").getAsString(), equalTo(compare.getClientId()));
|
||||||
assertThat(site.get("creationDate").getAsString(), equalTo(DateUtil.toUTCString(compare.getCreationDate())));
|
assertThat(site.get("creationDate").getAsString(), equalTo(formatter.print(compare.getCreationDate(), Locale.ENGLISH)));
|
||||||
assertThat(site.get("accessDate").getAsString(), equalTo(DateUtil.toUTCString(compare.getAccessDate())));
|
assertThat(site.get("accessDate").getAsString(), equalTo(formatter.print(compare.getAccessDate(), Locale.ENGLISH)));
|
||||||
if(site.get("timeoutDate").isJsonNull()) {
|
if(site.get("timeoutDate").isJsonNull()) {
|
||||||
assertNull(compare.getTimeoutDate());
|
assertNull(compare.getTimeoutDate());
|
||||||
} else {
|
} else {
|
||||||
assertThat(site.get("timeoutDate").getAsString(), equalTo(DateUtil.toUTCString(compare.getTimeoutDate())));
|
assertThat(site.get("timeoutDate").getAsString(), equalTo(formatter.print(compare.getTimeoutDate(), Locale.ENGLISH)));
|
||||||
}
|
}
|
||||||
assertThat(site.get("userId").getAsString(), equalTo(compare.getUserId()));
|
assertThat(site.get("userId").getAsString(), equalTo(compare.getUserId()));
|
||||||
assertThat(jsonArrayToStringSet(site.getAsJsonArray("allowedScopes")), equalTo(compare.getAllowedScopes()));
|
assertThat(jsonArrayToStringSet(site.getAsJsonArray("allowedScopes")), equalTo(compare.getAllowedScopes()));
|
||||||
|
@ -1254,9 +1260,9 @@ public class TestMITREidDataService_1_2 {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testImportGrants() throws IOException {
|
public void testImportGrants() throws IOException, ParseException {
|
||||||
Date creationDate1 = DateUtil.utcToDate("2014-09-10T22:49:44.090+0000");
|
Date creationDate1 = formatter.parse("2014-09-10T22:49:44.090+0000", Locale.ENGLISH);
|
||||||
Date accessDate1 = DateUtil.utcToDate("2014-09-10T23:49:44.090+0000");
|
Date accessDate1 = formatter.parse("2014-09-10T23:49:44.090+0000", Locale.ENGLISH);
|
||||||
|
|
||||||
WhitelistedSite mockWlSite1 = mock(WhitelistedSite.class);
|
WhitelistedSite mockWlSite1 = mock(WhitelistedSite.class);
|
||||||
when(mockWlSite1.getId()).thenReturn(1L);
|
when(mockWlSite1.getId()).thenReturn(1L);
|
||||||
|
@ -1274,9 +1280,9 @@ public class TestMITREidDataService_1_2 {
|
||||||
site1.setAllowedScopes(ImmutableSet.of("openid", "phone"));
|
site1.setAllowedScopes(ImmutableSet.of("openid", "phone"));
|
||||||
site1.setApprovedAccessTokens(ImmutableSet.of(mockToken1));
|
site1.setApprovedAccessTokens(ImmutableSet.of(mockToken1));
|
||||||
|
|
||||||
Date creationDate2 = DateUtil.utcToDate("2014-09-11T18:49:44.090+0000");
|
Date creationDate2 = formatter.parse("2014-09-11T18:49:44.090+0000", Locale.ENGLISH);
|
||||||
Date accessDate2 = DateUtil.utcToDate("2014-09-11T20:49:44.090+0000");
|
Date accessDate2 = formatter.parse("2014-09-11T20:49:44.090+0000", Locale.ENGLISH);
|
||||||
Date timeoutDate2 = DateUtil.utcToDate("2014-10-01T20:49:44.090+0000");
|
Date timeoutDate2 = formatter.parse("2014-10-01T20:49:44.090+0000", Locale.ENGLISH);
|
||||||
|
|
||||||
ApprovedSite site2 = new ApprovedSite();
|
ApprovedSite site2 = new ApprovedSite();
|
||||||
site2.setId(2L);
|
site2.setId(2L);
|
||||||
|
@ -1735,7 +1741,7 @@ public class TestMITREidDataService_1_2 {
|
||||||
@Test
|
@Test
|
||||||
public void testFixRefreshTokenAuthHolderReferencesOnImport() throws IOException, ParseException {
|
public void testFixRefreshTokenAuthHolderReferencesOnImport() throws IOException, ParseException {
|
||||||
String expiration1 = "2014-09-10T22:49:44.090+0000";
|
String expiration1 = "2014-09-10T22:49:44.090+0000";
|
||||||
Date expirationDate1 = DateUtil.utcToDate(expiration1);
|
Date expirationDate1 = formatter.parse(expiration1, Locale.ENGLISH);
|
||||||
|
|
||||||
ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
|
ClientDetailsEntity mockedClient1 = mock(ClientDetailsEntity.class);
|
||||||
when(mockedClient1.getClientId()).thenReturn("mocked_client_1");
|
when(mockedClient1.getClientId()).thenReturn("mocked_client_1");
|
||||||
|
@ -1758,7 +1764,7 @@ public class TestMITREidDataService_1_2 {
|
||||||
token1.setAuthenticationHolder(holder1);
|
token1.setAuthenticationHolder(holder1);
|
||||||
|
|
||||||
String expiration2 = "2015-01-07T18:31:50.079+0000";
|
String expiration2 = "2015-01-07T18:31:50.079+0000";
|
||||||
Date expirationDate2 = DateUtil.utcToDate(expiration2);
|
Date expirationDate2 = formatter.parse(expiration2, Locale.ENGLISH);
|
||||||
|
|
||||||
ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
|
ClientDetailsEntity mockedClient2 = mock(ClientDetailsEntity.class);
|
||||||
when(mockedClient2.getClientId()).thenReturn("mocked_client_2");
|
when(mockedClient2.getClientId()).thenReturn("mocked_client_2");
|
||||||
|
|
Loading…
Reference in New Issue