Search in sources :

Example 1 with FQDNUrl

use of com.sun.identity.shared.FQDNUrl in project OpenAM by OpenRock.

the class AgentConfiguration method createAgentGroup.

/**
     * Creates an agent group.
     *
     * @param ssoToken Single Sign On token that is to be used for creation.
     * @param realm Realm where group resides.
     * @param agentGroupName Name of agent group.
     * @param agentType Type of agent group.
     * @param attrValues Map of attribute name to its values.
     * @param serverURL Server URL.
     * @param agentURL Agent URL.
     * @throws IdRepoException if there are Id Repository related errors.
     * @throws SSOException if the Single Sign On token is invalid or has
     *         expired.
     * @throws SMSException if there are errors in service management layers.
     * @throws MalformedURLException if server or agent URL is invalid.
     * @throws ConfigurationException if there are missing information in
     *         server or agent URL; or invalid agent type
     */
public static void createAgentGroup(SSOToken ssoToken, String realm, String agentGroupName, String agentType, Map attrValues, String serverURL, String agentURL) throws IdRepoException, SSOException, SMSException, MalformedURLException, ConfigurationException {
    if ((serverURL == null) || (serverURL.trim().length() == 0)) {
        throw new ConfigurationException("create.agent.invalid.server.url", null);
    }
    FQDNUrl urlAgent = null;
    if ((agentURL != null) && (agentURL.trim().length() > 0)) {
        urlAgent = new FQDNUrl(agentURL);
    }
    createAgentGroupEx(ssoToken, realm, agentGroupName, agentType, attrValues, new FQDNUrl(serverURL), urlAgent);
}
Also used : FQDNUrl(com.sun.identity.shared.FQDNUrl)

Example 2 with FQDNUrl

use of com.sun.identity.shared.FQDNUrl in project OpenAM by OpenRock.

the class AgentConfiguration method createAgent.

/**
     * Creates an agent.
     *
     * @param ssoToken Single Sign On token that is to be used for creation.
     * @param realm Realm where agent resides.
     * @param agentName Name of agent.
     * @param agentType Type of agent.
     * @param attrValues Map of attribute name to its values.
     * @param serverURL Server URL.
     * @param agentURL Agent URL.
     * @throws IdRepoException if there are Id Repository related errors.
     * @throws SSOException if the Single Sign On token is invalid or has
     *         expired.
     * @throws SMSException if there are errors in service management layers.
     * @throws ConfigurationException if there are missing information in
     *         server or agent URL; or invalid agent type.
     */
public static void createAgent(SSOToken ssoToken, String realm, String agentName, String agentType, Map attrValues, String serverURL, String agentURL) throws IdRepoException, SSOException, SMSException, ConfigurationException {
    if ((serverURL == null) || (serverURL.trim().length() == 0)) {
        throw new ConfigurationException("create.agent.invalid.server.url", null);
    }
    if ((agentURL == null) || (agentURL.trim().length() == 0)) {
        throw new ConfigurationException("create.agent.invalid.agent.url", null);
    }
    FQDNUrl serverFQDNURL = null;
    FQDNUrl agentFQDNURL = null;
    try {
        serverFQDNURL = new FQDNUrl(serverURL);
    } catch (MalformedURLException e) {
        throw new ConfigurationException("create.agent.invalid.server.url", null);
    }
    try {
        agentFQDNURL = new FQDNUrl(agentURL);
    } catch (MalformedURLException e) {
        throw new ConfigurationException("create.agent.invalid.agent.url", null);
    }
    createAgentEx(ssoToken, realm, agentName, agentType, attrValues, serverFQDNURL, agentFQDNURL);
}
Also used : MalformedURLException(java.net.MalformedURLException) FQDNUrl(com.sun.identity.shared.FQDNUrl)

Example 3 with FQDNUrl

use of com.sun.identity.shared.FQDNUrl in project OpenAM by OpenRock.

the class IdRepoUtils method createAgent.

public static AMIdentity createAgent(String realm, String id) throws IdRepoException, SSOException, SMSException, MalformedURLException, ConfigurationException {
    String agentType = "J2EEAgent";
    String serverURL = "http://www.example.com:8080/opensso";
    String agentURL = "http://www.example.com:9090/client";
    FQDNUrl fqdnServerURL = new FQDNUrl(serverURL);
    FQDNUrl fqdnAgentURL = new FQDNUrl(agentURL);
    SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
    Map map = AgentConfiguration.getDefaultValues(agentType, false);
    AgentConfiguration.tagswapAttributeValues(map, agentType, fqdnServerURL, fqdnAgentURL);
    Set set = new HashSet();
    set.add(id);
    map.put("userpassword", set);
    return AgentConfiguration.createAgent(adminToken, realm, id, agentType, map);
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) HashSet(java.util.HashSet) FQDNUrl(com.sun.identity.shared.FQDNUrl) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 4 with FQDNUrl

