updated 1.2 import to reflect new objects

pull/819/merge
Justin Richer 2015-05-22 17:30:12 -04:00
parent 441b19f0c5
commit 3d1aee77b4
1 changed files with 49 additions and 80 deletions

View File

@ -35,6 +35,7 @@ import org.mitre.oauth2.model.ClientDetailsEntity.AuthMethod;
import org.mitre.oauth2.model.ClientDetailsEntity.SubjectType; import org.mitre.oauth2.model.ClientDetailsEntity.SubjectType;
import org.mitre.oauth2.model.OAuth2AccessTokenEntity; import org.mitre.oauth2.model.OAuth2AccessTokenEntity;
import org.mitre.oauth2.model.OAuth2RefreshTokenEntity; import org.mitre.oauth2.model.OAuth2RefreshTokenEntity;
import org.mitre.oauth2.model.SavedUserAuthentication;
import org.mitre.oauth2.model.SystemScope; import org.mitre.oauth2.model.SystemScope;
import org.mitre.oauth2.repository.AuthenticationHolderRepository; import org.mitre.oauth2.repository.AuthenticationHolderRepository;
import org.mitre.oauth2.repository.OAuth2ClientRepository; import org.mitre.oauth2.repository.OAuth2ClientRepository;
@ -681,43 +682,34 @@ public class MITREidDataService_1_2 extends MITREidDataServiceSupport implements
if (reader.peek() == JsonToken.NULL) { if (reader.peek() == JsonToken.NULL) {
reader.skipValue(); reader.skipValue();
} else if (name.equals("id")) { } else if (name.equals("id")) {
currentId = reader.nextLong(); ahe.setId(reader.nextLong());
} else if (name.equals("ownerId")) { currentId = ahe.getId();
//not needed } else if (name.equals("requestParameters")) {
reader.skipValue(); ahe.setRequestParameters(readMap(reader));
} else if (name.equals("authentication")) { } else if (name.equals("clientId")) {
OAuth2Request authorizationRequest = null; ahe.setClientId(reader.nextString());
Authentication userAuthentication = null; } else if (name.equals("scope")) {
reader.beginObject(); ahe.setScope(readSet(reader));
while (reader.hasNext()) { } else if (name.equals("resourceIds")) {
switch (reader.peek()) { ahe.setResourceIds(readSet(reader));
case END_OBJECT: } else if (name.equals("authorities")) {
continue; Set<String> authorityStrs = readSet(reader);
case NAME: Set<GrantedAuthority> authorities = new HashSet<GrantedAuthority>();
String subName = reader.nextName(); for (String s : authorityStrs) {
if (subName.equals("authorizationRequest")) { GrantedAuthority ga = new SimpleGrantedAuthority(s);
authorizationRequest = readAuthorizationRequest(reader); authorities.add(ga);
} else if (subName.equals("userAuthentication")) {
if (reader.peek() == JsonToken.NULL) {
reader.skipValue();
} else {
String authString = reader.nextString();
userAuthentication = base64UrlDecodeObject(authString, Authentication.class);
} }
} else { ahe.setAuthorities(authorities);
logger.debug("Found unexpected entry"); } else if (name.equals("approved")) {
reader.skipValue(); ahe.setApproved(reader.nextBoolean());
} } else if (name.equals("redirectUri")) {
break; ahe.setRedirectUri(reader.nextString());
default: } else if (name.equals("responseTypes")) {
logger.debug("Found unexpected entry"); ahe.setResponseTypes(readSet(reader));
reader.skipValue(); } else if (name.equals("extensions")) {
continue; ahe.setExtensions(readMap(reader));
} } else if (name.equals("savedUserAuthentication")) {
} ahe.setUserAuth(readSavedUserAuthentication(reader));
reader.endObject();
OAuth2Authentication auth = new OAuth2Authentication(authorizationRequest, userAuthentication);
ahe.setAuthentication(auth);
} else { } else {
logger.debug("Found unexpected entry"); logger.debug("Found unexpected entry");
reader.skipValue(); reader.skipValue();
@ -738,72 +730,47 @@ public class MITREidDataService_1_2 extends MITREidDataServiceSupport implements
logger.info("Done reading authentication holders"); logger.info("Done reading authentication holders");
} }
//used by readAuthenticationHolders /**
private OAuth2Request readAuthorizationRequest(JsonReader reader) throws IOException { * @param reader
Set<String> scope = new LinkedHashSet<String>(); * @return
Set<String> resourceIds = new HashSet<String>(); * @throws IOException
boolean approved = false; */
Collection<GrantedAuthority> authorities = new HashSet<GrantedAuthority>(); private SavedUserAuthentication readSavedUserAuthentication(JsonReader reader) throws IOException {
Map<String, String> requestParameters = new HashMap<String, String>(); SavedUserAuthentication savedUserAuth = new SavedUserAuthentication();
Set<String> responseTypes = new HashSet<String>();
Map<String, Serializable> extensions = new HashMap<String, Serializable>();
String redirectUri = null;
String clientId = null;
reader.beginObject(); reader.beginObject();
while (reader.hasNext()) { while (reader.hasNext()) {
switch (reader.peek()) { switch(reader.peek()) {
case END_OBJECT: case END_OBJECT:
continue; continue;
case NAME: case NAME:
String name = reader.nextName(); String name = reader.nextName();
if (reader.peek() == JsonToken.NULL) { if (reader.peek() == JsonToken.NULL) {
reader.skipValue(); reader.skipValue();
} else if (name.equals("requestParameters")) { } else if (name.equals("name")) {
requestParameters = readMap(reader); savedUserAuth.setName(reader.nextString());
} else if (name.equals("clientId")) { } else if (name.equals("sourceClass")) {
clientId = reader.nextString(); savedUserAuth.setSourceClass(reader.nextString());
} else if (name.equals("scope")) {
scope = readSet(reader);
} else if (name.equals("resourceIds")) {
resourceIds = readSet(reader);
} else if (name.equals("authorities")) { } else if (name.equals("authorities")) {
Set<String> authorityStrs = readSet(reader); Set<String> authorityStrs = readSet(reader);
authorities = new HashSet<GrantedAuthority>(); Set<GrantedAuthority> authorities = new HashSet<GrantedAuthority>();
for (String s : authorityStrs) { for (String s : authorityStrs) {
GrantedAuthority ga = new SimpleGrantedAuthority(s); GrantedAuthority ga = new SimpleGrantedAuthority(s);
authorities.add(ga); authorities.add(ga);
} }
} else if (name.equals("approved")) { savedUserAuth.setAuthorities(authorities);
approved = reader.nextBoolean();
} else if (name.equals("denied")) {
if (approved == false) {
approved = !reader.nextBoolean();
}
} else if (name.equals("redirectUri")) {
redirectUri = reader.nextString();
} else if (name.equals("responseTypes")) {
responseTypes = readSet(reader);
} else if (name.equals("extensions")) {
Map<String, String> extEnc = readMap(reader);
for (Entry<String, String> entry : extEnc.entrySet()) {
Serializable decoded = base64UrlDecodeObject(entry.getValue(), Serializable.class);
if (decoded != null) {
extensions.put(entry.getKey(), decoded);
}
}
} else { } else {
logger.debug("Found unexpected entry");
reader.skipValue(); reader.skipValue();
} }
break; break;
default:
logger.debug("Found unexpected entry");
reader.skipValue();
continue;
} }
} }
reader.endObject(); reader.endObject();
return new OAuth2Request(requestParameters, clientId, authorities, approved, scope, resourceIds, redirectUri, responseTypes, extensions); return savedUserAuth;
} }
Map<Long, Long> grantOldToNewIdMap = new HashMap<Long, Long>(); Map<Long, Long> grantOldToNewIdMap = new HashMap<Long, Long>();
Map<Long, Long> grantToWhitelistedSiteRefs = new HashMap<Long, Long>(); Map<Long, Long> grantToWhitelistedSiteRefs = new HashMap<Long, Long>();
Map<Long, Set<Long>> grantToAccessTokensRefs = new HashMap<Long, Set<Long>>(); Map<Long, Set<Long>> grantToAccessTokensRefs = new HashMap<Long, Set<Long>>();
@ -1147,6 +1114,7 @@ public class MITREidDataService_1_2 extends MITREidDataServiceSupport implements
} }
private void fixObjectReferences() { private void fixObjectReferences() {
logger.info("Fixing object references...");
for (Long oldRefreshTokenId : refreshTokenToClientRefs.keySet()) { for (Long oldRefreshTokenId : refreshTokenToClientRefs.keySet()) {
String clientRef = refreshTokenToClientRefs.get(oldRefreshTokenId); String clientRef = refreshTokenToClientRefs.get(oldRefreshTokenId);
ClientDetailsEntity client = clientRepository.getClientByClientId(clientRef); ClientDetailsEntity client = clientRepository.getClientByClientId(clientRef);
@ -1230,6 +1198,7 @@ public class MITREidDataService_1_2 extends MITREidDataServiceSupport implements
} }
accessTokenOldToNewIdMap.clear(); accessTokenOldToNewIdMap.clear();
grantOldToNewIdMap.clear(); grantOldToNewIdMap.clear();
logger.info("Done fixing object references.");
} }
} }