use of org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementException in project carbon-identity-framework by wso2.
the class UserFunctionalityManagerImpl method getLockStatus.
/**
* {@inheritDoc}
*/
@Override
public FunctionalityLockStatus getLockStatus(String userId, int tenantId, String functionalityIdentifier) throws UserFunctionalityManagementException {
if (!isPerUserFunctionalityLockingEnabled()) {
throw new UnsupportedOperationException("Per-user functionality locking is not enabled.");
}
if (StringUtils.isEmpty(userId) || !isUserIdExists(userId, tenantId)) {
if (log.isDebugEnabled()) {
log.debug("Cannot retrieve user from userId: " + userId);
}
throw buildUserNotFoundError();
}
FunctionalityLockStatus functionalityLockStatus = userFunctionalityManagerDAO.getFunctionalityLockStatus(userId, tenantId, functionalityIdentifier);
if (functionalityLockStatus == null) {
return FunctionalityLockStatus.UNLOCKED_STATUS;
}
long unlockTime = functionalityLockStatus.getUnlockTime();
if (unlockTime < System.currentTimeMillis()) {
userFunctionalityManagerDAO.deleteMappingForUser(userId, tenantId, functionalityIdentifier);
return FunctionalityLockStatus.UNLOCKED_STATUS;
}
return functionalityLockStatus;
}
use of org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementException in project carbon-identity-framework by wso2.
the class UserFunctionalityManagerImplTest method testLockFunctionalityForUser.
@Test(dataProvider = "LockFunctionalityForUserData")
public void testLockFunctionalityForUser(String functionalityIdentifier, String userId, int tenantId, boolean expected) {
DataSource dataSource = mock(DataSource.class);
TestUtils.mockDataSource(dataSource);
long functionalityUnlockTime = System.currentTimeMillis() + 300000;
String functionalityLockReasonCode = "Lock code";
String functionalityLockReason = "Lock Reason 2";
try {
try (Connection connection = TestUtils.getConnection()) {
Connection spyConnection = TestUtils.spyConnection(connection);
when(dataSource.getConnection()).thenReturn(spyConnection);
try {
mockIsUserStoreManager(userId);
userFunctionalityManager.lock(userId, tenantId, functionalityIdentifier, functionalityUnlockTime, functionalityLockReasonCode, functionalityLockReason);
assertEquals(userFunctionalityManager.getLockStatus(userId, tenantId, functionalityIdentifier).getLockStatus(), expected);
assertEquals(userFunctionalityManager.getLockStatus(userId, tenantId, functionalityIdentifier).getLockReason(), functionalityLockReason);
} catch (UserFunctionalityManagementException e) {
log.error(String.format("Error while selecting functionality: %s", functionalityIdentifier), e);
} catch (UserStoreException e) {
log.error("Error while checking userid in userstore", e);
}
}
} catch (SQLException e) {
log.error("SQL Exception", e);
}
}
use of org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementException in project carbon-identity-framework by wso2.
the class UserFunctionalityManagerImplTest method testUnlockFunctionalityForUser.
@Test(dataProvider = "UnlockFunctionalityForUserData")
public void testUnlockFunctionalityForUser(String functionalityIdentifier, String userId, int tenantId, boolean isFunctionalityLocked) {
DataSource dataSource = mock(DataSource.class);
TestUtils.mockDataSource(dataSource);
try {
try (Connection connection = TestUtils.getConnection()) {
Connection spyConnection = TestUtils.spyConnection(connection);
when(dataSource.getConnection()).thenReturn(spyConnection);
try {
mockIsUserStoreManager(userId);
assertEquals(userFunctionalityManager.getLockStatus(userId, tenantId, functionalityIdentifier).getLockStatus(), isFunctionalityLocked);
userFunctionalityManager.unlock(userId, tenantId, functionalityIdentifier);
assertEquals(userFunctionalityManager.getLockStatus(userId, tenantId, functionalityIdentifier).getLockStatus(), false);
} catch (UserFunctionalityManagementException e) {
log.error(String.format("Error while selecting functionality: %s", functionalityIdentifier), e);
} catch (UserStoreException e) {
log.error("Error while checking userid in userstore", e);
}
}
} catch (SQLException e) {
log.error("SQL Exception", e);
}
}
use of org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementException in project carbon-identity-framework by wso2.
the class UserFunctionalityPropertyDAOImplTest method testDeleteAllFunctionalityLockProperties.
@Test(dataProvider = "TestFunctionalityLockPropertiesData")
public void testDeleteAllFunctionalityLockProperties(String userId, int tenantId, String functionalityIdentifier, Map<String, String> properties) {
DataSource dataSource = mock(DataSource.class);
mockDataSource(dataSource);
try (Connection connection = getConnection()) {
Connection spyConnection = spyConnection(connection);
when(dataSource.getConnection()).thenReturn(spyConnection);
mockUser(userId);
userFunctionalityManager.setProperties(userId, tenantId, functionalityIdentifier, properties);
userFunctionalityPropertyDAO.deleteAllPropertiesForUser(userId, tenantId, functionalityIdentifier);
Map<String, String> functionalityLockProperties = userFunctionalityPropertyDAO.getAllProperties(userId, tenantId, functionalityIdentifier);
assertTrue(functionalityLockProperties.isEmpty());
} catch (SQLException | UserFunctionalityManagementException | UserStoreException e) {
// Mock behaviour. Hence ignored.
}
}
use of org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementException in project carbon-identity-framework by wso2.
the class UserFunctionalityManagerImplTest method testGetFunctionalityLockReasonForUser.
@Test(dataProvider = "FunctionalityLockedReasonData")
public void testGetFunctionalityLockReasonForUser(String functionalityIdentifier, String userId, int tenantId, String expected) {
DataSource dataSource = mock(DataSource.class);
TestUtils.mockDataSource(dataSource);
try {
try (Connection connection = TestUtils.getConnection()) {
Connection spyConnection = TestUtils.spyConnection(connection);
when(dataSource.getConnection()).thenReturn(spyConnection);
try {
mockIsUserStoreManager(userId);
assertEquals(userFunctionalityManager.getLockStatus(userId, tenantId, functionalityIdentifier).getLockReason(), expected);
} catch (UserFunctionalityManagementException e) {
log.error(String.format("Error while selecting functionality: %s", functionalityIdentifier), e);
} catch (UserStoreException e) {
log.error("Error while checking userid in userstore", e);
}
}
} catch (SQLException e) {
log.error("SQL Exception", e);
}
}
Aggregations