Search in sources :

Example 36 with ConfigurationException

use of com.sun.identity.common.configuration.ConfigurationException in project OpenAM by OpenRock.

the class SitesResourceProvider method updateInstance.

@Override
public Promise<ResourceResponse, ResourceException> updateInstance(Context context, String id, UpdateRequest request) {
    JsonValue content = request.getContent();
    try {
        validWriteOperation(content, id);
    } catch (BadRequestException e) {
        return e.asPromise();
    }
    ResourceResponse site;
    SSOToken token;
    try {
        token = getSsoToken(context);
        site = getSite(token, id);
    } catch (SMSException | SSOException | ConfigurationException e) {
        debug.error("Could not read site {}", id, e);
        return new InternalServerErrorException("Could not read site").asPromise();
    } catch (NotFoundException e) {
        return e.asPromise();
    }
    try {
        if (!site.getRevision().equals(request.getRevision())) {
            return new PreconditionFailedException("Revision did not match").asPromise();
        }
        SiteConfiguration.setSitePrimaryURL(token, id, content.get("url").asString());
        SiteConfiguration.setSiteSecondaryURLs(token, id, content.get("secondaryURLs").asSet());
        return newResultPromise(getSite(token, id));
    } catch (SSOException | SMSException | ConfigurationException e) {
        debug.error("Could not update site {}", id, e);
        return new InternalServerErrorException("Could not update site").asPromise();
    } catch (NotFoundException e) {
        return new InternalServerErrorException("Could not read site after just updating it", e).asPromise();
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) ResourceResponse(org.forgerock.json.resource.ResourceResponse) SMSException(com.sun.identity.sm.SMSException) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) JsonValue(org.forgerock.json.JsonValue) BadRequestException(org.forgerock.json.resource.BadRequestException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) NotFoundException(org.forgerock.json.resource.NotFoundException) SSOException(com.iplanet.sso.SSOException) PreconditionFailedException(org.forgerock.json.resource.PreconditionFailedException)

Example 37 with ConfigurationException

use of com.sun.identity.common.configuration.ConfigurationException in project OpenAM by OpenRock.

the class SpecialRepo method updateServiceConfiguration.

private void updateServiceConfiguration(String urlAccessAgentCryptPwd) throws IdRepoException, SSOException {
    if (urlAccessAgentCryptPwd != null) {
        Map<String, Set<String>> map = new HashMap<String, Set<String>>();
        Set<String> set = new HashSet<String>();
        set.add(urlAccessAgentCryptPwd);
        map.put(Constants.AM_SERVICES_SECRET, set);
        SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
        String instance = SystemProperties.getServerInstanceName();
        try {
            ServerConfiguration.setServerInstance(adminToken, instance, map);
        } catch (SMSException e) {
            debug.error("SpecialRepo.updateServiceConfiguration", e);
            Object[] args = { NAME, IdOperation.EDIT.getName() };
            throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.UNABLE_SYNC_URL_ACCESS_AGENT, args);
        } catch (IOException e) {
            debug.error("SpecialRepo.updateServiceConfiguration", e);
            Object[] args = { NAME, IdOperation.EDIT.getName() };
            throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.UNABLE_SYNC_URL_ACCESS_AGENT, args);
        } catch (ConfigurationException e) {
            debug.error("SpecialRepo.updateServiceConfiguration", e);
            Object[] args = { NAME, IdOperation.EDIT.getName() };
            throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.UNABLE_SYNC_URL_ACCESS_AGENT, args);
        } catch (UnknownPropertyNameException e) {
        // never happen
        }
    }
}
Also used : UnknownPropertyNameException(com.sun.identity.common.configuration.UnknownPropertyNameException) Set(java.util.Set) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) SSOToken(com.iplanet.sso.SSOToken) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) SMSException(com.sun.identity.sm.SMSException) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) IdRepoException(com.sun.identity.idm.IdRepoException) IOException(java.io.IOException) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet)

Example 38 with ConfigurationException

use of com.sun.identity.common.configuration.ConfigurationException in project OpenAM by OpenRock.

the class IdentityServicesImpl method create.

/**
     * Creates a new {@code AMIdentity} in the identity repository with the
     * details specified in {@code identity}.
     *
     * @param identity The identity details.
     * @param admin The admin token.
     * @throws ResourceException If a problem occurs.
     */
