Skip to content

Commit

Permalink
LPD-40120 SF - Match to SYZ's code for better readability and perform…
Browse files Browse the repository at this point in the history
…ance
  • Loading branch information
ChrisKian authored and brianchandotcom committed Nov 7, 2024
1 parent 7327eee commit d7c166c
Showing 1 changed file with 24 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.liferay.oauth2.provider.model.OAuth2Authorization;
import com.liferay.oauth2.provider.model.OAuth2ScopeGrant;
import com.liferay.oauth2.provider.scope.liferay.LiferayOAuth2Scope;
import com.liferay.oauth2.provider.service.OAuth2AuthorizationLocalService;
import com.liferay.oauth2.provider.service.base.OAuth2ScopeGrantLocalServiceBaseImpl;
import com.liferay.portal.aop.AopService;
import com.liferay.portal.kernel.exception.PortalException;
Expand All @@ -23,7 +22,6 @@

import org.osgi.framework.Bundle;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

/**
* @author Brian Wing Shun Chan
Expand Down Expand Up @@ -118,42 +116,35 @@ public Collection<OAuth2ScopeGrant> getOAuth2ScopeGrants(
long companyId, String applicationName, String bundleSymbolicName,
String accessTokenContent) {

List<OAuth2Authorization> oAuth2Authorizations =
oAuth2AuthorizationPersistence.findByC_ATCH(
companyId, accessTokenContent.hashCode());
List<OAuth2ScopeGrant> oAuth2ScopeGrants = new ArrayList<>();

if (oAuth2Authorizations.isEmpty()) {
return Collections.emptyList();
}
for (OAuth2Authorization oAuth2Authorization :
oAuth2AuthorizationPersistence.findByC_ATCH(
companyId, accessTokenContent.hashCode())) {

List<OAuth2ScopeGrant> oAuth2ScopeGrants = new ArrayList<>();
if (!Objects.equals(
accessTokenContent,
oAuth2Authorization.getAccessTokenContent())) {

oAuth2Authorizations.forEach(
oAuth2Authorization -> {
if (!Objects.equals(
oAuth2Authorization.getAccessTokenContent(),
accessTokenContent)) {
continue;
}

return;
}
for (OAuth2ScopeGrant oAuth2ScopeGrant :
oAuth2ScopeGrantPersistence.
getOAuth2AuthorizationOAuth2ScopeGrants(
oAuth2Authorization.getPrimaryKey())) {

oAuth2ScopeGrantPersistence.
getOAuth2AuthorizationOAuth2ScopeGrants(
oAuth2Authorization.getOAuth2AuthorizationId()
).forEach(
oAuth2ScopeGrant -> {
if (Objects.equals(
oAuth2ScopeGrant.getApplicationName(),
applicationName) &&
Objects.equals(
oAuth2ScopeGrant.getBundleSymbolicName(),
bundleSymbolicName)) {

oAuth2ScopeGrants.add(oAuth2ScopeGrant);
}
}
);
});
if (Objects.equals(
applicationName,
oAuth2ScopeGrant.getApplicationName()) &&
Objects.equals(
bundleSymbolicName,
oAuth2ScopeGrant.getBundleSymbolicName())) {

oAuth2ScopeGrants.add(oAuth2ScopeGrant);
}
}
}

return oAuth2ScopeGrants;
}
Expand Down Expand Up @@ -221,7 +212,4 @@ private boolean _isMatch(
return true;
}

@Reference
private OAuth2AuthorizationLocalService _oAuth2AuthorizationLocalService;

}

0 comments on commit d7c166c

Please sign in to comment.