Search in sources :

Example 96 with AMIdentityRepository

use of com.sun.identity.idm.AMIdentityRepository in project OpenAM by OpenRock.

the class ServicesModelImpl method unassignServices.

/**
     * Unassigns services from realm.
     *
     * @param realmName Name of Realm.
     * @param names Names of services that are to be unassigned.
     * @throws AMConsoleException if services cannot be unassigned.
     */
public void unassignServices(String realmName, Set names) throws AMConsoleException {
    if ((names != null) && !names.isEmpty()) {
        if ((realmName == null) || (realmName.trim().length() == 0)) {
            realmName = "/";
        }
        String[] params = new String[2];
        params[0] = realmName;
        String curServiceName = "";
        try {
            OrganizationConfigManager scm = new OrganizationConfigManager(getUserSSOToken(), realmName);
            AMIdentityRepository repo = new AMIdentityRepository(getUserSSOToken(), realmName);
            AMIdentity realmIdentity = repo.getRealmIdentity();
            Set realmServices = realmIdentity.getAssignedServices();
            for (Iterator iter = names.iterator(); iter.hasNext(); ) {
                String name = (String) iter.next();
                curServiceName = name;
                params[1] = name;
                logEvent("ATTEMPT_UNASSIGN_SERVICE_FROM_REALM", params);
                if (realmServices.contains(name)) {
                    realmIdentity.unassignService(name);
                } else {
                    scm.unassignService(name);
                }
                logEvent("SUCCEED_UNASSIGN_SERVICE_FROM_REALM", params);
            }
        } catch (SMSException e) {
            String strError = getErrorString(e);
            String[] paramsEx = { realmName, curServiceName, strError };
            logEvent("SMS_EXCEPTION_UNASSIGN_SERVICE_FROM_REALM", paramsEx);
            throw new AMConsoleException(strError);
        } catch (SSOException e) {
            String strError = getErrorString(e);
            String[] paramsEx = { realmName, curServiceName, strError };
            logEvent("SSO_EXCEPTION_UNASSIGN_SERVICE_FROM_REALM", paramsEx);
            throw new AMConsoleException(strError);
        } catch (IdRepoException e) {
            String strError = getErrorString(e);
            String[] paramsEx = { realmName, curServiceName, strError };
            logEvent("IDREPO_EXCEPTION_UNASSIGN_SERVICE_FROM_REALM", paramsEx);
            throw new AMConsoleException(strError);
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) SMSException(com.sun.identity.sm.SMSException) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) Iterator(java.util.Iterator) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException)

Example 97 with AMIdentityRepository

use of com.sun.identity.idm.AMIdentityRepository in project OpenAM by OpenRock.

the class ServicesModelImpl method getIdentityServices.

private void getIdentityServices(String realmName, Set names) {
    /*
         * It is ok that administrator such as policy administrator
         * does not have access to AMIdentityRepository. We just ignore it.
         */
    try {
        AMIdentityRepository repo = new AMIdentityRepository(getUserSSOToken(), realmName);
        AMIdentity realmIdentity = repo.getRealmIdentity();
        names.addAll(realmIdentity.getAssignedServices());
    } catch (SSOException e) {
        debug.warning("ServicesModelImpl.getIdentityServices", e);
    } catch (IdRepoException e) {
        debug.warning("ServicesModelImpl.getIdentityServices", e);
    }
}
Also used : AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException)

Example 98 with AMIdentityRepository

use of com.sun.identity.idm.AMIdentityRepository in project OpenAM by OpenRock.

the class ServicesProfileModelImpl method assignService.

/**
     * Assigns service to a realm.
     *
     * @param map Map of attribute name to Set of attribute values.
     * @throws AMConsoleException if values cannot be set.
     */