public void create(IdentityDetails identity, SSOToken admin) throws ResourceException {
    Reject.ifNull(identity, admin);
    // Obtain identity details & verify
    String idName = identity.getName();
    String idType = identity.getType();
    String realm = identity.getRealm();
    if (StringUtils.isEmpty(idName)) {
        // TODO: add a message to the exception
        throw new BadRequestException("Identity name not provided");
    }
    if (StringUtils.isEmpty(idType)) {
        idType = "user";
    }
    if (realm == null) {
        realm = "/";
    }
    try {
        // Obtain IdRepo to create validate IdType & operations
        IdType objectIdType = getIdType(idType);
        AMIdentityRepository repo = getRepo(admin, realm);
        if (!isOperationSupported(repo, objectIdType, IdOperation.CREATE)) {
            // TODO: add message to exception
            throw new UnsupportedOperationException("Unsupported: Type: " + idType + " Operation: CREATE");
        }
        // Obtain creation attributes
        Map<String, Set<String>> idAttrs = asMap(identity.getAttributes());
        // Create the identity, special case of Agents to merge
        // and validate the attributes
        AMIdentity amIdentity;
        if (isTypeAgent(objectIdType)) {
            createAgent(idAttrs, objectIdType, idType, idName, realm, admin);
        } else {
            // Create other identites like User, Group, Role, etc.
            amIdentity = repo.createIdentity(objectIdType, idName, idAttrs);
            // Process roles, groups & memberships
            if (IdType.USER.equals(objectIdType)) {
                Set<String> roles = asSet(identity.getRoleList());
                if (roles != null && !roles.isEmpty()) {
                    if (!isOperationSupported(repo, IdType.ROLE, IdOperation.EDIT)) {
                        // TODO: localize message
                        throw new UnsupportedOperationException("Unsupported: Type: " + IdType.ROLE + " Operation: EDIT");
                    }
                    for (String roleName : roles) {
                        AMIdentity role = fetchAMIdentity(repo, IdType.ROLE, roleName, false);
                        if (role != null) {
                            role.addMember(amIdentity);
                            role.store();
                        }
                    }
                }
                Set<String> groups = asSet(identity.getGroupList());
                if (groups != null && !groups.isEmpty()) {
                    if (!isOperationSupported(repo, IdType.GROUP, IdOperation.EDIT)) {
                        // TODO: localize message
                        throw new UnsupportedOperationException("Unsupported: Type: " + IdType.GROUP + " Operation: EDIT");
                    }
                    for (String groupName : groups) {
                        AMIdentity group = fetchAMIdentity(repo, IdType.GROUP, groupName, false);
                        if (group != null) {
                            group.addMember(amIdentity);
                            group.store();
                        }
                    }
                }
            }
            if (IdType.GROUP.equals(objectIdType) || IdType.ROLE.equals(objectIdType)) {
                Set<String> members = asSet(identity.getMemberList());
                if (members != null) {
                    if (IdType.GROUP.equals(objectIdType) && !isOperationSupported(repo, IdType.GROUP, IdOperation.EDIT)) {
                        throw new ForbiddenException("Token is not authorized");
                    }
                    if (IdType.ROLE.equals(objectIdType) && !isOperationSupported(repo, IdType.ROLE, IdOperation.EDIT)) {
                        throw new ForbiddenException("Token is not authorized");
                    }
                    for (String memberName : members) {
                        AMIdentity user = fetchAMIdentity(repo, IdType.USER, memberName, false);
                        if (user != null) {
                            amIdentity.addMember(user);
                        }
                    }
                    amIdentity.store();
                }
            }
        }
    } catch (IdRepoDuplicateObjectException ex) {
        throw new ConflictException("Resource already exists", ex);
    } catch (IdRepoException e) {
        debug.error("IdentityServicesImpl:create", e);
        if (IdRepoErrorCode.ACCESS_DENIED.equals(e.getErrorCode())) {
            throw new ForbiddenException(e.getMessage());
        } else if (e.getLdapErrorIntCode() == LDAPConstants.LDAP_CONSTRAINT_VIOLATION) {
            debug.error(e.getMessage(), e);
            throw new BadRequestException();
        } else {
            throw new NotFoundException(e.getMessage());
        }
    } catch (SSOException | SMSException | ConfigurationException | MalformedURLException | UnsupportedOperationException e) {
        debug.error("IdentityServicesImpl:create", e);
        throw new NotFoundException(e.getMessage());
    } catch (ObjectNotFound e) {
        debug.error("IdentityServicesImpl:create", e);
        throw new NotFoundException(e.getMessage());
    }
}
Also used : ForbiddenException(org.forgerock.json.resource.ForbiddenException) MalformedURLException(java.net.MalformedURLException) Set(java.util.Set) HashSet(java.util.HashSet) ConflictException(org.forgerock.json.resource.ConflictException) SMSException(com.sun.identity.sm.SMSException) IdRepoException(com.sun.identity.idm.IdRepoException) NotFoundException(org.forgerock.json.resource.NotFoundException) SSOException(com.iplanet.sso.SSOException) IdType(com.sun.identity.idm.IdType) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) ObjectNotFound(com.sun.identity.idsvcs.ObjectNotFound) IdRepoDuplicateObjectException(com.sun.identity.idm.IdRepoDuplicateObjectException) AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) BadRequestException(org.forgerock.json.resource.BadRequestException)

Example 39 with ConfigurationException

use of com.sun.identity.common.configuration.ConfigurationException in project OpenAM by OpenRock.

