use of org.apache.openmeetings.util.OmException in project openmeetings by apache.
the class UserDao method login.
/**
* login logic
*
* @param userOrEmail - login or email of the user being tested
* @param userpass - password of the user being tested
* @return User object in case of successful login
* @throws OmException in case of any issue
*/
public User login(String userOrEmail, String userpass) throws OmException {
List<User> users = em.createNamedQuery("getUserByLoginOrEmail", User.class).setParameter("userOrEmail", userOrEmail).setParameter("type", Type.user).getResultList();
log.debug("login:: {} users were found", users.size());
if (users.isEmpty()) {
log.debug("No users was found: {}", userOrEmail);
return null;
}
User u = users.get(0);
if (!verifyPassword(u.getId(), userpass)) {
log.debug("Password does not match: {}", u);
return null;
}
// Check if activated
if (!AuthLevelUtil.hasLoginLevel(u.getRights())) {
log.debug("Not activated: {}", u);
throw new OmException("error.notactivated");
}
log.debug("loginUser " + u.getGroupUsers());
if (u.getGroupUsers().isEmpty()) {
log.debug("No Group assigned: {}", u);
throw new OmException("error.nogroup");
}
u.setLastlogin(new Date());
return update(u, u.getId());
}
use of org.apache.openmeetings.util.OmException in project openmeetings by apache.
the class WebSession method isSignedIn.
@Override
public boolean isSignedIn() {
if (userId == null) {
IAuthenticationStrategy strategy = getAuthenticationStrategy();
// get username and password from persistence store
String[] data = strategy.load();
if (data != null && data.length > 3 && data[2] != null) {
Long domainId = null;
try {
domainId = Long.valueOf(data[3]);
} catch (Exception e) {
// no-op
}
// try to sign in the user
try {
if (!signIn(data[0], data[1], Type.valueOf(data[2]), domainId)) {
// the loaded credentials are wrong. erase them.
strategy.remove();
}
} catch (OmException e) {
// no-op, bad credentials
}
}
}
return userId != null && userId.longValue() > 0;
}
use of org.apache.openmeetings.util.OmException in project openmeetings by apache.
the class WebSession method signIn.
public boolean signIn(String login, String password, Type type, Long domainId) throws OmException {
User u;
switch(type) {
case ldap:
u = ldapManager.login(login, password, domainId);
break;
case user:
/* we will allow login against internal DB in case user 'guess' LDAP password */
u = userDao.login(login, password);
break;
case oauth:
// we did all the checks at this stage, just set the user
u = userDao.getByLogin(login, Type.oauth, domainId);
break;
default:
throw new OmException("error.unknown");
}
if (u == null) {
return false;
}
signIn(u);
return true;
}
use of org.apache.openmeetings.util.OmException in project openmeetings by apache.
the class SignInDialog method onSubmit.
@Override
protected void onSubmit(AjaxRequestTarget target) {
if (domain.getAddDomainToUserName()) {
login = login + "@" + domain.getDomain();
}
OmAuthenticationStrategy strategy = getAuthenticationStrategy();
WebSession ws = WebSession.get();
Type type = domain.getId() > 0 ? Type.ldap : Type.user;
boolean signIn = false;
try {
signIn = ws.signIn(login, password, type, domain.getId());
} catch (OmException e) {
error(getString(e.getKey()));
target.add(feedback);
}
if (signIn) {
setResponsePage(Application.get().getHomePage());
if (rememberMe) {
strategy.save(login, password, type, domain.getId());
} else {
strategy.remove();
}
} else {
if (!hasErrorMessage()) {
error(getString("error.bad.credentials"));
target.add(feedback);
}
// add random timeout
try {
Thread.sleep(6 + (long) (10 * Math.random() * 1000));
} catch (InterruptedException e) {
log.error("Unexpected exception while sleeping", e);
}
strategy.remove();
shake(target);
}
}
use of org.apache.openmeetings.util.OmException in project openmeetings by apache.
the class LdapLoginManager method login.
/**
* Ldap Login
*
* Connection Data is retrieved from ConfigurationFile
*
* @param _login - user login
* @param passwd - user password
* @param domainId - user domain id
* @return - {@link User} with this credentials or <code>null</code>
* @throws OmException - in case of any error
*/
public User login(String _login, String passwd, Long domainId) throws OmException {
log.debug("LdapLoginmanager.doLdapLogin");
if (!userDao.validLogin(_login)) {
log.error("Invalid login provided");
return null;
}
User u = null;
try (LdapWorker w = new LdapWorker(domainId)) {
String login = w.options.useLowerCase ? _login.toLowerCase() : _login;
boolean authenticated = true;
Dn userDn = null;
Entry entry = null;
switch(w.options.type) {
case SEARCHANDBIND:
{
bindAdmin(w.conn, w.options);
Dn baseDn = new Dn(w.options.searchBase);
String searchQ = String.format(w.options.searchQuery, login);
try (EntryCursor cursor = new EntryCursorImpl(w.conn.search(new SearchRequestImpl().setBase(baseDn).setFilter(searchQ).setScope(w.options.scope).addAttributes("*").setDerefAliases(w.options.derefMode)))) {
while (cursor.next()) {
try {
Entry e = cursor.get();
if (userDn != null) {
log.error("more than 1 user found in LDAP");
throw UNKNOWN;
}
userDn = e.getDn();
if (w.options.useAdminForAttrs) {
entry = e;
}
} catch (CursorLdapReferralException cle) {
log.warn("Referral LDAP entry found, ignore it");
}
}
}
if (userDn == null) {
log.error("NONE users found in LDAP");
throw BAD_CREDENTIALS;
}
w.conn.bind(userDn, passwd);
}
break;
case SIMPLEBIND:
userDn = new Dn(String.format(w.options.userDn, login));
w.conn.bind(userDn, passwd);
break;
case NONE:
default:
authenticated = false;
break;
}
u = authenticated ? userDao.getByLogin(login, Type.ldap, domainId) : userDao.login(login, passwd);
log.debug("getByLogin:: authenticated ? {}, login = '{}', domain = {}, user = {}", authenticated, login, domainId, u);
if (u == null && Provisionning.AUTOCREATE != w.options.prov) {
log.error("User not found in OM DB and Provisionning.AUTOCREATE was not set");
throw BAD_CREDENTIALS;
}
if (authenticated && entry == null) {
if (w.options.useAdminForAttrs) {
bindAdmin(w.conn, w.options);
}
entry = w.conn.lookup(userDn);
}
switch(w.options.prov) {
case AUTOUPDATE:
case AUTOCREATE:
u = w.getUser(entry, u);
if (w.options.syncPasswd) {
u.updatePassword(cfgDao, passwd);
}
u = userDao.update(u, null);
break;
case NONE:
default:
break;
}
} catch (LdapAuthenticationException ae) {
log.error("Not authenticated.", ae);
throw BAD_CREDENTIALS;
} catch (OmException e) {
throw e;
} catch (Exception e) {
log.error("Unexpected exception.", e);
throw new OmException(e);
}
return u;
}
Aggregations