use of com.sun.identity.cli.CommandManager in project OpenAM by OpenRock.
the class CLITestImpl method setup.
@BeforeClass
public void setup() throws Exception {
Map<String, Object> env = new HashMap<String, Object>();
env.put(CLIConstants.SYS_PROPERTY_COMMAND_NAME, "testclifw");
env.put(CLIConstants.SYS_PROPERTY_DEFINITION_FILES, "com.sun.identity.cli.AccessManager");
env.put(CLIConstants.SYS_PROPERTY_OUTPUT_WRITER, outputWriter);
cmdManager = new CommandManager(env);
beforeClass();
}
use of com.sun.identity.cli.CommandManager in project OpenAM by OpenRock.
the class AddSubSchema 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();
String serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
String schemaType = getStringOptionValue(IArgument.SCHEMA_TYPE);
String subSchemaName = getStringOptionValue(IArgument.SUBSCHEMA_NAME);
String fileName = getStringOptionValue(ARGUMENT_FILENAME);
if (subSchemaName == null) {
subSchemaName = "/";
}
IOutput outputWriter = getOutputWriter();
String[] params = { serviceName, schemaType, subSchemaName };
ServiceSchema ss = getServiceSchema();
CommandManager mgr = getCommandManager();
String url = mgr.getWebEnabledURL();
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ADD_SUB_SCHEMA", params);
try {
if ((url != null) && (url.length() > 0)) {
ss.addSubSchema(new ByteArrayInputStream(fileName.getBytes()));
} else {
ss.addSubSchema(new FileInputStream(fileName));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_ADD_SUB_SCHEMA", params);
outputWriter.printlnMessage(MessageFormat.format(getResourceString("add-subschema-succeed"), (Object[]) params));
} catch (SSOException e) {
String[] args = { serviceName, schemaType, subSchemaName, e.getMessage() };
debugError("AddSubSchema.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_SUB_SCHEMA", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SMSException e) {
String[] args = { serviceName, schemaType, subSchemaName, e.getMessage() };
debugError("AddSubSchema.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_SUB_SCHEMA", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (IOException e) {
String[] args = { serviceName, schemaType, subSchemaName, e.getMessage() };
debugError("AddSubSchema.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_SUB_SCHEMA", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.cli.CommandManager in project OpenAM by OpenRock.
the class AddAttributeSchema 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();
List listContinues = (List) rc.getOption(IArgument.CONTINUE);
boolean continueFlag = (listContinues != null);
IOutput outputWriter = getOutputWriter();
List fileNames = (List) rc.getOption(ARGUMENT_SCHEMA_FILES);
String serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
String schemaType = getStringOptionValue(IArgument.SCHEMA_TYPE);
ServiceSchema ss = getServiceSchema();
CommandManager mgr = getCommandManager();
String url = mgr.getWebEnabledURL();
if ((url != null) && (url.length() > 0)) {
String[] param = { CLIConstants.WEB_INPUT };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ADD_ATTRIBUTE_SCHEMA", param);
addAttributeSchemaXML(ss, serviceName, schemaType, (String) fileNames.iterator().next());
outputWriter.printlnMessage(getResourceString("attribute-schema-added"));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_ADD_ATTRIBUTE_SCHEMA", param);
} else {
for (Iterator i = fileNames.iterator(); i.hasNext(); ) {
String name = (String) i.next();
String[] param = { serviceName, schemaType, name };
try {
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ADD_ATTRIBUTE_SCHEMA", param);
addAttributeSchema(ss, serviceName, schemaType, name);
outputWriter.printlnMessage(getResourceString("attribute-schema-added"));
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_ADD_ATTRIBUTE_SCHEMA", param);
} catch (CLIException e) {
if (continueFlag) {
outputWriter.printlnError(getResourceString("add-attribute-schema-failed") + e.getMessage());
if (isVerbose()) {
outputWriter.printlnError(Debugger.getStackTrace(e));
}
} else {
throw e;
}
}
}
}
}
use of com.sun.identity.cli.CommandManager in project OpenAM by OpenRock.
the class ImportMetaData method handleRequest.
/**
* Imports Meta Data.
*
* @param rc Request Context.
* @throws CLIException if unable to process this request.
*/
@Override
public void handleRequest(RequestContext rc) throws CLIException {
super.handleRequest(rc);
ldapLogin();
realm = getStringOptionValue(FedCLIConstants.ARGUMENT_REALM, "/");
metadata = getStringOptionValue(FedCLIConstants.ARGUMENT_METADATA);
extendedData = getStringOptionValue(FedCLIConstants.ARGUMENT_EXTENDED_DATA);
cot = getStringOptionValue(FedCLIConstants.ARGUMENT_COT);
spec = FederationManager.getIDFFSubCommandSpecification(rc);
String[] params = { realm, metadata, extendedData, cot, spec };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_IMPORT_ENTITY", params);
if ((metadata == null) && (extendedData == null)) {
String[] args = { realm, metadata, extendedData, cot, spec, getResourceString("import-entity-exception-no-datafile") };
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IMPORT_ENTITY", args);
throw new CLIException(getResourceString("import-entity-exception-no-datafile"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
validateCOT();
CommandManager mgr = getCommandManager();
String url = mgr.getWebEnabledURL();
webAccess = (url != null) && (url.length() > 0);
try {
if (spec.equals(FederationManager.DEFAULT_SPECIFICATION)) {
handleSAML2Request(rc);
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_IMPORT_ENTITY", params);
} else if (spec.equals(FedCLIConstants.IDFF_SPECIFICATION)) {
handleIDFFRequest(rc);
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_IMPORT_ENTITY", params);
} else if (spec.equals(FedCLIConstants.WSFED_SPECIFICATION)) {
handleWSFedRequest(rc);
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_IMPORT_ENTITY", params);
} else {
throw new CLIException(getResourceString("unsupported-specification"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
} catch (CLIException e) {
String[] args = { realm, metadata, extendedData, cot, spec, e.getMessage() };
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IMPORT_ENTITY", args);
throw e;
}
}
use of com.sun.identity.cli.CommandManager in project OpenAM by OpenRock.
the class AuthConfigTest method suiteSetup.
/**
* Create the CLIManager.
*/
@BeforeTest(groups = { "cli-authconfig" })
public void suiteSetup() throws CLIException {
Map<String, Object> env = new HashMap<String, Object>();
env.put(CLIConstants.SYS_PROPERTY_COMMAND_NAME, "amadm");
env.put(CLIConstants.SYS_PROPERTY_DEFINITION_FILES, "com.sun.identity.cli.AccessManager");
env.put(CLIConstants.SYS_PROPERTY_OUTPUT_WRITER, outputWriter);
cmdManager = new CommandManager(env);
}
Aggregations