Search in sources :

Example 1 with SCIMUserStoreErrorResolver

use of org.wso2.carbon.identity.scim2.common.extenstion.SCIMUserStoreErrorResolver in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class SCIMCommonComponent method activate.

@Activate
protected void activate(ComponentContext ctx) {
    try {
        String filePath = IdentityUtil.getIdentityConfigDirPath() + File.separator + SCIMCommonConstants.CHARON_CONFIG_NAME;
        SCIMConfigProcessor scimConfigProcessor = SCIMConfigProcessor.getInstance();
        scimConfigProcessor.buildConfigFromFile(filePath);
        // reading user schema extension
        if (Boolean.parseBoolean(scimConfigProcessor.getProperty("user-schema-extension-enabled"))) {
            String schemaFilePath = CarbonUtils.getCarbonConfigDirPath() + File.separator + SCIMConfigConstants.SCIM_SCHEMA_EXTENSION_CONFIG;
            SCIMUserSchemaExtensionBuilder.getInstance().buildUserSchemaExtension(schemaFilePath);
        }
        // If custom schema is enabled, read it root attribute URI from the file config if it is configured.
        if (SCIMCommonUtils.isCustomSchemaEnabled()) {
            SCIMCustomSchemaExtensionBuilder.getInstance().setURI(SCIMCommonUtils.getCustomSchemaURI());
        }
        // register UserOperationEventListener implementation
        SCIMUserOperationListener scimUserOperationListener = new SCIMUserOperationListener();
        userOperationEventListenerServiceReg = ctx.getBundleContext().registerService(UserOperationEventListener.class, scimUserOperationListener, null);
        // register scimTenantMgtListener implementation
        SCIMTenantMgtListener scimTenantMgtListener = new SCIMTenantMgtListener();
        tenantMgtListenerServiceReg = ctx.getBundleContext().registerService(TenantMgtListener.class, scimTenantMgtListener, null);
        // Register claim operation event handler implementation.
        ctx.getBundleContext().registerService(AbstractEventHandler.class.getName(), new SCIMClaimOperationEventHandler(), null);
        if (logger.isDebugEnabled()) {
            logger.debug("SCIMClaimOperationEventHandler is successfully registered.");
        }
        // Register default implementation of SCIMUserStoreErrorResolver
        ctx.getBundleContext().registerService(SCIMUserStoreErrorResolver.class.getName(), new DefaultSCIMUserStoreErrorResolver(), null);
        // Register default implementation of SCIMGroupResolver.
        ctx.getBundleContext().registerService(GroupResolver.class.getName(), new SCIMGroupResolver(), null);
        // Update super tenant user/group attributes.
        AdminAttributeUtil.updateAdminUser(MultitenantConstants.SUPER_TENANT_ID, true);
        AdminAttributeUtil.updateAdminGroup(MultitenantConstants.SUPER_TENANT_ID);
        if (logger.isDebugEnabled()) {
            logger.debug("SCIM Common component activated successfully.");
        }
    } catch (CharonException e) {
        logger.error("Error in reading information from identity tables at SCIMCommonComponentStartup.", e);
    } catch (InternalErrorException e) {
        logger.error("Error in reading information from identity tables at SCIMCommonComponentStartup.", e);
    }
}
Also used : UserOperationEventListener(org.wso2.carbon.user.core.listener.UserOperationEventListener) SCIMUserOperationListener(org.wso2.carbon.identity.scim2.common.listener.SCIMUserOperationListener) InternalErrorException(org.wso2.charon3.core.exceptions.InternalErrorException) SCIMConfigProcessor(org.wso2.carbon.identity.scim2.common.utils.SCIMConfigProcessor) SCIMTenantMgtListener(org.wso2.carbon.identity.scim2.common.listener.SCIMTenantMgtListener) TenantMgtListener(org.wso2.carbon.stratos.common.listeners.TenantMgtListener) SCIMTenantMgtListener(org.wso2.carbon.identity.scim2.common.listener.SCIMTenantMgtListener) DefaultSCIMUserStoreErrorResolver(org.wso2.carbon.identity.scim2.common.impl.DefaultSCIMUserStoreErrorResolver) SCIMUserStoreErrorResolver(org.wso2.carbon.identity.scim2.common.extenstion.SCIMUserStoreErrorResolver) AbstractEventHandler(org.wso2.carbon.identity.event.handler.AbstractEventHandler) SCIMClaimOperationEventHandler(org.wso2.carbon.identity.scim2.common.handlers.SCIMClaimOperationEventHandler) SCIMGroupResolver(org.wso2.carbon.identity.scim2.common.listener.SCIMGroupResolver) SCIMGroupResolver(org.wso2.carbon.identity.scim2.common.listener.SCIMGroupResolver) GroupResolver(org.wso2.carbon.user.core.listener.GroupResolver) CharonException(org.wso2.charon3.core.exceptions.CharonException) DefaultSCIMUserStoreErrorResolver(org.wso2.carbon.identity.scim2.common.impl.DefaultSCIMUserStoreErrorResolver) Activate(org.osgi.service.component.annotations.Activate)

Example 2 with SCIMUserStoreErrorResolver

use of org.wso2.carbon.identity.scim2.common.extenstion.SCIMUserStoreErrorResolver in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class SCIMUserManager method resolveError.

