RealmAssignService.java revision 5dfd75bba89c5676f0394273e13a5dccb26ac3c8
af062818b47340eef15700d2f0211576ba3506eevboxsync/**
af062818b47340eef15700d2f0211576ba3506eevboxsync * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
af062818b47340eef15700d2f0211576ba3506eevboxsync *
af062818b47340eef15700d2f0211576ba3506eevboxsync * Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
af062818b47340eef15700d2f0211576ba3506eevboxsync *
af062818b47340eef15700d2f0211576ba3506eevboxsync * The contents of this file are subject to the terms
af062818b47340eef15700d2f0211576ba3506eevboxsync * of the Common Development and Distribution License
af062818b47340eef15700d2f0211576ba3506eevboxsync * (the License). You may not use this file except in
af062818b47340eef15700d2f0211576ba3506eevboxsync * compliance with the License.
af062818b47340eef15700d2f0211576ba3506eevboxsync *
af062818b47340eef15700d2f0211576ba3506eevboxsync * You can obtain a copy of the License at
af062818b47340eef15700d2f0211576ba3506eevboxsync * https://opensso.dev.java.net/public/CDDLv1.0.html or
af062818b47340eef15700d2f0211576ba3506eevboxsync * opensso/legal/CDDLv1.0.txt
af062818b47340eef15700d2f0211576ba3506eevboxsync * See the License for the specific language governing
af062818b47340eef15700d2f0211576ba3506eevboxsync * permission and limitations under the License.
af062818b47340eef15700d2f0211576ba3506eevboxsync *
af062818b47340eef15700d2f0211576ba3506eevboxsync * When distributing Covered Code, include this CDDL
af062818b47340eef15700d2f0211576ba3506eevboxsync * Header Notice in each file and include the License file
af062818b47340eef15700d2f0211576ba3506eevboxsync * at opensso/legal/CDDLv1.0.txt.
af062818b47340eef15700d2f0211576ba3506eevboxsync * If applicable, add the following below the CDDL Header,
af062818b47340eef15700d2f0211576ba3506eevboxsync * with the fields enclosed by brackets [] replaced by
af062818b47340eef15700d2f0211576ba3506eevboxsync * your own identifying information:
af062818b47340eef15700d2f0211576ba3506eevboxsync * "Portions Copyrighted [year] [name of copyright owner]"
af062818b47340eef15700d2f0211576ba3506eevboxsync *
af062818b47340eef15700d2f0211576ba3506eevboxsync * $Id: RealmAssignService.java,v 1.3 2008/06/25 05:42:16 qcheng Exp $
af062818b47340eef15700d2f0211576ba3506eevboxsync *
af062818b47340eef15700d2f0211576ba3506eevboxsync */
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync/*
af062818b47340eef15700d2f0211576ba3506eevboxsync * Portions copyright 2010-2015 ForgeRock AS.
af062818b47340eef15700d2f0211576ba3506eevboxsync */
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsyncpackage com.sun.identity.cli.realm;
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsyncimport com.iplanet.sso.SSOException;
af062818b47340eef15700d2f0211576ba3506eevboxsyncimport com.iplanet.sso.SSOToken;
af062818b47340eef15700d2f0211576ba3506eevboxsyncimport com.sun.identity.cli.AttributeValues;
af062818b47340eef15700d2f0211576ba3506eevboxsyncimport com.sun.identity.cli.AuthenticatedCommand;
af062818b47340eef15700d2f0211576ba3506eevboxsyncimport com.sun.identity.cli.CLIException;
af062818b47340eef15700d2f0211576ba3506eevboxsyncimport com.sun.identity.cli.ExitCodes;
af062818b47340eef15700d2f0211576ba3506eevboxsyncimport com.sun.identity.cli.IArgument;
af062818b47340eef15700d2f0211576ba3506eevboxsyncimport com.sun.identity.cli.IOutput;
af062818b47340eef15700d2f0211576ba3506eevboxsyncimport com.sun.identity.cli.LogWriter;
af062818b47340eef15700d2f0211576ba3506eevboxsyncimport com.sun.identity.cli.RequestContext;
af062818b47340eef15700d2f0211576ba3506eevboxsyncimport com.sun.identity.idm.AMIdentity;
af062818b47340eef15700d2f0211576ba3506eevboxsyncimport com.sun.identity.idm.AMIdentityRepository;
af062818b47340eef15700d2f0211576ba3506eevboxsyncimport com.sun.identity.idm.IdRepoException;
af062818b47340eef15700d2f0211576ba3506eevboxsyncimport com.sun.identity.sm.OrganizationConfigManager;
af062818b47340eef15700d2f0211576ba3506eevboxsyncimport com.sun.identity.sm.SMSException;
af062818b47340eef15700d2f0211576ba3506eevboxsyncimport java.text.MessageFormat;
af062818b47340eef15700d2f0211576ba3506eevboxsyncimport java.util.List;
af062818b47340eef15700d2f0211576ba3506eevboxsyncimport java.util.Map;
af062818b47340eef15700d2f0211576ba3506eevboxsyncimport java.util.Set;
af062818b47340eef15700d2f0211576ba3506eevboxsyncimport java.util.logging.Level;
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync/**
af062818b47340eef15700d2f0211576ba3506eevboxsync * Assigns service to a realm.
af062818b47340eef15700d2f0211576ba3506eevboxsync */
af062818b47340eef15700d2f0211576ba3506eevboxsyncpublic class RealmAssignService extends AuthenticatedCommand {
af062818b47340eef15700d2f0211576ba3506eevboxsync /**
* 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 attributeValues = null;
if ((datafile != null) || (attrValues != null)) {
attributeValues = AttributeValues.parse(
getCommandManager(), datafile, attrValues);
}
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);
}
}
}