use of org.wso2.carbon.identity.oauth.ciba.exceptions.CibaCoreException in project identity-inbound-auth-oauth by wso2-extensions.
the class CibaMgtDAOImpl method persistAuthenticationSuccess.
@Override
public void persistAuthenticationSuccess(String authCodeKey, AuthenticatedUser authenticatedUser) throws CibaCoreException {
// Obtain authenticated identity provider's identifier.
String authenticatedIDP = OAuth2Util.getAuthenticatedIDP(authenticatedUser);
try (Connection connection = IdentityDatabaseUtil.getDBConnection(true)) {
try (PreparedStatement prepStmt = connection.prepareStatement(SQLQueries.CibaSQLQueries.UPDATE_AUTHENTICATION_SUCCESS)) {
int authenticatedTenant = OAuth2Util.getTenantId(authenticatedUser.getTenantDomain());
prepStmt.setString(1, authenticatedUser.getUserName());
prepStmt.setString(2, authenticatedUser.getUserStoreDomain());
prepStmt.setInt(3, authenticatedTenant);
prepStmt.setString(4, authenticatedIDP);
prepStmt.setInt(5, authenticatedTenant);
prepStmt.setString(6, AuthReqStatus.AUTHENTICATED.toString());
prepStmt.setString(7, authCodeKey);
prepStmt.execute();
IdentityDatabaseUtil.commitTransaction(connection);
if (log.isDebugEnabled()) {
log.debug("Successfully updated the authentication request status to 'AUTHENTICATED' for the " + "request identified by authCodeKey: " + authCodeKey);
}
} catch (SQLException | IdentityOAuth2Exception e) {
IdentityDatabaseUtil.rollbackTransaction(connection);
throw new CibaCoreException("Error occurred in persisting the successful authentication identified by" + " authCodeKey: " + authCodeKey, e);
}
} catch (SQLException e) {
throw new CibaCoreException("Error occurred in persisting the successful authentication identified by " + "authCodeKey: " + authCodeKey, e);
}
}
use of org.wso2.carbon.identity.oauth.ciba.exceptions.CibaCoreException in project identity-inbound-auth-oauth by wso2-extensions.
the class CibaMgtDAOImpl method persistCibaAuthCode.
@Override
public void persistCibaAuthCode(CibaAuthCodeDO cibaAuthCodeDO) throws CibaCoreException {
try (Connection connection = IdentityDatabaseUtil.getDBConnection(true)) {
try (PreparedStatement prepStmt = connection.prepareStatement(SQLQueries.CibaSQLQueries.STORE_CIBA_AUTH_CODE)) {
prepStmt.setString(1, cibaAuthCodeDO.getCibaAuthCodeKey());
prepStmt.setString(2, cibaAuthCodeDO.getAuthReqId());
prepStmt.setString(3, cibaAuthCodeDO.getConsumerKey());
prepStmt.setTimestamp(4, cibaAuthCodeDO.getIssuedTime(), Calendar.getInstance(TimeZone.getTimeZone(CibaConstants.UTC)));
prepStmt.setTimestamp(5, cibaAuthCodeDO.getLastPolledTime(), Calendar.getInstance(TimeZone.getTimeZone(CibaConstants.UTC)));
prepStmt.setLong(6, cibaAuthCodeDO.getInterval());
prepStmt.setLong(7, cibaAuthCodeDO.getExpiresIn());
prepStmt.setString(8, cibaAuthCodeDO.getAuthReqStatus().toString());
prepStmt.execute();
if (log.isDebugEnabled()) {
log.debug("Successfully persisted cibaAuthCodeDO for unique CibaAuthCodeKey : " + cibaAuthCodeDO.getCibaAuthCodeKey());
}
} catch (SQLException e) {
IdentityDatabaseUtil.rollbackTransaction(connection);
throw new CibaCoreException("Error occurred while persisting cibaAuthCode for the application with " + "consumer key: " + cibaAuthCodeDO.getConsumerKey() + " and with authCodeKey: " + cibaAuthCodeDO.getCibaAuthCodeKey(), e);
}
try (PreparedStatement prepStmtForScope = connection.prepareStatement(SQLQueries.CibaSQLQueries.STORE_SCOPES)) {
for (String singleScopeValue : cibaAuthCodeDO.getScopes()) {
prepStmtForScope.setString(1, cibaAuthCodeDO.getCibaAuthCodeKey());
prepStmtForScope.setString(2, singleScopeValue);
prepStmtForScope.addBatch();
}
prepStmtForScope.executeBatch();
if (log.isDebugEnabled()) {
log.debug("Successfully persisted scopes for unique authCodeKey : " + cibaAuthCodeDO.getCibaAuthCodeKey());
}
} catch (SQLException e) {
IdentityDatabaseUtil.rollbackTransaction(connection);
throw new CibaCoreException("Error occurred while persisting scopes for the application with " + "consumer key: " + cibaAuthCodeDO.getConsumerKey() + " and with authCodeKey: " + cibaAuthCodeDO.getCibaAuthCodeKey(), e);
}
IdentityDatabaseUtil.commitTransaction(connection);
} catch (SQLException e) {
throw new CibaCoreException("Error occurred while persisting cibaAuthCode for the application with " + "consumer key: " + cibaAuthCodeDO.getConsumerKey() + " and with authCodeKey: " + cibaAuthCodeDO.getCibaAuthCodeKey(), e);
}
}
use of org.wso2.carbon.identity.oauth.ciba.exceptions.CibaCoreException in project identity-inbound-auth-oauth by wso2-extensions.
the class CibaMgtDAOImpl method updateStatus.
@Override
public void updateStatus(String authCodeKey, Enum authenticationStatus) throws CibaCoreException {
try (Connection connection = IdentityDatabaseUtil.getDBConnection(true)) {
try (PreparedStatement prepStmt = connection.prepareStatement(SQLQueries.CibaSQLQueries.UPDATE_AUTHENTICATION_STATUS)) {
prepStmt.setString(1, authenticationStatus.toString());
prepStmt.setString(2, authCodeKey);
prepStmt.execute();
IdentityDatabaseUtil.commitTransaction(connection);
if (log.isDebugEnabled()) {
log.debug("Successfully persisted the authentication status: " + authenticationStatus + " identified by authCodeKey: " + authCodeKey);
}
} catch (SQLException e) {
IdentityDatabaseUtil.rollbackTransaction(connection);
throw new CibaCoreException("Error occurred in persisting authentication status for the authCodeKey: " + authCodeKey, e);
}
} catch (SQLException e) {
throw new CibaCoreException("Error occurred in persisting authentication status for the authCodeKey: " + authCodeKey, e);
}
}
use of org.wso2.carbon.identity.oauth.ciba.exceptions.CibaCoreException in project identity-inbound-auth-oauth by wso2-extensions.
the class CibaGrantHandler method issue.
@Override
public OAuth2AccessTokenRespDTO issue(OAuthTokenReqMessageContext tokReqMsgCtx) throws IdentityOAuth2Exception {
OAuth2AccessTokenRespDTO responseDTO = super.issue(tokReqMsgCtx);
String authReqId = getAuthReqId(tokReqMsgCtx);
CibaAuthCodeDO cibaAuthCodeDO = retrieveCibaAuthCode(authReqId);
try {
CibaDAOFactory.getInstance().getCibaAuthMgtDAO().updateStatus(cibaAuthCodeDO.getCibaAuthCodeKey(), AuthReqStatus.TOKEN_ISSUED);
if (log.isDebugEnabled()) {
log.debug("Successfully updated the status of authentication request made by client:" + tokReqMsgCtx.getOauth2AccessTokenReqDTO().getClientId());
}
} catch (CibaCoreException e) {
throw new IdentityOAuth2Exception("Error occurred in persisting status for the request made with " + "auth_req_id: " + authReqId, e);
}
return responseDTO;
}
use of org.wso2.carbon.identity.oauth.ciba.exceptions.CibaCoreException in project identity-inbound-auth-oauth by wso2-extensions.
the class CibaGrantHandler method retrieveCibaAuthCode.
/**
* Validates whether provided auth_req_id exists in and return AuthCode if exists.
*
* @param authReqId Authentication Request Identifier.
* @throws IdentityOAuth2Exception
*/
private CibaAuthCodeDO retrieveCibaAuthCode(String authReqId) throws IdentityOAuth2Exception {
try {
String authCodeKey = CibaDAOFactory.getInstance().getCibaAuthMgtDAO().getCibaAuthCodeKey(authReqId);
if (StringUtils.isBlank(authCodeKey)) {
if (log.isDebugEnabled()) {
log.debug("Provided auth_req_id : " + authReqId + " with the token request is not valid.Or not issued by Identity server.");
}
throw new IdentityOAuth2Exception(INVALID_AUTH_REQ_ID);
}
CibaAuthCodeDO cibaAuthCodeDO = CibaDAOFactory.getInstance().getCibaAuthMgtDAO().getCibaAuthCode(authCodeKey);
if (cibaAuthCodeDO.getAuthReqStatus().equals(AuthReqStatus.AUTHENTICATED)) {
// Retrieve scopes.
List<String> scope = CibaDAOFactory.getInstance().getCibaAuthMgtDAO().getScopes(cibaAuthCodeDO.getCibaAuthCodeKey());
cibaAuthCodeDO.setScopes(scope.toArray(new String[scope.size()]));
// Retrieve authenticated user.
AuthenticatedUser authenticatedUser = CibaDAOFactory.getInstance().getCibaAuthMgtDAO().getAuthenticatedUser(cibaAuthCodeDO.getCibaAuthCodeKey());
cibaAuthCodeDO.setAuthenticatedUser(authenticatedUser);
}
return cibaAuthCodeDO;
} catch (CibaCoreException e) {
throw new IdentityOAuth2Exception(INVALID_AUTH_REQ_ID, e);
}
}
Aggregations