|
| 1 | +/* |
| 2 | + * Copyright (c) 2024, Oracle and/or its affiliates. |
| 3 | + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. |
| 4 | + */ |
| 5 | +package oracle.weblogic.deploy.tool.archive_helper.extract; |
| 6 | + |
| 7 | +import oracle.weblogic.deploy.logging.PlatformLogger; |
| 8 | +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; |
| 9 | +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; |
| 10 | +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; |
| 11 | +import oracle.weblogic.deploy.util.ExitCode; |
| 12 | +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; |
| 13 | +import picocli.CommandLine.Command; |
| 14 | +import picocli.CommandLine.Option; |
| 15 | + |
| 16 | +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; |
| 17 | + |
| 18 | +@Command( |
| 19 | + name = "xacmlPolicy", |
| 20 | + header = "Extract XACML Authorizer policy definition file from the archive file.", |
| 21 | + description = "%nCommand-line options:" |
| 22 | +) |
| 23 | +public class ExtractXACMLPolicyCommand extends ExtractTypeCommandBase { |
| 24 | + private static final String CLASS = ExtractXACMLPolicyCommand.class.getName(); |
| 25 | + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); |
| 26 | + private static final String TYPE = "XACML Authorizer policy definition file"; |
| 27 | + private static final String ERROR_KEY = "WLSDPLY-30047"; |
| 28 | + |
| 29 | + @Option( |
| 30 | + names = {"-name"}, |
| 31 | + description = "Name of the XACML Authorizer policy definition file to be extracted from the archive file", |
| 32 | + required = true |
| 33 | + ) |
| 34 | + private String name; |
| 35 | + |
| 36 | + @Override |
| 37 | + public CommandResponse call() throws Exception { |
| 38 | + final String METHOD = "call"; |
| 39 | + LOGGER.entering(CLASS, METHOD); |
| 40 | + |
| 41 | + CommandResponse response; |
| 42 | + try { |
| 43 | + initializeOptions(); |
| 44 | + |
| 45 | + this.archive.extractXACMLPolicyFile(this.name, this.targetDirectory); |
| 46 | + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30046", TYPE, this.name, |
| 47 | + this.archiveFilePath, this.targetDirectory.getPath()); |
| 48 | + } catch (ArchiveHelperException ex) { |
| 49 | + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.archiveFilePath, |
| 50 | + this.targetDirectory.getPath(), ex.getLocalizedMessage()); |
| 51 | + response = new CommandResponse(ex.getExitCode(), ERROR_KEY, TYPE, this.name, |
| 52 | + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); |
| 53 | + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { |
| 54 | + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.archiveFilePath, |
| 55 | + this.targetDirectory.getPath(), ex.getLocalizedMessage()); |
| 56 | + response = new CommandResponse(ExitCode.ERROR, ERROR_KEY, TYPE, this.name, |
| 57 | + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); |
| 58 | + } |
| 59 | + |
| 60 | + LOGGER.exiting(CLASS, METHOD, response); |
| 61 | + return response; |
| 62 | + } |
| 63 | +} |
0 commit comments