+/*
+ * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.argeo.security.core;
import org.argeo.ArgeoException;
private String systemAuthenticationKey;
+ public ArgeoUser getCurrentUser() {
+ ArgeoUser argeoUser = ArgeoUserDetails.securityContextUser();
+ if (argeoUser == null)
+ return null;
+ if (argeoUser.getRoles().contains(securityDao.getDefaultRole()))
+ argeoUser.getRoles().remove(securityDao.getDefaultRole());
+ return argeoUser;
+ }
+
public ArgeoSecurityDao getSecurityDao() {
return securityDao;
}
}
public void updateUserPassword(String username, String password) {
- SimpleArgeoUser user = new SimpleArgeoUser(securityDao
- .getUser(username));
+ SimpleArgeoUser user = new SimpleArgeoUser(
+ securityDao.getUser(username));
user.setPassword(password);
securityDao.update(user);
}
public void updateCurrentUserPassword(String oldPassword, String newPassword) {
- SimpleArgeoUser user = new SimpleArgeoUser(securityDao.getCurrentUser());
- if (!user.getPassword().equals(oldPassword))
+ SimpleArgeoUser user = new SimpleArgeoUser(getCurrentUser());
+ if (!securityDao.isPasswordValid(user.getPassword(), oldPassword))
throw new ArgeoException("Old password is not correct.");
- user.setPassword(newPassword);
+ user.setPassword(securityDao.encodePassword(newPassword));
securityDao.update(user);
}
public void setSystemAuthenticationKey(String systemAuthenticationKey) {
this.systemAuthenticationKey = systemAuthenticationKey;
}
-
}