public void assignService(Map map) throws AMConsoleException {
    String[] params = { currentRealm, serviceName };
    logEvent("ATTEMPT_ASSIGN_SERVICE_TO_REALM", params);
    try {
        AMIdentityRepository repo = new AMIdentityRepository(getUserSSOToken(), currentRealm);
        AMIdentity realmIdentity = repo.getRealmIdentity();
        Set servicesFromIdRepo = realmIdentity.getAssignableServices();
        if (servicesFromIdRepo.contains(serviceName)) {
            realmIdentity.assignService(serviceName, map);
        } else {
            OrganizationConfigManager orgCfgMgr = new OrganizationConfigManager(getUserSSOToken(), currentRealm);
            orgCfgMgr.assignService(serviceName, map);
        }
        logEvent("SUCCEED_ASSIGN_SERVICE_TO_REALM", params);
    } catch (SSOException e) {
        String strError = getErrorString(e);
        String[] paramsEx = { currentRealm, serviceName, strError };
        logEvent("SSO_EXCEPTION_ASSIGN_SERVICE_TO_REALM", paramsEx);
        throw new AMConsoleException(strError);
    } catch (IdRepoException e) {
        String strError = getErrorString(e);
        String[] paramsEx = { currentRealm, serviceName, strError };
        logEvent("IDREPO_EXCEPTION_ASSIGN_SERVICE_TO_REALM", paramsEx);
        throw new AMConsoleException(strError);
    } catch (SMSException e) {
        String strError = getErrorString(e);
        String[] paramsEx = { currentRealm, serviceName, strError };
        logEvent("SMS_EXCEPTION_ASSIGN_SERVICE_TO_REALM", paramsEx);
        throw new AMConsoleException(strError);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) SMSException(com.sun.identity.sm.SMSException) AMIdentity(com.sun.identity.idm.AMIdentity) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException)

Example 99 with AMIdentityRepository

use of com.sun.identity.idm.AMIdentityRepository in project OpenAM by OpenRock.

the class ServicesProfileModelImpl method setAttributes.

/**
     * Set attributes of an service.
     *
     * @param attrValues Map of attribute name to its values.
     * @throws AMConsoleException if values cannot be set.
     */
public void setAttributes(Map attrValues) throws AMConsoleException {
    String[] params = { currentRealm, serviceName };
    logEvent("ATTEMPT_MODIFY_SERVICE_UNDER_REALM", params);
    try {
        AMIdentityRepository repo = new AMIdentityRepository(getUserSSOToken(), currentRealm);
        AMIdentity realmIdentity = repo.getRealmIdentity();
        Set servicesFromIdRepo = realmIdentity.getAssignedServices();
        if (servicesFromIdRepo.contains(serviceName)) {
            realmIdentity.modifyService(serviceName, attrValues);
        } else {
            OrganizationConfigManager orgCfgMgr = new OrganizationConfigManager(getUserSSOToken(), currentRealm);
            orgCfgMgr.modifyService(serviceName, attrValues);
        }
        logEvent("SUCCEED_MODIFY_SERVICE_UNDER_REALM", params);
    } catch (SSOException e) {
        String strError = getErrorString(e);
        String[] paramsEx = { currentRealm, serviceName, strError };
        logEvent("SSO_EXCEPTION_MODIFY_SERVICE_UNDER_REALM", paramsEx);
        throw new AMConsoleException(strError);
    } catch (IdRepoException e) {
        String strError = getErrorString(e);
        String[] paramsEx = { currentRealm, serviceName, strError };
        logEvent("IDREPO_EXCEPTION_MODIFY_SERVICE_UNDER_REALM", paramsEx);
        throw new AMConsoleException(strError);
    } catch (SMSException e) {
        String strError = getErrorString(e);
        String[] paramsEx = { currentRealm, serviceName, strError };
        logEvent("SMS_EXCEPTION_MODIFY_SERVICE_UNDER_REALM", paramsEx);
        throw new AMConsoleException(strError);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) SMSException(com.sun.identity.sm.SMSException) AMIdentity(com.sun.identity.idm.AMIdentity) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException)

Example 100 with AMIdentityRepository

use of com.sun.identity.idm.AMIdentityRepository in project OpenAM by OpenRock.

the class RealmResourceOfferingModelImpl method getRealmDiscoEntry.

/**
     * Returns resource offering entry stored for a realm name.
     *
     * @param realm Realm Name.
     * @return resource offering entry stored for a given user.
     * @throws AMConsoleException if entry cannot be determined.
     */
