Search in sources :

Example 31 with AMIdentityRepository

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

the class RealmModifyService method handleRequest.

/**
     * Services a Commandline Request.
     *
     * @param rc Request Context.
     * @throws CLIException if the request cannot serviced.
     */
public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    ldapLogin();
    SSOToken adminSSOToken = getAdminSSOToken();
    IOutput outputWriter = getOutputWriter();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    String serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
    String datafile = getStringOptionValue(IArgument.DATA_FILE);
    List attrValues = rc.getOption(IArgument.ATTRIBUTE_VALUES);
    if ((datafile == null) && (attrValues == null)) {
        throw new CLIException(getResourceString("missing-attributevalues"), ExitCodes.INCORRECT_OPTION, rc.getSubCommand().getName());
    }
    Map<String, Set<String>> attributeValues = AttributeValues.parse(getCommandManager(), datafile, attrValues);
    attributeValues = processFileAttributes(attributeValues);
    try {
        String[] params = { realm, serviceName };
        OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
        Set assignedServices = ocm.getAssignedServices(true);
        AMIdentityRepository repo = new AMIdentityRepository(adminSSOToken, realm);
        AMIdentity ai = repo.getRealmIdentity();
        Set servicesFromIdRepo = ai.getAssignedServices();
        boolean modified = false;
        if (assignedServices.contains(serviceName)) {
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_MODIFY_SERVICE_REALM", params);
            ocm.modifyService(serviceName, attributeValues);
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_MODIFY_SERVICE_REALM", params);
            modified = true;
        }
        if (servicesFromIdRepo.contains(serviceName)) {
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_MODIFY_SERVICE_REALM", params);
            ai.modifyService(serviceName, attributeValues);
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_MODIFY_SERVICE_REALM", params);
            modified = true;
        }
        if (modified) {
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("modify-service-of-realm-succeed"), (Object[]) params));
        } else {
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("modify-service-of-realm-not-assigned"), (Object[]) params));
        }
    } catch (IdRepoException e) {
        String[] args = { realm, serviceName, e.getMessage() };
        debugError("RealmModifyService.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_MODIFY_SERVICE_REALM", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, serviceName, e.getMessage() };
        debugError("RealmModifyService.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_MODIFY_SERVICE_REALM", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { realm, serviceName, e.getMessage() };
        debugError("RealmModifyService.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_MODIFY_SERVICE_REALM", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) SMSException(com.sun.identity.sm.SMSException) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) IOutput(com.sun.identity.cli.IOutput) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) CLIException(com.sun.identity.cli.CLIException) List(java.util.List)

Example 32 with AMIdentityRepository

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

the class RealmRemoveServiceAttributes method handleRequest.

/**
     * Services a Commandline Request.
     *
     * @param rc Request Context.
     * @throws CLIException if the request cannot serviced.
     */