use of com.sun.identity.shared.FQDNUrl in project OpenAM by OpenRock.

the class SiteConfiguration method setSiteSecondaryURLs.

/**
     * Sets the secondary URLs of a site.
     *
     * @param ssoToken Single Sign-On Token which is used to access to the
     *        service management datastore.
     * @param siteName Name of the site.
     * @param secondaryURLs secondary URLs of a site.
     * @throws SMSException if errors access in the service management
     *         datastore.
     * @throws SSOException if the <code>ssoToken</code> is not valid.
     */
public static void setSiteSecondaryURLs(SSOToken ssoToken, String siteName, Collection secondaryURLs) throws SMSException, SSOException, ConfigurationException {
    for (Iterator i = secondaryURLs.iterator(); i.hasNext(); ) {
        String url = (String) i.next();
        try {
            FQDNUrl test = new FQDNUrl(url);
            if ((!test.isFullyQualified()) || (test.getPort().length() == 0) || (test.getURI().length() == 0)) {
                String[] param = { url };
                throw new ConfigurationException("invalid.site.secondary.url", param);
            }
        } catch (MalformedURLException ex) {
            String[] param = { url };
            throw new ConfigurationException("invalid.site.secondary.url", param);
        }
    }
    ServiceConfig rootNode = getRootSiteConfig(ssoToken);
    ServiceConfig sc = rootNode.getSubConfig(siteName);
    ServiceConfig accessPoint = sc.getSubConfig(SUBCONFIG_ACCESS_URL);
    Set secondary = accessPoint.getSubConfigNames("*");
    Set toAdd = new HashSet(secondaryURLs.size());
    toAdd.addAll(secondaryURLs);
    Set toRemove = new HashSet(secondary.size());
    if ((secondary != null) && !secondary.isEmpty()) {
        toRemove.addAll(secondary);
        toRemove.removeAll(secondaryURLs);
        toAdd.removeAll(secondary);
    }
    Set allURLs = getAllSiteURLs(ssoToken);
    for (Iterator i = toAdd.iterator(); i.hasNext(); ) {
        String url = (String) i.next();
        if (allURLs.contains(url)) {
            String[] param = { url };
            throw new ConfigurationException("duplicated.site.url", param);
        }
    }
    for (Iterator i = toRemove.iterator(); i.hasNext(); ) {
        String url = (String) i.next();
        accessPoint.removeSubConfig(url);
    }
    for (Iterator i = toAdd.iterator(); i.hasNext(); ) {
        String url = (String) i.next();
        Map values = new HashMap(2);
        Set set = new HashSet(2);
        set.add(getNextId(ssoToken));
        values.put(ATTR_SEC_ID, set);
        accessPoint.addSubConfig(url, SUBCONFIG_SEC_URLS, 0, values);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) FQDNUrl(com.sun.identity.shared.FQDNUrl) ServiceConfig(com.sun.identity.sm.ServiceConfig) HashMap(java.util.HashMap) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 5 with FQDNUrl

use of com.sun.identity.shared.FQDNUrl in project OpenAM by OpenRock.

the class CreateAgent 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 agentName = getStringOptionValue(IArgument.AGENT_NAME);
    String agentType = getStringOptionValue(IArgument.AGENT_TYPE);
    String datafile = getStringOptionValue(IArgument.DATA_FILE);
    List attrValues = rc.getOption(IArgument.ATTRIBUTE_VALUES);
    Map attributeValues = Collections.EMPTY_MAP;
    if ((datafile != null) || (attrValues != null)) {
        attributeValues = AttributeValues.parse(getCommandManager(), datafile, attrValues);
    }
    if ((attributeValues == null) || attributeValues.isEmpty()) {
        throw new CLIException(getResourceString("agent-creation-pwd-needed"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
    String serverURL = getStringOptionValue(IArgument.SERVER_URL);
    String agentURL = getStringOptionValue(AGENT_URL);
    boolean webJ2EEAgent = agentType.equals("WebAgent") || agentType.equals("J2EEAgent");
    if (!webJ2EEAgent) {
        if (serverURL != null) {
            throw new CLIException(getResourceString("does-not-support-server-url"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        if (agentURL != null) {
            throw new CLIException(getResourceString("does-not-support-agent-url"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
    } else {
        if (agentURL != null && serverURL == null) {
            throw new CLIException(getResourceString("server-url-missing"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        if (serverURL != null && agentURL == null) {
            throw new CLIException(getResourceString("agent-url-missing"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        if (serverURL == null && agentURL == null && attributeValues.size() == 1) {
            //only the password is provided
            throw new CLIException(getResourceString("missing-urls"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
    }
    boolean hasPassword = false;
    for (Iterator i = attributeValues.keySet().iterator(); (i.hasNext() && !hasPassword); ) {
        String k = (String) i.next();
        if (k.equals(CLIConstants.ATTR_SCHEMA_AGENT_PWD)) {
            Set values = (Set) attributeValues.get(k);
            if ((values != null) && !values.isEmpty()) {
                String pwd = (String) values.iterator().next();
                hasPassword = (pwd.trim().length() > 0);
            }
        }
    }
    if (!hasPassword) {
        throw new CLIException(getResourceString("agent-creation-pwd-needed"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
    String[] params = { realm, agentType, agentName };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_CREATE_AGENT", params);
    try {
        AMIdentityRepository amir = new AMIdentityRepository(adminSSOToken, realm);
        Set set = amir.getAllowedIdOperations(IdType.AGENTONLY);
        if (!set.contains(IdOperation.CREATE)) {
            String[] args = { realm };
            throw new CLIException(MessageFormat.format(getResourceString("does-not-support-agent-creation"), (Object[]) args), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        if (webJ2EEAgent) {
            if (serverURL != null) {
                FQDNUrl fqdnServerURL = null;
                try {
                    fqdnServerURL = new FQDNUrl(serverURL);
                } catch (MalformedURLException e) {
                    throw new CLIException(getResourceString("server-url-invalid"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
                }
                FQDNUrl fqdnAgentURL = null;
                try {
                    fqdnAgentURL = new FQDNUrl(agentURL);
                } catch (MalformedURLException e) {
                    throw new CLIException(getResourceString("agent-url-invalid"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
                }
                Map map = AgentConfiguration.getDefaultValues(agentType, false);
                map.putAll(attributeValues);
                AgentConfiguration.tagswapAttributeValues(map, agentType, fqdnServerURL, fqdnAgentURL);
                // Remove any default values that have not been replaced by values
                // supplied when calling create agent. These are in the form of
                // propertyname[n] where n is a value starting from 0
                AgentConfiguration.removeDefaultDuplicates(attributeValues, map);
                AgentConfiguration.createAgent(adminSSOToken, realm, agentName, agentType, map);
            } else {
                AgentConfiguration.createAgent(adminSSOToken, realm, agentName, agentType, attributeValues);
            }
        } else {
            AgentConfiguration.createAgent(adminSSOToken, realm, agentName, agentType, attributeValues);
        }
        getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("create-agent-succeeded"), (Object[]) params));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_CREATE_AGENT", params);
    } catch (ConfigurationException e) {
        String[] args = { realm, agentType, agentName, e.getMessage() };
        debugError("CreateAgent.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_CREATE_AGENT", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (IdRepoException e) {
        String[] args = { realm, agentType, agentName, e.getMessage() };
        debugError("CreateAgent.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_CREATE_AGENT", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { realm, agentType, agentName, e.getMessage() };
        debugError("CreateAgent.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_CREATE_AGENT", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, agentType, agentName, e.getMessage() };
        debugError("CreateAgent.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_CREATE_AGENT", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) 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) FQDNUrl(com.sun.identity.shared.FQDNUrl) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) Iterator(java.util.Iterator) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) Map(java.util.Map)

Aggregations

FQDNUrl (com.sun.identity.shared.FQDNUrl)8 MalformedURLException (java.net.MalformedURLException)6 Map (java.util.Map)5 Set (java.util.Set)5 SSOToken (com.iplanet.sso.SSOToken)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Iterator (java.util.Iterator)3 SSOException (com.iplanet.sso.SSOException)2 CLIException (com.sun.identity.cli.CLIException)2 ConfigurationException (com.sun.identity.common.configuration.ConfigurationException)2 AMIdentityRepository (com.sun.identity.idm.AMIdentityRepository)2 IdRepoException (com.sun.identity.idm.IdRepoException)2 SMSException (com.sun.identity.sm.SMSException)2 ServiceConfig (com.sun.identity.sm.ServiceConfig)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 AMPropertySheet (com.sun.identity.console.base.AMPropertySheet)1 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)1 ServerSiteModel (com.sun.identity.console.service.model.ServerSiteModel)1