Search in sources :

Example 1 with UserNotFoundException

use of net.geoprism.registry.session.UserNotFoundException in project geoprism-registry by terraframe.

the class RegistrySessionService method getActor.

@Transaction
private static synchronized SingleActorDAOIF getActor(OauthServer server, String username) throws JSONException {
    UsersQuery query = new UsersQuery(new QueryFactory());
    query.WHERE(query.getUsername().EQ(username));
    OIterator<? extends Users> it = query.getIterator();
    try {
        if (it.hasNext()) {
            UserDAO user = (UserDAO) BusinessFacade.getEntityDAO(it.next());
            try {
                GeoprismUser geoprismUser = GeoprismUser.getByUsername(user.getUsername());
                UserInfo userInfo = UserInfo.getByUser(geoprismUser);
                ExternalSystem system = ExternalSystem.get(userInfo.getExternalSystemOid());
                if (system instanceof DHIS2ExternalSystem) {
                    DHIS2ExternalSystem dhis2System = (DHIS2ExternalSystem) system;
                    if (dhis2System.getOauthServerOid().equals(server.getOid())) {
                        return user;
                    }
                }
            } catch (Throwable t) {
                logger.error("Encountered an unexpected error while logging user in.", t);
            }
            UserNotOuathEnabledException ex = new UserNotOuathEnabledException();
            ex.setUsername(user.getUsername());
            ex.setOauthServer(server.getDisplayLabel().getValue());
            throw ex;
        } else {
            UserNotFoundException ex = new UserNotFoundException();
            ex.setUsername(username);
            throw ex;
        }
    } finally {
        it.close();
    }
}
Also used : UserNotFoundException(net.geoprism.registry.session.UserNotFoundException) UserNotOuathEnabledException(net.geoprism.registry.session.UserNotOuathEnabledException) QueryFactory(com.runwaysdk.query.QueryFactory) UserDAO(com.runwaysdk.business.rbac.UserDAO) DHIS2ExternalSystem(net.geoprism.registry.graph.DHIS2ExternalSystem) UsersQuery(com.runwaysdk.system.UsersQuery) DHIS2ExternalSystem(net.geoprism.registry.graph.DHIS2ExternalSystem) ExternalSystem(net.geoprism.registry.graph.ExternalSystem) GeoprismUser(net.geoprism.GeoprismUser) UserInfo(net.geoprism.registry.UserInfo) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Aggregations

UserDAO (com.runwaysdk.business.rbac.UserDAO)1 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)1 QueryFactory (com.runwaysdk.query.QueryFactory)1 UsersQuery (com.runwaysdk.system.UsersQuery)1 GeoprismUser (net.geoprism.GeoprismUser)1 UserInfo (net.geoprism.registry.UserInfo)1 DHIS2ExternalSystem (net.geoprism.registry.graph.DHIS2ExternalSystem)1 ExternalSystem (net.geoprism.registry.graph.ExternalSystem)1 UserNotFoundException (net.geoprism.registry.session.UserNotFoundException)1 UserNotOuathEnabledException (net.geoprism.registry.session.UserNotOuathEnabledException)1