public SMDiscoveryServiceData getRealmDiscoEntry(String realm) throws AMConsoleException {
    SMDiscoveryServiceData resourceOffering = null;
    String[] params = { realm, AMAdminConstants.DISCOVERY_SERVICE, AMAdminConstants.DISCOVERY_SERVICE_NAME_DYNAMIC_DISCO_ENTRIES };
    logEvent("ATTEMPT_GET_ATTR_VALUE_OF_SERVICE_UNDER_REALM", params);
    try {
        AMIdentityRepository repo = new AMIdentityRepository(getUserSSOToken(), realm);
        AMIdentity realmIdentity = repo.getRealmIdentity();
        Set servicesFromIdRepo = realmIdentity.getAssignedServices();
        Map map = null;
        if (servicesFromIdRepo.contains(AMAdminConstants.DISCOVERY_SERVICE)) {
            map = realmIdentity.getServiceAttributes(AMAdminConstants.DISCOVERY_SERVICE);
        } else {
            OrganizationConfigManager orgCfgMgr = new OrganizationConfigManager(getUserSSOToken(), realm);
            map = orgCfgMgr.getServiceAttributes(AMAdminConstants.DISCOVERY_SERVICE);
        }
        logEvent("SUCCEED_GET_ATTR_VALUE_OF_SERVICE_UNDER_REALM", params);
        resourceOffering = SMDiscoveryServiceData.getEntries((Set) map.get(AMAdminConstants.DISCOVERY_SERVICE_NAME_DYNAMIC_DISCO_ENTRIES));
    } catch (SSOException e) {
        String strError = getErrorString(e);
        String[] paramsEx = { realm, AMAdminConstants.DISCOVERY_SERVICE, strError };
        logEvent("SSO_EXCEPTION_GET_ATTR_VALUE_OF_SERVICE_UNDER_REALM", paramsEx);
        debug.error("RealmResourceOfferingModelImpl.getAttributeValues", e);
    } catch (IdRepoException e) {
        String strError = getErrorString(e);
        String[] paramsEx = { realm, AMAdminConstants.DISCOVERY_SERVICE, strError };
        logEvent("IDREPO_EXCEPTION_GET_ATTR_VALUE_OF_SERVICE_UNDER_REALM", paramsEx);
        debug.error("RealmResourceOfferingModelImpl.getAttributeValues", e);
    } catch (SMSException e) {
        String strError = getErrorString(e);
        String[] paramsEx = { realm, AMAdminConstants.DISCOVERY_SERVICE, strError };
        logEvent("SMS_EXCEPTION_GET_ATTR_VALUE_OF_SERVICE_UNDER_REALM", paramsEx);
        debug.error("RealmResourceOfferingModelImpl.getAttributeValues", e);
    }
    return resourceOffering;
}
Also used : SMDiscoveryServiceData(com.sun.identity.console.service.model.SMDiscoveryServiceData) Set(java.util.Set) SMSException(com.sun.identity.sm.SMSException) AMIdentity(com.sun.identity.idm.AMIdentity) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

AMIdentityRepository (com.sun.identity.idm.AMIdentityRepository)138 IdRepoException (com.sun.identity.idm.IdRepoException)103 SSOException (com.iplanet.sso.SSOException)94 AMIdentity (com.sun.identity.idm.AMIdentity)85 Set (java.util.Set)82 HashSet (java.util.HashSet)58 SSOToken (com.iplanet.sso.SSOToken)56 IdSearchControl (com.sun.identity.idm.IdSearchControl)36 IdSearchResults (com.sun.identity.idm.IdSearchResults)36 Iterator (java.util.Iterator)32 CLIException (com.sun.identity.cli.CLIException)29 HashMap (java.util.HashMap)29 IdType (com.sun.identity.idm.IdType)28 Map (java.util.Map)27 IOutput (com.sun.identity.cli.IOutput)26 SMSException (com.sun.identity.sm.SMSException)24 OrganizationConfigManager (com.sun.identity.sm.OrganizationConfigManager)20 List (java.util.List)13 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)12 Callback (javax.security.auth.callback.Callback)6