Commit ae43ca37 authored by michael.simon's avatar michael.simon
Browse files

implement deregister for nextcloud

disable user on deregister, enable on register, if the account exists.
parent a6c198a5
......@@ -464,4 +464,137 @@ public class NextcloudWorker {
throw new RegisterException(e);
}
}
public NextcloudAnswer disableAccount(RegistryEntity registry) throws RegisterException {
String id = registry.getRegistryValues().get("id");
URI uri;
try {
URIBuilder uriBuilder = new URIBuilder(apiUrl + "users/" + id + "/disable");
uri = uriBuilder.build();
} catch (URISyntaxException e) {
throw new RegisterException(e);
}
HttpClientContext context = buildHttpContext(uri);
CloseableHttpResponse response;
try {
HttpPut http = buildHttpPut(uri);
response = httpClient.execute(http, context);
} catch (ClientProtocolException e) {
logger.warn("Client protocol problem", e);
throw new RegisterException(e);
} catch (SSLException e) {
logger.error("SSL Certificate problem with SNS Server: {}", e.toString());
throw new RegisterException(e);
} catch (IOException e) {
logger.warn("Connection", e);
throw new RegisterException(e);
}
logger.debug("Status line of response: {}", response.getStatusLine());
if (response.getStatusLine() != null && response.getStatusLine().getStatusCode() == 404) {
logger.warn("Status answer is 404, Account not found.");
return null;
} else if (response.getStatusLine() == null || response.getStatusLine().getStatusCode() != 200) {
logger.warn("Status answer was not HTTP OK 200");
throw new RegisterException("Nexcloud: " + response.getStatusLine());
}
HttpEntity entity = response.getEntity();
try {
JAXBContext jaxbContext = JAXBContext.newInstance(NextcloudAnswer.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
NextcloudAnswer answer = (NextcloudAnswer) unmarshaller.unmarshal(entity.getContent());
logger.debug("{} {}", answer.getMeta().getStatusCode(), answer.getMeta().getStatus());
return answer;
} catch (ParseException e) {
logger.warn("Parse problem", e);
throw new RegisterException(e);
} catch (IOException e) {
logger.warn("Connection", e);
throw new RegisterException(e);
} catch (IllegalStateException e) {
logger.warn("Parse problem", e);
throw new RegisterException(e);
} catch (JAXBException e) {
logger.warn("Parse problem", e);
throw new RegisterException(e);
}
}
public NextcloudAnswer enableAccount(RegistryEntity registry) throws RegisterException {
String id = registry.getRegistryValues().get("id");
URI uri;
try {
URIBuilder uriBuilder = new URIBuilder(apiUrl + "users/" + id + "/enable");
uri = uriBuilder.build();
} catch (URISyntaxException e) {
throw new RegisterException(e);
}
HttpClientContext context = buildHttpContext(uri);
CloseableHttpResponse response;
try {
HttpPut http = buildHttpPut(uri);
response = httpClient.execute(http, context);
} catch (ClientProtocolException e) {
logger.warn("Client protocol problem", e);
throw new RegisterException(e);
} catch (SSLException e) {
logger.error("SSL Certificate problem with SNS Server: {}", e.toString());
throw new RegisterException(e);
} catch (IOException e) {
logger.warn("Connection", e);
throw new RegisterException(e);
}
logger.debug("Status line of response: {}", response.getStatusLine());
if (response.getStatusLine() != null && response.getStatusLine().getStatusCode() == 404) {
logger.warn("Status answer is 404, Account not found.");
return null;
} else if (response.getStatusLine() == null || response.getStatusLine().getStatusCode() != 200) {
logger.warn("Status answer was not HTTP OK 200");
throw new RegisterException("Nexcloud: " + response.getStatusLine());
}
HttpEntity entity = response.getEntity();
try {
JAXBContext jaxbContext = JAXBContext.newInstance(NextcloudAnswer.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
NextcloudAnswer answer = (NextcloudAnswer) unmarshaller.unmarshal(entity.getContent());
logger.debug("{} {}", answer.getMeta().getStatusCode(), answer.getMeta().getStatus());
return answer;
} catch (ParseException e) {
logger.warn("Parse problem", e);
throw new RegisterException(e);
} catch (IOException e) {
logger.warn("Connection", e);
throw new RegisterException(e);
} catch (IllegalStateException e) {
logger.warn("Parse problem", e);
throw new RegisterException(e);
} catch (JAXBException e) {
logger.warn("Parse problem", e);
throw new RegisterException(e);
}
}
}
......@@ -85,12 +85,35 @@ public class NextcloudProxyIdpRegisterWorkflow implements RegisterUserWorkflow,
if (! registry.getRegistryValues().containsKey("id")) {
registry.getRegistryValues().put("id", user.getGenericStore().get(idKey));
}
NextcloudWorker worker = new NextcloudWorker(prop);
NextcloudAnswer answer = worker.loadAccount(registry);
if (answer.getMeta().getStatusCode() == 100) {
if ((answer.getUser() != null) &&
((answer.getUser().getEnabled() == null) || (answer.getUser().getEnabled() == false))) {
// user exists and is disabled, enable him
NextcloudAnswer enableAnswer = worker.enableAccount(registry);
if (enableAnswer.getMeta().getStatusCode() != 100) {
logger.warn("Enabling of registry {} for user {} failed", registry.getId(), user.getEppn());
throw new RegisterException("Failed to enable account");
}
}
}
}
@Override
public void deregisterUser(UserEntity user, ServiceEntity service, RegistryEntity registry, Auditor auditor)
throws RegisterException {
PropertyReader prop = PropertyReader.newRegisterPropReader(service);
NextcloudWorker worker = new NextcloudWorker(prop);
NextcloudAnswer answer = worker.disableAccount(registry);
if (answer.getMeta().getStatusCode() != 100) {
logger.warn("Enabling of registry {} for user {} failed", registry.getId(), user.getEppn());
throw new RegisterException("Failed to enable account");
}
}
@Override
......
......@@ -48,6 +48,22 @@ public class PfNcMigrationRegisterWorkflow extends PowerFolderRegisterWorkflow
if (! registry.getRegistryValues().containsKey("id")) {
registry.getRegistryValues().put("id", user.getGenericStore().get(idKey));
}
NextcloudWorker worker = new NextcloudWorker(prop);
NextcloudAnswer answer = worker.loadAccount(registry);
if (answer.getMeta().getStatusCode() == 100) {
if ((answer.getUser() != null) &&
((answer.getUser().getEnabled() == null) || (answer.getUser().getEnabled() == false))) {
// user exists and is disabled, enable him
NextcloudAnswer enableAnswer = worker.enableAccount(registry);
if (enableAnswer.getMeta().getStatusCode() != 100) {
logger.warn("Enabling of registry {} for user {} failed", registry.getId(), user.getEppn());
throw new RegisterException("Failed to enable account");
}
}
}
}
@Override
......@@ -115,6 +131,21 @@ public class PfNcMigrationRegisterWorkflow extends PowerFolderRegisterWorkflow
}
return info;
}
@Override
public void deregisterUser(UserEntity user, ServiceEntity service, RegistryEntity registry, Auditor auditor)
throws RegisterException {
super.deregisterUser(user, service, registry, auditor);
PropertyReader prop = PropertyReader.newRegisterPropReader(service);
NextcloudWorker worker = new NextcloudWorker(prop);
NextcloudAnswer answer = worker.disableAccount(registry);
if (answer.getMeta().getStatusCode() != 100) {
logger.warn("Enabling of registry {} for user {} failed", registry.getId(), user.getEppn());
throw new RegisterException("Failed to enable account");
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment