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();
}
}
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
}
}
}
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());
}
}
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));
}
}
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));
}
}
Aggregations