/**
 * Iterate through the registered error resolver implementations and try to resolve the error.
 * If couldn't resolve, default CharonException will be returned with 500 Status code.
 *
 * @param e User store exception to be resolved.
 * @return Resolved charon exception.
 */
private CharonException resolveError(UserStoreException e, String defaultMsg) {
    if (log.isDebugEnabled()) {
        log.debug(e);
    }
    for (SCIMUserStoreErrorResolver resolver : SCIMCommonComponentHolder.getScimUserStoreErrorResolverList()) {
        SCIMUserStoreException scimUserStoreException = resolver.resolve(e);
        if (scimUserStoreException != null) {
            CharonException charonException = new CharonException();
            charonException.setDetail(scimUserStoreException.getMessage());
            charonException.setStatus(scimUserStoreException.getHttpStatusCode());
            return charonException;
        }
    }
    // If all resolvers failed to resolve, log error and throw 500 status error.
    log.error(defaultMsg, e);
    return new CharonException(defaultMsg, e);
}
Also used : SCIMUserStoreErrorResolver(org.wso2.carbon.identity.scim2.common.extenstion.SCIMUserStoreErrorResolver) SCIMUserStoreException(org.wso2.carbon.identity.scim2.common.extenstion.SCIMUserStoreException) CharonException(org.wso2.charon3.core.exceptions.CharonException)

Example 3 with SCIMUserStoreErrorResolver

use of org.wso2.carbon.identity.scim2.common.extenstion.SCIMUserStoreErrorResolver in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class SCIMUserManagerTest method testGetUserWithInvalidUserID.

@Test(expectedExceptions = AbstractCharonException.class, dataProvider = "exceptionHandlingConfigurations")
public void testGetUserWithInvalidUserID(Boolean isNotifyUserstoreStatusEnabled) throws Exception {
    String userId = "12345";
    Map<String, Boolean> requiredAttributes = new HashMap<>();
    Map<String, String> scimToLocalClaimsMap = new HashMap<>();
    scimToLocalClaimsMap.put(SCIMConstants.CommonSchemaConstants.ID_URI, USERID_LOCAL_CLAIM);
    mockStatic(SCIMCommonUtils.class);
    when(SCIMCommonUtils.getSCIMtoLocalMappings()).thenReturn(scimToLocalClaimsMap);
    when(SCIMCommonUtils.isNotifyUserstoreStatusEnabled()).thenReturn(isNotifyUserstoreStatusEnabled);
    SCIMUserManager scimUserManager = new SCIMUserManager(mockedUserStoreManager, mockClaimMetadataManagementService, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
    UserStoreException e = new UserStoreException("30007 - UserNotFound: User 12345 does not exist in: PRIMARY");
    when(mockedUserStoreManager.getUserWithID(anyString(), any(), anyString())).thenThrow(e);
    List<SCIMUserStoreErrorResolver> scimUserStoreErrorResolvers = new ArrayList<>();
    SCIMUserStoreErrorResolver scimUserStoreErrorResolver = new DefaultSCIMUserStoreErrorResolver();
    scimUserStoreErrorResolvers.add(scimUserStoreErrorResolver);
    mockStatic(SCIMCommonComponentHolder.class);
    when(SCIMCommonComponentHolder.getScimUserStoreErrorResolverList()).thenReturn(scimUserStoreErrorResolvers);
    scimUserManager.getUser(userId, requiredAttributes);
// This method is for testing of throwing CharonException, hence no assertion.
}
Also used : SCIMUserStoreErrorResolver(org.wso2.carbon.identity.scim2.common.extenstion.SCIMUserStoreErrorResolver) HashMap(java.util.HashMap) UserStoreException(org.wso2.carbon.user.core.UserStoreException) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

SCIMUserStoreErrorResolver (org.wso2.carbon.identity.scim2.common.extenstion.SCIMUserStoreErrorResolver)3 CharonException (org.wso2.charon3.core.exceptions.CharonException)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Matchers.anyBoolean (org.mockito.Matchers.anyBoolean)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Activate (org.osgi.service.component.annotations.Activate)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 Test (org.testng.annotations.Test)1 AbstractEventHandler (org.wso2.carbon.identity.event.handler.AbstractEventHandler)1 SCIMUserStoreException (org.wso2.carbon.identity.scim2.common.extenstion.SCIMUserStoreException)1 SCIMClaimOperationEventHandler (org.wso2.carbon.identity.scim2.common.handlers.SCIMClaimOperationEventHandler)1 DefaultSCIMUserStoreErrorResolver (org.wso2.carbon.identity.scim2.common.impl.DefaultSCIMUserStoreErrorResolver)1 SCIMGroupResolver (org.wso2.carbon.identity.scim2.common.listener.SCIMGroupResolver)1 SCIMTenantMgtListener (org.wso2.carbon.identity.scim2.common.listener.SCIMTenantMgtListener)1 SCIMUserOperationListener (org.wso2.carbon.identity.scim2.common.listener.SCIMUserOperationListener)1 SCIMConfigProcessor (org.wso2.carbon.identity.scim2.common.utils.SCIMConfigProcessor)1 TenantMgtListener (org.wso2.carbon.stratos.common.listeners.TenantMgtListener)1 UserStoreException (org.wso2.carbon.user.core.UserStoreException)1 GroupResolver (org.wso2.carbon.user.core.listener.GroupResolver)1