Skip to content

Commit

Permalink
INTGW-584 -reformatting the code
Browse files Browse the repository at this point in the history
  • Loading branch information
SkNuwanTissera authored and jaadds committed Jun 28, 2019
1 parent a6f8a40 commit cc11072
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@
import org.wso2.carbon.user.core.common.AbstractUserOperationEventListener;

/**
*
* Generate a new Access Token on Password Reset
* **This Event Listener executes before IdentityMgtEventListener **
*
*/
public class TokenRegenerationEventListener extends AbstractUserOperationEventListener {

Expand All @@ -53,8 +51,9 @@ public int getExecutionOrderId() {

/**
* Refresh token on password reset
* @param userName username
* @param credential password
*
* @param userName username
* @param credential password
* @param userStoreManager userStoreManager
* @return true
* @throws UserStoreException
Expand All @@ -64,7 +63,7 @@ public boolean doPostUpdateCredential(String userName, Object credential, UserSt

if (log.isDebugEnabled()) {
log.debug("Executing TokenRegenerationEventListener");
log.debug("Username : "+ userName);
log.debug("Username : " + userName);
}

String threadLocalUsername = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
Expand All @@ -75,7 +74,7 @@ public boolean doPostUpdateCredential(String userName, Object credential, UserSt
startTenantFlow(userName);

if (log.isDebugEnabled()) {
log.debug("Fetching application details for "+userName);
log.debug("Fetching application details for " + userName);
}

OAuthConsumerAppDTO[] oauthApps = new OAuthAdminService().getAllOAuthApplicationData();
Expand All @@ -84,32 +83,32 @@ public boolean doPostUpdateCredential(String userName, Object credential, UserSt
OAuth2AccessTokenReqDTO tokenReqDTO = new OAuth2AccessTokenReqDTO();
tokenReqDTO.setGrantType(GRANT_TYPE);

if(oauthApps.length > 0) {
if (oauthApps.length > 0) {
issueAccessToken(userName, tokenReqDTO, oauthApps[0]);
} else {
if (log.isDebugEnabled()) {
log.debug("No Application Found for User: "+userName);
log.debug("No Application Found for User: " + userName);
}
}
}
}
} catch (IdentityOAuthAdminException e) {
log.error("Error while Fetching application details ", e);
} finally {
endTenantFlow(threadLocalUsername, threadTenantDomain,tenantId);
endTenantFlow(threadLocalUsername, threadTenantDomain, tenantId);
}

return true;
}

private void issueAccessToken(String userName, OAuth2AccessTokenReqDTO tokenReqDTO, OAuthConsumerAppDTO oauthapp) {

final String scope = DataHolder.getInstance().getApiManagerConfigurationService().getAPIManagerConfiguration().getFirstProperty(APIConstants.
final String scope = DataHolder.getInstance().getApiManagerConfigurationService().getAPIManagerConfiguration().getFirstProperty(APIConstants.
APPLICATION_TOKEN_SCOPE);

final String[] applicationScope = new String[] {scope};
final String[] applicationScope = new String[]{scope};

RequestParameter[] requestParameters = new RequestParameter[1];
RequestParameter requestParameter = new RequestParameter(VALIDITY_PERIOD_KEY,VALIDITY_PERIOD_VALUE);
RequestParameter requestParameter = new RequestParameter(VALIDITY_PERIOD_KEY, VALIDITY_PERIOD_VALUE);
tokenReqDTO.setClientId(oauthapp.getOauthConsumerKey());
tokenReqDTO.setClientSecret(oauthapp.getOauthConsumerSecret());
tokenReqDTO.setCallbackURI(oauthapp.getCallbackUrl());
Expand All @@ -119,9 +118,9 @@ private void issueAccessToken(String userName, OAuth2AccessTokenReqDTO tokenReqD

if (log.isDebugEnabled()) {
log.debug("Application Details Fetched Successfully \n" +
"Application name: "+ oauthapp.getApplicationName() + "\n" +
"Consumer_key: "+ oauthapp.getOauthConsumerKey() + "\n" +
"Consumer_secret: "+ oauthapp.getOauthConsumerSecret()
"Application name: " + oauthapp.getApplicationName() + "\n" +
"Consumer_key: " + oauthapp.getOauthConsumerKey() + "\n" +
"Consumer_secret: " + oauthapp.getOauthConsumerSecret()
);
}

Expand All @@ -130,17 +129,17 @@ private void issueAccessToken(String userName, OAuth2AccessTokenReqDTO tokenReqD
tokenReqDTO.setRequestParameters(requestParameters);
OAuth2Service service = (OAuth2Service) PrivilegedCarbonContext.getThreadLocalCarbonContext()
.getOSGiService(OAuth2Service.class);
if(log.isDebugEnabled()) {
log.debug("Starting to issue AccessToken for User "+userName);
if (log.isDebugEnabled()) {
log.debug("Starting to issue AccessToken for User " + userName);
}

tokenReqDTO.setoAuthClientAuthnContext(getOAuthClientAuthnContext(oauthapp));

OAuth2AccessTokenRespDTO oAuth2AccessTokenRespDTO = service.issueAccessToken(tokenReqDTO);

if (log.isDebugEnabled()) {
log.debug("Generated Access Token :" +oAuth2AccessTokenRespDTO.getAccessToken());
}
log.debug("Generated Access Token :" + oAuth2AccessTokenRespDTO.getAccessToken());
}
}

private OAuthClientAuthnContext getOAuthClientAuthnContext(OAuthConsumerAppDTO oauthapp) {
Expand All @@ -166,6 +165,7 @@ private void startTenantFlow(String userName) {

/**
* Executing doPostUpdateCredential method for obtaining new access token
*
* @param userName
* @param credential
* @param userStoreManager
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@

Patch Information:
-----------

Patch ID : WSO2Telco-MIG-2.2.0-00106
Applies To : wso2telcoids-2.2.0
Associated JIRA : https://jira.wso2telco.com/jira/browse/MCSDDEV-173

DESCRIPTION
-----------

This patch includes the fix to avoid entering username as part of the password field during signup process [API STORE]
This avoid entering username as part of the password field during signup process [API STORE]


CONFIGURATIONS & INSTALLATION INSTRUCTIONS
Expand Down

0 comments on commit cc11072

Please sign in to comment.