/** * 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); SSOToken adminSSOToken = getAdminSSOToken(); IOutput outputWriter = getOutputWriter(); String realm = getStringOptionValue(IArgument.REALM_NAME); String idName = getStringOptionValue(ARGUMENT_ID_NAME); String type = getStringOptionValue(ARGUMENT_ID_TYPE); IdType idType = convert2IdType(type); String[] params = {realm, type, idName}; try { AMIdentityRepository amir = new AMIdentityRepository(adminSSOToken, realm); Set set = amir.getAllowedIdOperations(idType); if (!set.contains(IdOperation.SERVICE)) { throw new CLIException( MessageFormat.format( getResourceString("realm-does-not-support-service"), (Object[]) params), ExitCodes.REQUEST_CANNOT_BE_PROCESSED); } writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_GET_ASSIGNED_SERVICES", params); AMIdentity amid = new AMIdentity(adminSSOToken, idName, idType, realm, null); Set services = amid.getAssignedServices(); if ((services != null) && !services.isEmpty()) { String msg = getResourceString("assigned-service-result"); String[] arg = {""}; for (Iterator i = services.iterator(); i.hasNext(); ) { arg[0] = (String) i.next(); outputWriter.printlnMessage(MessageFormat.format(msg, (Object[]) arg)); } } else { outputWriter.printlnMessage(getResourceString("no-service-assigned")); } writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_GET_ASSIGNED_SERVICES", params); } catch (IdRepoException e) { String[] args = {realm, type, idName, e.getMessage()}; debugError("GetAssignedServices.handleRequest", e); writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_ASSIGNED_SERVICES", args); throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED); } catch (SSOException e) { String[] args = {realm, type, idName, e.getMessage()}; debugError("GetAssignedServices.handleRequest", e); writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_ASSIGNED_SERVICES", args); throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED); } }
/** * Services a Commandline Request. * * @param rc Request Context. * @throw CLIException if the request cannot serviced. */ public void handleRequest(RequestContext rc) throws CLIException { super.handleRequest(rc); SSOToken adminSSOToken = getAdminSSOToken(); IOutput outputWriter = getOutputWriter(); String realm = getStringOptionValue(IArgument.REALM_NAME); String idName = getStringOptionValue(ARGUMENT_ID_NAME); String type = getStringOptionValue(ARGUMENT_ID_TYPE); String serviceName = getStringOptionValue(IArgument.SERVICE_NAME); IdType idType = convert2IdType(type); 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); String[] params = {realm, type, idName, serviceName}; try { writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_IDREPO_ASSIGN_SERVICE", params); AMIdentity amid = new AMIdentity(adminSSOToken, idName, idType, realm, null); amid.assignService(serviceName, attributeValues); outputWriter.printlnMessage( MessageFormat.format( getResourceString("idrepo-assign-service-succeed"), (Object[]) params)); writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_IDREPO_ASSIGN_SERVICE", params); } catch (IdRepoException e) { String[] args = {realm, type, idName, serviceName, e.getMessage()}; debugError("AssignService.handleRequest", e); writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_ASSIGN_SERVICE", args); throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED); } catch (SSOException e) { String[] args = {realm, type, idName, serviceName, e.getMessage()}; debugError("AssignService.handleRequest", e); writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_ASSIGN_SERVICE", args); throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED); } }
/** * 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); SSOToken adminSSOToken = getAdminSSOToken(); IOutput outputWriter = getOutputWriter(); String realm = getStringOptionValue(IArgument.REALM_NAME); String idName = getStringOptionValue(ARGUMENT_ID_NAME); String type = getStringOptionValue(ARGUMENT_ID_TYPE); List privileges = (List) rc.getOption(IArgument.PRIVILEGES); IdType idType = convert2IdType(type); String[] params = {realm, type, idName}; try { writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_IDREPO_ADD_PRIVILEGES", params); DelegationManager mgr = new DelegationManager(adminSSOToken, realm); Set privilegeObjects = mgr.getPrivileges(); AMIdentity amid = new AMIdentity(adminSSOToken, idName, idType, realm, null); if (!amid.isExists()) { Object[] p = {idName, type}; throw new CLIException( MessageFormat.format(getResourceString("idrepo-add-privileges-do-not-exist"), p), ExitCodes.REQUEST_CANNOT_BE_PROCESSED); } String uid = amid.getUniversalId(); DelegationPrivilege newDp = null; for (Iterator i = privileges.iterator(); i.hasNext(); ) { String name = (String) i.next(); DelegationPrivilege dp = getDelegationPrivilege(name, privilegeObjects); if (dp != null) { Set subjects = dp.getSubjects(); if (!subjects.contains(uid)) { subjects.add(uid); newDp = new DelegationPrivilege(name, subjects, realm); mgr.addPrivilege(newDp); } else { String[] args = {idName, name}; String msg = MessageFormat.format( getResourceString("delegation-already-has-privilege"), (Object[]) args); throw new CLIException(msg, ExitCodes.REQUEST_CANNOT_BE_PROCESSED); } } else { Set subjects = new HashSet(2); subjects.add(uid); newDp = new DelegationPrivilege(name, subjects, realm); mgr.addPrivilege(newDp); } } outputWriter.printlnMessage( MessageFormat.format( getResourceString("idrepo-add-privileges-succeed"), (Object[]) params)); writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_IDREPO_ADD_PRIVILEGES", params); } catch (IdRepoException e) { String[] args = {realm, type, idName, e.getMessage()}; debugError("AddPrivileges.handleRequest", e); writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_ADD_PRIVILEGES", args); throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED); } catch (DelegationException e) { String[] args = {realm, type, idName, e.getMessage()}; debugError("AddPrivileges.handleRequest", e); writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_ADD_PRIVILEGES", args); throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED); } catch (SSOException e) { String[] args = {realm, type, idName, e.getMessage()}; debugError("AddPrivileges.handleRequest", e); writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_ADD_PRIVILEGES", args); throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED); } }