the class AgentsModelImpl method createAgent.

/**
     * Creates agent.
     *
     * @param realmName Realm where agent resides.
     * @param name Name of agent.
     * @param type Type of agent.
     * @param password Password of agent.
     * @param serverURL Server URL.
     * @param agentURL Agent URL.
     * @throws AMConsoleException if agent cannot be created.
     */
public void createAgent(String realmName, String name, String type, String password, String serverURL, String agentURL) throws AMConsoleException {
    String[] params = { realmName, name, type };
    try {
        logEvent("ATTEMPT_CREATE_AGENT", params);
        Map map = AgentConfiguration.getDefaultValues(type, false);
        Set set = new HashSet(2);
        map.put(AgentConfiguration.ATTR_NAME_PWD, set);
        set.add(password);
        AgentConfiguration.createAgent(getUserSSOToken(), realmName, name, type, map, serverURL, agentURL);
        logEvent("SUCCEED_CREATE_AGENT", params);
    } catch (ConfigurationException e) {
        String[] paramsEx = { realmName, name, type, getErrorString(e) };
        logEvent("EXCEPTION_CREATE_AGENT", paramsEx);
        debug.warning("AgentsModelImpl.createAgent", e);
        throw new AMConsoleException(getErrorString(e));
    } catch (SSOException e) {
        String[] paramsEx = { realmName, name, type, getErrorString(e) };
        logEvent("EXCEPTION_CREATE_AGENT", paramsEx);
        debug.warning("AgentsModelImpl.createAgent", e);
        throw new AMConsoleException(getErrorString(e));
    } catch (IdRepoException e) {
        String[] paramsEx = { realmName, name, type, getErrorString(e) };
        logEvent("EXCEPTION_CREATE_AGENT", paramsEx);
        debug.warning("AgentsModelImpl.createAgent", e);
        throw new AMConsoleException(getErrorString(e));
    } catch (SMSException e) {
        String[] paramsEx = { realmName, name, type, getErrorString(e) };
        logEvent("EXCEPTION_CREATE_AGENT", paramsEx);
        debug.warning("AgentsModelImpl.createAgent", e);
        throw new AMConsoleException(getErrorString(e));
    }
}
Also used : TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) SMSException(com.sun.identity.sm.SMSException) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 40 with ConfigurationException

use of com.sun.identity.common.configuration.ConfigurationException in project OpenAM by OpenRock.

the class ServerSiteModelImpl method setServerConfigXML.

/**
     * Sets the server configuration XML.
     *
     * @param serverName Name of server.
     * @param xml the server configuration XML.
     * @throws AMConsoleException if server configuration XML cannot be set.
     */
public void setServerConfigXML(String serverName, String xml) throws AMConsoleException {
    String[] param = { serverName };
    logEvent("ATTEMPT_SET_SERVER_CONFIG_XML", param);
    try {
        ServerConfiguration.setServerConfigXML(getUserSSOToken(), serverName, xml);
        logEvent("SUCCEED_SET_SERVER_CONFIG_XML", param);
    } catch (SMSException e) {
        String[] params = { serverName, e.getMessage() };
        logEvent("SMS_EXCEPTION_SET_SERVER_CONFIG_XML", params);
        throw new AMConsoleException(getErrorString(e));
    } catch (SSOException e) {
        String[] params = { serverName, e.getMessage() };
        logEvent("SSO_EXCEPTION_SET_SERVER_CONFIG_XML", params);
        throw new AMConsoleException(getErrorString(e));
    } catch (ConfigurationException e) {
        String[] params = { serverName, e.getMessage() };
        logEvent("SSO_EXCEPTION_SET_SERVER_CONFIG_XML", params);
        throw new AMConsoleException(getErrorString(e));
    }
}
Also used : SMSException(com.sun.identity.sm.SMSException) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) SSOException(com.iplanet.sso.SSOException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException)

Aggregations

ConfigurationException (com.sun.identity.common.configuration.ConfigurationException)48 SSOException (com.iplanet.sso.SSOException)40 SMSException (com.sun.identity.sm.SMSException)39 SSOToken (com.iplanet.sso.SSOToken)30 CLIException (com.sun.identity.cli.CLIException)19 IOutput (com.sun.identity.cli.IOutput)17 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)14 List (java.util.List)12 IdRepoException (com.sun.identity.idm.IdRepoException)11 IOException (java.io.IOException)11 Map (java.util.Map)10 Set (java.util.Set)9 UnknownPropertyNameException (com.sun.identity.common.configuration.UnknownPropertyNameException)6 HashSet (java.util.HashSet)6 Iterator (java.util.Iterator)6 NotFoundException (org.forgerock.json.resource.NotFoundException)6 AMIdentity (com.sun.identity.idm.AMIdentity)5 MalformedURLException (java.net.MalformedURLException)5 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)5 HashMap (java.util.HashMap)4