public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    ldapLogin();
    SSOToken adminSSOToken = getAdminSSOToken();
    IOutput outputWriter = getOutputWriter();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    String serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
    String datafile = getStringOptionValue(IArgument.DATA_FILE);
    List attrValues = rc.getOption(IArgument.ATTRIBUTE_VALUES);
    if ((datafile == null) && (attrValues == null)) {
        throw new CLIException(getResourceString("missing-attributevalues"), ExitCodes.INCORRECT_OPTION, rc.getSubCommand().getName());
    }
    Map attributeValues = AttributeValues.parse(getCommandManager(), datafile, attrValues);
    try {
        String[] params = { realm, serviceName };
        OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
        Set assignedServices = ocm.getAssignedServices(true);
        AMIdentityRepository repo = new AMIdentityRepository(adminSSOToken, realm);
        AMIdentity ai = repo.getRealmIdentity();
        Set servicesFromIdRepo = ai.getAssignedServices();
        boolean modified = false;
        if (assignedServices.contains(serviceName)) {
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_REALM_REMOVE_SERVICE_ATTR_VALUES", params);
            Map origValues = ocm.getServiceAttributes(serviceName);
            if (AttributeValues.mergeAttributeValues(origValues, attributeValues, false)) {
                ocm.modifyService(serviceName, origValues);
            }
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REALM_REMOVE_SERVICE_ATTR_VALUES", params);
            modified = true;
        }
        if (servicesFromIdRepo.contains(serviceName)) {
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_REALM_REMOVE_SERVICE_ATTR_VALUES", params);
            Map origValues = ai.getServiceAttributes(serviceName);
            if (AttributeValues.mergeAttributeValues(origValues, attributeValues, false)) {
                ai.modifyService(serviceName, origValues);
            }
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REALM_REMOVE_SERVICE_ATTR_VALUES", params);
            modified = true;
        }
        if (modified) {
            outputWriter.printlnMessage(getResourceString("realm-remove-service-attributes-succeed"));
            outputWriter.printlnMessage("");
            outputWriter.printlnMessage(FormatUtils.printAttributeValues("{0}={1}", attributeValues));
        } else {
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("realm-remove-service-attributes-not-assigned"), (Object[]) params));
        }
    } catch (IdRepoException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmRemoveServiceAttributes.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REALM_REMOVE_SERVICE_ATTR_VALUES", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmRemoveServiceAttributes.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REALM_REMOVE_SERVICE_ATTR_VALUES", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmRemoveServiceAttributes.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REALM_REMOVE_SERVICE_ATTR_VALUES", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) SMSException(com.sun.identity.sm.SMSException) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) IOutput(com.sun.identity.cli.IOutput) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) Map(java.util.Map)

Example 33 with AMIdentityRepository

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

the class RealmAddServiceAttributes method handleRequest.

/**
     * Services a Commandline Request.
     *
     * @param rc Request Context.
     * @throws CLIException if the request cannot serviced.
     */
@Override
public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    ldapLogin();
    SSOToken adminSSOToken = getAdminSSOToken();
    IOutput outputWriter = getOutputWriter();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    String serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
    String datafile = getStringOptionValue(IArgument.DATA_FILE);
    List attrValues = rc.getOption(IArgument.ATTRIBUTE_VALUES);
    if ((datafile == null) && (attrValues == null)) {
        throw new CLIException(getResourceString("missing-attributevalues"), ExitCodes.INCORRECT_OPTION, rc.getSubCommand().getName());
    }
    Map<String, Set<String>> attributeValues = AttributeValues.parse(getCommandManager(), datafile, attrValues);
    attributeValues = processFileAttributes(attributeValues);
    try {
        String[] params = { realm, serviceName };
        OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
        Map<String, Boolean> mapAttrType = getMultipleValueAttrs(serviceName);
        Set assignedServices = ocm.getAssignedServices(true);
        AMIdentityRepository repo = new AMIdentityRepository(adminSSOToken, realm);
        AMIdentity ai = repo.getRealmIdentity();
        Set servicesFromIdRepo = ai.getAssignedServices();
        boolean modified = false;
        if (assignedServices.contains(serviceName)) {
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_REALM_ADD_SERVICE_ATTR_VALUES", params);
            Map origValues = ocm.getServiceAttributes(serviceName);
            if (AttributeValues.mergeAttributeValues(origValues, attributeValues, mapAttrType, true)) {
                ocm.modifyService(serviceName, origValues);
            }
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REALM_ADD_SERVICE_ATTR_VALUES", params);
            modified = true;
        }
        if (servicesFromIdRepo.contains(serviceName)) {
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_REALM_ADD_SERVICE_ATTR_VALUES", params);
            Map origValues = ai.getServiceAttributes(serviceName);
            if (AttributeValues.mergeAttributeValues(origValues, attributeValues, mapAttrType, true)) {
                ai.modifyService(serviceName, origValues);
            }
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REALM_ADD_SERVICE_ATTR_VALUES", params);
            modified = true;
        }
        if (modified) {
            outputWriter.printlnMessage(getResourceString("realm-add-service-attributes-succeed"));
            outputWriter.printlnMessage("");
            outputWriter.printlnMessage(FormatUtils.printAttributeValues("{0}={1}", attributeValues));
        } else {
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("realm-add-service-attributes-not-assigned"), (Object[]) params));
        }
    } catch (IdRepoException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmAddServiceAttributes.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REALM_ADD_SERVICE_ATTR_VALUES", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmAddServiceAttributes.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REALM_ADD_SERVICE_ATTR_VALUES", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmAddServiceAttributes.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REALM_ADD_SERVICE_ATTR_VALUES", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) SMSException(com.sun.identity.sm.SMSException) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) IOutput(com.sun.identity.cli.IOutput) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 34 with AMIdentityRepository

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

the class RealmAssignService method handleRequest.

/**
     * Services a Commandline Request.
     *
     * @param rc Request Context.
     * @throws CLIException if the request cannot serviced.
     */
public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    ldapLogin();
    SSOToken adminSSOToken = getAdminSSOToken();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    String serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
    String datafile = getStringOptionValue(IArgument.DATA_FILE);
    List attrValues = rc.getOption(IArgument.ATTRIBUTE_VALUES);
    Map<String, Set<String>> attributeValues = null;
    if ((datafile != null) || (attrValues != null)) {
        attributeValues = AttributeValues.parse(getCommandManager(), datafile, attrValues);
        attributeValues = processFileAttributes(attributeValues);
    }
    IOutput outputWriter = getOutputWriter();
    String[] params = { realm, serviceName };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ASSIGN_SERVICE_TO_REALM", params);
    try {
        OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
        Set assignableServices = ocm.getAssignableServices();
        AMIdentityRepository amir = new AMIdentityRepository(adminSSOToken, realm);
        AMIdentity ai = amir.getRealmIdentity();
        Set dynAssignableServices = ai.getAssignableServices();
        if (assignableServices.contains(serviceName)) {
            ocm.assignService(serviceName, attributeValues);
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("assign-service-to-realm-succeed"), (Object[]) params));
        }
        if (dynAssignableServices.contains(serviceName)) {
            ai.assignService(serviceName, attributeValues);
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("assign-service-to-realm-succeed"), (Object[]) params));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_ASSIGN_SERVICE_TO_REALM", params);
    } catch (SSOException e) {
        String[] args = { realm, serviceName, e.getMessage() };
        debugError("RealmAssignService.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ASSIGN_SERVICE_TO_REALM", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (IdRepoException e) {
        String[] args = { realm, serviceName, e.getMessage() };
        debugError("RealmAssignService.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ASSIGN_SERVICE_TO_REALM", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { realm, serviceName, e.getMessage() };
        debugError("RealmAssignService.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ASSIGN_SERVICE_TO_REALM", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) SMSException(com.sun.identity.sm.SMSException) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) IOutput(com.sun.identity.cli.IOutput) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) CLIException(com.sun.identity.cli.CLIException) List(java.util.List)

Example 35 with AMIdentityRepository

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

the class RealmGetAssignedServices method getAssignedDynamicServiceNames.

private Set getAssignedDynamicServiceNames(SSOToken adminSSOToken, String realm) throws SMSException, IdRepoException, SSOException {
    AMIdentityRepository repo = new AMIdentityRepository(adminSSOToken, realm);
    AMIdentity ai = repo.getRealmIdentity();
    return ai.getAssignedServices();
}
Also used : AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository)

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