Search in sources :

Example 1 with InternalAuth

use of fi.otavanopisto.muikku.plugins.internalauth.model.InternalAuth in project muikku by otavanopisto.

the class InternalAuthDAO method findByUserId.

public InternalAuth findByUserId(Long userEntityId) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<InternalAuth> criteria = criteriaBuilder.createQuery(InternalAuth.class);
    Root<InternalAuth> root = criteria.from(InternalAuth.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.equal(root.get(InternalAuth_.userEntityId), userEntityId));
    return getSingleResult(entityManager.createQuery(criteria));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) InternalAuth(fi.otavanopisto.muikku.plugins.internalauth.model.InternalAuth)

Example 2 with InternalAuth

use of fi.otavanopisto.muikku.plugins.internalauth.model.InternalAuth in project muikku by otavanopisto.

the class InternalAuthDAO method updatePassword.

public void updatePassword(UserEntity user, String passwordHash, String newPasswordHash) {
    InternalAuth internalAuth = findByUserIdAndPassword(user.getId(), passwordHash);
    internalAuth.setPassword(newPasswordHash);
    persist(internalAuth);
}
Also used : InternalAuth(fi.otavanopisto.muikku.plugins.internalauth.model.InternalAuth)

Example 3 with InternalAuth

use of fi.otavanopisto.muikku.plugins.internalauth.model.InternalAuth in project muikku by otavanopisto.

the class InternalAuthController method confirmUserPassword.

public boolean confirmUserPassword(UserEntity user, String password) {
    String passwordHash = DigestUtils.md5Hex(password);
    InternalAuth internalAuth = internalAuthDAO.findByUserIdAndPassword(user.getId(), passwordHash);
    return internalAuth != null;
}
Also used : InternalAuth(fi.otavanopisto.muikku.plugins.internalauth.model.InternalAuth)

Example 4 with InternalAuth

use of fi.otavanopisto.muikku.plugins.internalauth.model.InternalAuth in project muikku by otavanopisto.

the class InternalAuthController method findInternalAuthByEmailAndPassword.

public InternalAuth findInternalAuthByEmailAndPassword(String email, String password) {
    String passwordHash = DigestUtils.md5Hex(password);
    UserEntity userEntity = userEntityController.findUserEntityByEmailAddress(email);
    if (userEntity != null) {
        InternalAuth internalAuth = internalAuthDAO.findByUserIdAndPassword(userEntity.getId(), passwordHash);
        return internalAuth;
    }
    return null;
}
Also used : InternalAuth(fi.otavanopisto.muikku.plugins.internalauth.model.InternalAuth) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity)

Example 5 with InternalAuth

use of fi.otavanopisto.muikku.plugins.internalauth.model.InternalAuth in project muikku by otavanopisto.

the class InternalAuthenticationStrategy method processLogin.

@Override
public AuthenticationResult processLogin(AuthSource authSource, Map<String, String[]> requestParameters) {
    String email = StringUtils.lowerCase(getFirstRequestParameter(requestParameters, "email"));
    String password = getFirstRequestParameter(requestParameters, "password");
    InternalAuth internalAuth = internalLoginController.findInternalAuthByEmailAndPassword(email, password);
    if (internalAuth != null) {
        UserEntity userEntity = userEntityController.findUserEntityById(internalAuth.getUserEntityId());
        if (userEntity != null) {
            return processLogin(authSource, requestParameters, DigestUtils.md5Hex("INTERNAL-" + internalAuth.getId()), Arrays.asList(email), null, null);
        }
    }
    return new AuthenticationResult(Status.INVALID_CREDENTIALS);
}
Also used : InternalAuth(fi.otavanopisto.muikku.plugins.internalauth.model.InternalAuth) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) AuthenticationResult(fi.otavanopisto.muikku.auth.AuthenticationResult)

Aggregations

InternalAuth (fi.otavanopisto.muikku.plugins.internalauth.model.InternalAuth)7 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)2 EntityManager (javax.persistence.EntityManager)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 AuthenticationResult (fi.otavanopisto.muikku.auth.AuthenticationResult)1