use of org.olat.basesecurity.Authentication in project openolat by klemens.
the class UserAuthenticationsEditorController method event.
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
*/
@Override
public void event(UserRequest ureq, Controller source, Event event) {
if (source == confirmationDialog) {
if (DialogBoxUIFactory.isYesEvent(event)) {
Authentication auth = (Authentication) confirmationDialog.getUserObject();
securityManager.deleteAuthentication(auth);
getWindowControl().setInfo(getTranslator().translate("authedit.delete.success", new String[] { auth.getProvider(), changeableIdentity.getName() }));
authTableModel.setObjects(securityManager.getAuthentications(changeableIdentity));
tableCtr.modelChanged();
}
} else if (source == tableCtr) {
if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
TableEvent te = (TableEvent) event;
String actionid = te.getActionId();
if (actionid.equals("delete")) {
int rowid = te.getRowId();
Authentication auth = authTableModel.getObject(rowid);
String fullname = userManager.getUserDisplayName(changeableIdentity);
String msg = translate("authedit.delete.confirm", new String[] { auth.getProvider(), fullname });
confirmationDialog = activateYesNoDialog(ureq, null, msg, confirmationDialog);
confirmationDialog.setUserObject(auth);
}
}
}
}
use of org.olat.basesecurity.Authentication in project OpenOLAT by OpenOLAT.
the class ViteroManager method checkUsers.
public CheckUserInfo checkUsers() throws VmsNotAvailableException {
final String[] authProviders = new String[] { VMS_PROVIDER };
final String prefix = getVmsUsernamePrefix();
int authenticationCreated = 0;
int authenticationDeleted = 0;
// check if vms user with an openolat login exists on vms server
// without the need authentication object in openolat.
List<Usertype> users = getCustomersUsers();
if (users != null && users.size() > 0) {
for (Usertype user : users) {
String vmsUsername = user.getUsername();
if (vmsUsername.startsWith(prefix)) {
String olatUsername = vmsUsername.substring(prefix.length(), vmsUsername.length());
List<Identity> identities = securityManager.getIdentitiesByPowerSearch(olatUsername, null, false, null, null, authProviders, null, null, null, null, null);
if (identities.isEmpty()) {
Identity identity = securityManager.findIdentityByName(olatUsername);
if (identity != null) {
authenticationCreated++;
securityManager.createAndPersistAuthentication(identity, VMS_PROVIDER, Integer.toString(user.getId()), null, null);
log.info("Recreate VMS authentication for: " + identity.getName());
}
}
}
}
}
// check if all openolat users with a vms authentication have an user
// on the vms server
List<Identity> identities = securityManager.getIdentitiesByPowerSearch(null, null, false, null, null, authProviders, null, null, null, null, null);
for (Identity identity : identities) {
Authentication authentication = securityManager.findAuthentication(identity, VMS_PROVIDER);
String vmsUserId = authentication.getAuthusername();
boolean foundIt = false;
for (Usertype user : users) {
if (vmsUserId.equals(Integer.toString(user.getId()))) {
foundIt = true;
}
}
if (!foundIt) {
securityManager.deleteAuthentication(authentication);
authenticationDeleted++;
}
}
CheckUserInfo infos = new CheckUserInfo();
infos.setAuthenticationCreated(authenticationCreated);
infos.setAuthenticationDeleted(authenticationDeleted);
return infos;
}
use of org.olat.basesecurity.Authentication in project OpenOLAT by OpenOLAT.
the class WebDAVPasswordController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
setFormTitle("pwdav.title");
if (formLayout instanceof FormLayoutContainer) {
FormLayoutContainer layoutContainer = (FormLayoutContainer) formLayout;
layoutContainer.contextPut("webdavhttp", FolderManager.getWebDAVHttp());
layoutContainer.contextPut("webdavhttps", FolderManager.getWebDAVHttps());
accessDataFlc = FormLayoutContainer.createDefaultFormLayout("flc_access_data", getTranslator());
layoutContainer.add(accessDataFlc);
StringBuilder sb = new StringBuilder();
sb.append(getIdentity().getName());
if (StringHelper.containsNonWhitespace(getIdentity().getUser().getEmail())) {
sb.append(", ").append(getIdentity().getUser().getEmail());
}
if (StringHelper.containsNonWhitespace(getIdentity().getUser().getInstitutionalEmail())) {
sb.append(", ").append(getIdentity().getUser().getInstitutionalEmail());
}
uifactory.addStaticTextElement("pwdav.username", "pwdav.username", sb.toString(), accessDataFlc);
boolean hasOlatToken = false;
boolean hasWebDAVToken = false;
List<Authentication> authentications = securityManager.getAuthentications(ureq.getIdentity());
for (Authentication auth : authentications) {
if (BaseSecurityModule.getDefaultAuthProviderIdentifier().equals(auth.getProvider())) {
hasOlatToken = true;
} else if (WebDAVAuthManager.PROVIDER_WEBDAV.equals(auth.getProvider())) {
hasWebDAVToken = true;
}
}
if (hasOlatToken) {
String passwordPlaceholder = getTranslator().translate("pwdav.password.placeholder");
uifactory.addStaticTextElement("pwdav.password", "pwdav.password", passwordPlaceholder, accessDataFlc);
} else {
String passwordPlaceholderKey = hasWebDAVToken ? "pwdav.password.set" : "pwdav.password.not_set";
String passwordPlaceholder = getTranslator().translate(passwordPlaceholderKey);
passwordStaticEl = uifactory.addStaticTextElement("pwdav.password", "pwdav.password", passwordPlaceholder, accessDataFlc);
passwordEl = uifactory.addPasswordElement("pwdav.password.2", "pwdav.password", 64, "", accessDataFlc);
passwordEl.setVisible(false);
passwordEl.setMandatory(true);
confirmPasswordEl = uifactory.addPasswordElement("pwdav.password.confirm", "pwdav.password.confirm", 64, "", accessDataFlc);
confirmPasswordEl.setVisible(false);
confirmPasswordEl.setMandatory(true);
buttonGroupLayout = FormLayoutContainer.createButtonLayout("buttonGroupLayout", getTranslator());
buttonGroupLayout.setRootForm(mainForm);
accessDataFlc.add(buttonGroupLayout);
if (hasWebDAVToken) {
newButton = uifactory.addFormLink("pwdav.password.change", buttonGroupLayout, Link.BUTTON);
} else {
newButton = uifactory.addFormLink("pwdav.password.new", buttonGroupLayout, Link.BUTTON);
}
saveButton = uifactory.addFormSubmitButton("save", buttonGroupLayout);
saveButton.setVisible(false);
cancelButton = uifactory.addFormCancelButton("cancel", buttonGroupLayout, ureq, getWindowControl());
cancelButton.setVisible(false);
}
layoutContainer.put("access_data", accessDataFlc.getComponent());
}
}
use of org.olat.basesecurity.Authentication in project OpenOLAT by OpenOLAT.
the class UserAuthenticationWebService method create.
/**
* Creates and persists an authentication
* @response.representation.qname {http://www.example.com}authenticationVO
* @response.representation.mediaType application/xml, application/json
* @response.representation.doc An authentication to save
* @response.representation.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_AUTHVO}
* @response.representation.200.qname {http://www.example.com}authenticationVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The saved authentication
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_AUTHVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The identity not found
* @response.representation.406.doc Cannot create the authentication for an unkown reason
* @response.representation.409.doc Cannot create the authentication because the authentication username is already used by someone else within the same provider
* @param username The username of the user
* @param authenticationVO The authentication object to persist
* @param request The HTTP request
* @return the saved authentication
*/
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response create(@PathParam("username") String username, AuthenticationVO authenticationVO, @Context HttpServletRequest request) {
if (!RestSecurityHelper.isUserManager(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
BaseSecurity baseSecurity = BaseSecurityManager.getInstance();
Identity identity = baseSecurity.loadIdentityByKey(authenticationVO.getIdentityKey(), false);
if (identity == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
if (!identity.getName().equals(username)) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
String provider = authenticationVO.getProvider();
String authUsername = authenticationVO.getAuthUsername();
String credentials = authenticationVO.getCredential();
Authentication currentAuthentication = baseSecurity.findAuthenticationByAuthusername(authUsername, provider);
if (currentAuthentication != null) {
if (!currentAuthentication.getIdentity().equals(identity)) {
ErrorVO error = new ErrorVO();
error.setCode("unkown:409");
error.setTranslation("Authentication name used by: " + currentAuthentication.getIdentity().getUser().getEmail());
return Response.serverError().status(Status.CONFLICT).entity(error).build();
}
}
Authentication authentication = baseSecurity.createAndPersistAuthentication(identity, provider, authUsername, credentials, null);
if (authentication == null) {
return Response.serverError().status(Status.NOT_ACCEPTABLE).build();
}
log.audit("New authentication created for " + authUsername + " with provider " + provider);
AuthenticationVO savedAuth = ObjectFactory.get(authentication, true);
return Response.ok(savedAuth).build();
}
use of org.olat.basesecurity.Authentication in project OpenOLAT by OpenOLAT.
the class UserAuthenticationWebService method getAuthenticationTokenList.
/**
* Returns all user authentications
* @response.representation.200.qname {http://www.example.com}authenticationVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The list of all users in the OLAT system
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_AUTHVOes}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The identity not found
* @param username The username of the user to retrieve authentication
* @param request The HTTP request
* @return
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getAuthenticationTokenList(@PathParam("username") String username, @Context HttpServletRequest request) {
if (!isUserManager(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
BaseSecurity baseSecurity = BaseSecurityManager.getInstance();
Identity identity = baseSecurity.findIdentityByName(username);
if (identity == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
List<Authentication> authentications = baseSecurity.getAuthentications(identity);
AuthenticationVO[] vos = new AuthenticationVO[authentications.size()];
int count = 0;
for (Authentication authentication : authentications) {
vos[count++] = ObjectFactory.get(authentication, false);
}
return Response.ok(vos).build();
}
Aggregations