Project

General

Profile

« Previous | Next » 

Revision bfedf5f3

Added by Katja Luther about 4 years ago

fix #8925: and fix #8927 use role_admin for check whether user is admin and check for user_manager for right to edit pwd

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/LoginManager.java
25 25
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
26 26
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
27 27
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
28
import eu.etaxonomy.cdm.api.utility.CdmUserHelper;
29
import eu.etaxonomy.cdm.api.utility.RoleProber;
28 30
import eu.etaxonomy.cdm.model.permission.Group;
29 31
import eu.etaxonomy.cdm.model.permission.User;
30 32
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
33
import eu.etaxonomy.cdm.persistence.hibernate.permission.Role;
31 34
import eu.etaxonomy.taxeditor.model.IContextListener;
32 35
import eu.etaxonomy.taxeditor.model.MessagingUtils;
33 36

  
......
48 51
	public static final String ACCOUNT_LOCKED_MESSAGE = "Account is locked";
49 52
	public static final String EMPTY_CREDENTIALS_MESSAGE = "Login and/or Password empty";
50 53

  
54

  
55
    private CdmUserHelper userHelper = null;
56

  
51 57
	public LoginManager(){
52 58
	    CdmStore.getContextManager().addContextListener(this);
59

  
53 60
	}
54 61

  
55 62
	/**
......
106 113
	    } catch(LockedException e){
107 114
	        throw new CdmAuthenticationException(ACCOUNT_LOCKED_MESSAGE, e);
108 115
	    } catch(IllegalArgumentException e){
116
	        e.printStackTrace();
109 117
	        throw new CdmAuthenticationException(EMPTY_CREDENTIALS_MESSAGE, e);
110 118
	    }
111 119

  
......
163 171
	 * @return
164 172
	 */
165 173
	public boolean isAdmin() {
166
		// FIXME until we have rights implemented properly we do this
167
		// by a simple string check. This has to change
168

  
169
		return "admin".equals(getAuthenticatedUser().getUsername());
174
	    if (userHelper == null){
175
	        userHelper = new CdmUserHelper();
176
	    }
177
	    boolean result = userHelper.userIs(new RoleProber(Role.ROLE_ADMIN));
178
        return result;
170 179
	}
171 180

  
181
	/**
182
     * Whether the current user has the role user manager
183
     *
184
     * @return
185
     */
186
    public boolean isUserManager() {
187
        if (userHelper == null){
188
            userHelper = new CdmUserHelper();
189
        }
190
        boolean result = userHelper.userIs(new RoleProber(Role.ROLE_USER_MANAGER));
191
        return result;
192
    }
193

  
172 194
	@Override
173 195
	public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
174 196

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/user/UserDetailElement.java
27 27
	private CheckboxElement checkbox_accountNonLocked;
28 28
	private CheckboxElement checkbox_accountNonExpired;
29 29

  
30

  
31

  
30 32
	public UserDetailElement(CdmFormFactory formFactory,
31 33
			ICdmFormElement formElement) {
32 34
		super(formFactory, formElement);
......
48 50
		// Disabling the text field since the user entity is immutable
49 51
		text_username.setEnabled(false);
50 52

  
51
		if (userIsAuthenticated() || CdmStore.getLoginManager().isAdmin()) {
53
		if (userIsAuthenticated() || CdmStore.getLoginManager().isUserManager() || CdmStore.getLoginManager().isAdmin() ) {
52 54
			formFactory.createEditPasswordElement(
53 55
					formElement, "Change Password", getConversationHolder(),
54 56
					entity, style);
......
77 79
//				entity.isCredentialsNonExpired(), style);
78 80
	}
79 81

  
80
	/**
82

  
83
    /**
81 84
	 *
82 85
	 * @return
83 86
	 */

Also available in: Unified diff