Search in sources :

Example 26 with IdentityException

use of org.wso2.carbon.identity.base.IdentityException in project carbon-identity-framework by wso2.

the class ThriftAuthenticatorServiceImpl method addThriftSession.

private void addThriftSession(ThriftSession thriftSession) throws IdentityException {
    // add to cache
    authenticatedSessions.put(thriftSession.getSessionId(), thriftSession);
    // add to database
    ThriftSessionDAO sessionDAO = this.thriftSessionDAO.getInstance();
    sessionDAO.addSession(thriftSession);
}
Also used : ThriftSessionDAO(org.wso2.carbon.identity.thrift.authentication.dao.ThriftSessionDAO)

Example 27 with IdentityException

use of org.wso2.carbon.identity.base.IdentityException in project carbon-identity-framework by wso2.

the class DBThriftSessionDAO method getSession.

@Override
public ThriftSession getSession(String sessionId) throws IdentityException {
    Connection connection = null;
    PreparedStatement prepStmt = null;
    ResultSet rSet = null;
    ThriftSession thriftSession = new ThriftSession();
    try {
        connection = ThriftAuthenticationDatabaseUtil.getDBConnection(false);
        prepStmt = connection.prepareStatement(ThriftAuthenticationConstants.GET_THRIFT_SESSION_SQL);
        prepStmt.setString(1, sessionId);
        rSet = prepStmt.executeQuery();
        while (rSet.next()) {
            if (rSet.getString(1) != null && rSet.getString(1).length() > 0) {
                thriftSession.setSessionId(rSet.getString(1));
                thriftSession.setUserName(rSet.getString(2));
                thriftSession.setCreatedAt(rSet.getLong(3));
                thriftSession.setLastAccess(rSet.getLong(4));
            }
        }
    } catch (AuthenticationException e) {
        String errorMsg = ERROR_WHEN_GETTING_AN_IDENTITY_PERSISTENCE_STORE_INSTANCE;
        log.error(errorMsg, e);
        throw IdentityException.error(errorMsg, e);
    } catch (SQLException e) {
        log.error(ERROR_WHEN_EXECUTING_THE_SQL + " " + ThriftAuthenticationConstants.GET_THRIFT_SESSION_SQL);
        log.error(e.getMessage(), e);
        throw IdentityException.error("Error when reading the Thrift session information from " + THE_PERSISTENCE_STORE);
    } finally {
        ThriftAuthenticationDatabaseUtil.closeAllConnections(connection, rSet, prepStmt);
    }
    return thriftSession;
}
Also used : AuthenticationException(org.wso2.carbon.identity.thrift.authentication.internal.generatedCode.AuthenticationException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ThriftSession(org.wso2.carbon.utils.ThriftSession) PreparedStatement(java.sql.PreparedStatement)

Example 28 with IdentityException

use of org.wso2.carbon.identity.base.IdentityException in project carbon-identity-framework by wso2.

the class ThriftAuthenticatorServiceImpl method onSuccessLogin.

private void onSuccessLogin(ThriftSession authSession) throws IdentityException {
    PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    try {
        carbonContext.setUsername((String) (authSession.getAttribute(ServerConstants.AUTHENTICATION_SERVICE_USERNAME)));
        carbonContext.setTenantDomain((String) (authSession.getAttribute(MultitenantConstants.TENANT_DOMAIN)));
        carbonContext.setTenantId((Integer) (authSession.getAttribute(MultitenantConstants.TENANT_ID)));
    } catch (Exception e) {
        String authErrorMsg = "Error populating current carbon context from thrift auth session: " + e.getMessage();
        throw IdentityException.error(authErrorMsg);
    }
}
Also used : PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) UserStoreException(org.wso2.carbon.user.api.UserStoreException) AuthenticationException(org.wso2.carbon.identity.thrift.authentication.internal.generatedCode.AuthenticationException) IdentityException(org.wso2.carbon.identity.base.IdentityException)

Example 29 with IdentityException

use of org.wso2.carbon.identity.base.IdentityException in project carbon-identity-framework by wso2.

the class IdentityPersistenceManager method addXmppSettings.

/**
 * Add XMPP settings.
 *
 * @param userId
 * @param xmppServer
 * @param xmppUserName
 * @param xmppUserCode
 * @param enabled
 * @throws IdentityException
 */
public void addXmppSettings(Registry registry, String userId, String xmppServer, String xmppUserName, String xmppUserCode, boolean enabled, boolean isPINEnabled) throws IdentityException {
    XMPPSettingsDAO dao = new XMPPSettingsDAO(registry);
    dao.addXmppSettings(userId, xmppServer, xmppUserName, xmppUserCode, enabled, isPINEnabled);
}
Also used : XMPPSettingsDAO(org.wso2.carbon.identity.core.dao.XMPPSettingsDAO)

Example 30 with IdentityException

use of org.wso2.carbon.identity.base.IdentityException in project carbon-identity-framework by wso2.

the class IdentityPersistenceManager method removeParameter.

/**
 * @param parameterDO
 * @throws IdentityException
 */
public void removeParameter(Registry registry, ParameterDO parameterDO) throws IdentityException {
    ParameterDAO dao = new ParameterDAO(registry);
    dao.removeParameter(parameterDO);
}
Also used : ParameterDAO(org.wso2.carbon.identity.core.dao.ParameterDAO)

Aggregations

IdentityException (org.wso2.carbon.identity.base.IdentityException)132 UserStoreException (org.wso2.carbon.user.api.UserStoreException)62 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)38 Test (org.testng.annotations.Test)37 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)35 HashMap (java.util.HashMap)30 ArrayList (java.util.ArrayList)29 SQLException (java.sql.SQLException)25 Connection (java.sql.Connection)23 IdentityMgtServiceException (org.wso2.carbon.identity.mgt.IdentityMgtServiceException)22 Resource (org.wso2.carbon.registry.core.Resource)22 PreparedStatement (java.sql.PreparedStatement)21 UserDTO (org.wso2.carbon.identity.mgt.dto.UserDTO)20 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)19 ApplicationManagementService (org.wso2.carbon.identity.application.mgt.ApplicationManagementService)18 VerificationBean (org.wso2.carbon.identity.mgt.beans.VerificationBean)18 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)17 DCRDataHolder (org.wso2.carbon.identity.oauth.dcr.internal.DCRDataHolder)17 Map (java.util.Map)15 RecoveryProcessor (org.wso2.carbon.identity.mgt.RecoveryProcessor)15