/* * Copyright 2015-Present Entando Inc. (http://www.entando.com) All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ package com.agiletec.plugins.jpldap.apsadmin.user; import com.agiletec.aps.system.ApsSystemUtils; import com.agiletec.aps.system.SystemConstants; import com.agiletec.aps.system.services.user.AbstractUser; import com.agiletec.aps.system.services.user.User; import com.agiletec.aps.system.services.user.UserDetails; import com.agiletec.apsadmin.system.ApsAdminSystemConstants; import com.agiletec.plugins.jpldap.aps.system.services.user.ILdapUserManager; import java.util.Date; /** * @author E.Santoboni */ public class UserAction extends org.entando.entando.apsadmin.user.UserAction { @Override public String edit() { this.setStrutsAction(ApsAdminSystemConstants.EDIT); try { String result = this.checkUserForEdit(); if (null != result) return result; String username = this.getUsername(); UserDetails user = this.getUserManager().getUser(username); this.setRemoteUser(!user.isEntandoUser()); this.setActive(!user.isDisabled()); this.setUser(user); } catch (Throwable t) { ApsSystemUtils.logThrowable(t, this, "edit"); return FAILURE; } return SUCCESS; } @Override protected String checkUserForEdit() throws Throwable { if (!this.existsUser(this.getUsername())) { this.addActionError(this.getText("error.user.notExist")); return "userList"; } if (!this.getUserManager().isWriteUserEnable() && !this.isEntandoUser(this.getUsername())) { this.addActionError(this.getText("error.user.notLocal")); return "userList"; } return null; } @Override protected String checkUserForDelete() throws Throwable { if (!this.existsUser(this.getUsername())) { this.addActionError(this.getText("error.user.notExist")); return "userList"; } else if (SystemConstants.ADMIN_USER_NAME.equals(this.getUsername())) { this.addActionError(this.getText("error.user.cannotDeleteAdminUser")); return "userList"; } else if (this.isCurrentUser()) { this.addActionError(this.getText("error.user.cannotDeleteCurrentUser")); return "userList"; } else if (!this.getUserManager().isWriteUserEnable() && !this.isEntandoUser(this.getUsername())) { this.addActionError(this.getText("error.user.cannotDeleteNotLocalUser")); return "userList"; } return null; } @Override public String save() { AbstractUser user = null; try { if (this.getStrutsAction() == ApsAdminSystemConstants.ADD) { user = new User(); user.setUsername(this.getUsername()); user.setPassword(this.getPassword()); } else if (this.getStrutsAction() == ApsAdminSystemConstants.EDIT) { user = (AbstractUser) this.getUserManager().getUser(this.getUsername()); if (null != this.getPassword() && this.getPassword().trim().length()>0) { user.setPassword(this.getPassword()); } } if (user instanceof User) { ((User) user).setDisabled(!this.isActive()); if (this.isReset()) { ((User) user).setLastAccess(new Date()); ((User) user).setLastPasswordChange(new Date()); } } if (this.getStrutsAction() == ApsAdminSystemConstants.ADD) { this.getUserManager().addUser(user); } else if (this.getStrutsAction() == ApsAdminSystemConstants.EDIT) { this.getUserManager().updateUser(user); if (null != this.getPassword() && this.getPassword().trim().length()>0) { this.getUserManager().changePassword(this.getUsername(), this.getPassword()); } } } catch (Throwable t) { ApsSystemUtils.logThrowable(t, this, "save"); return FAILURE; } return SUCCESS; } @Override protected ILdapUserManager getUserManager() { return (ILdapUserManager) super.getUserManager(); } public boolean isWriteUserEnable() { return this.getUserManager().isWriteUserEnable(); } public boolean isRemoteUser() { return _remoteUser; } public void setRemoteUser(boolean remoteUser) { this._remoteUser = remoteUser; } private boolean _remoteUser; }