Search in sources :

Example 1 with TokenAuthentication

use of org.bimserver.shared.TokenAuthentication in project BIMserver by opensourceBIM.

the class InternalServicesManager method getBimServerClient.

private P getBimServerClient(String serviceIdentifier, String profileIdentifier, String apiUrl, String token) {
    ServiceMapInterface serviceMapInterface = new ServiceMap(bimServer, null, AccessMethod.JSON);
    serviceMapInterface.add(RemoteServiceInterface.class, internalRemoteServiceInterfaces.get(serviceIdentifier));
    P p = new P();
    final InternalChannel internalChannel = new InternalChannel(bimServer.getServiceFactory(), bimServer.getServicesMap());
    try {
        internalChannel.connect(new SimpleTokenHolder());
    } catch (ChannelConnectionException e) {
        LOGGER.error("", e);
    }
    try {
        DatabaseSession session = bimServer.getDatabase().createSession();
        try {
            long profileId = Long.parseLong(profileIdentifier);
            EClass eClassForOid = session.getEClassForOid(profileId);
            InternalServicePluginConfiguration internalServicePluginConfiguration = null;
            if (eClassForOid == StorePackage.eINSTANCE.getInternalServicePluginConfiguration()) {
                internalServicePluginConfiguration = session.get(profileId, OldQuery.getDefault());
            } else if (eClassForOid == StorePackage.eINSTANCE.getService()) {
                Service service = session.get(profileId, OldQuery.getDefault());
                internalServicePluginConfiguration = service.getInternalService();
            } else {
                throw new RuntimeException("Oid is neither an InternalServicePluginConfiguration nor a Service");
            }
            final SObjectType settings = bimServer.getSConverter().convertToSObject(internalServicePluginConfiguration.getSettings());
            BimServerClientInterface bimServerClient = null;
            BimServerClientFactory factory = null;
            if (apiUrl == null) {
                factory = bimServer.getBimServerClientFactory();
            } else {
                if (factories.containsKey(apiUrl)) {
                    factory = factories.get(apiUrl);
                } else {
                    factory = new JsonBimServerClientFactory(apiUrl, bimServer.getServicesMap(), new JsonSocketReflectorFactory(bimServer.getServicesMap()), bimServer.getReflectorFactory(), bimServer.getMetaDataManager());
                    factories.put(apiUrl, factory);
                }
            }
            bimServerClient = factory.create(new TokenAuthentication(token));
            p.client = bimServerClient;
            p.settings = settings;
            return p;
        } catch (BimserverDatabaseException e) {
            LOGGER.error("", e);
        } catch (ServiceException e) {
            LOGGER.error("", e);
        } catch (ChannelConnectionException e) {
            LOGGER.error("", e);
        } finally {
            session.close();
        }
    } finally {
    }
    return null;
}
Also used : SObjectType(org.bimserver.interfaces.objects.SObjectType) ServiceMap(org.bimserver.webservices.ServiceMap) ChannelConnectionException(org.bimserver.shared.ChannelConnectionException) DatabaseSession(org.bimserver.database.DatabaseSession) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) Service(org.bimserver.models.store.Service) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) BimServerClientFactory(org.bimserver.shared.BimServerClientFactory) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) EClass(org.eclipse.emf.ecore.EClass) ServiceMapInterface(org.bimserver.shared.ServiceMapInterface) JsonSocketReflectorFactory(org.bimserver.client.json.JsonSocketReflectorFactory) ServiceException(org.bimserver.shared.exceptions.ServiceException) SimpleTokenHolder(org.bimserver.client.SimpleTokenHolder) InternalServicePluginConfiguration(org.bimserver.models.store.InternalServicePluginConfiguration) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) TokenAuthentication(org.bimserver.shared.TokenAuthentication)

Example 2 with TokenAuthentication

use of org.bimserver.shared.TokenAuthentication in project BIMserver by opensourceBIM.

the class BimServerClient method authenticate.

public void authenticate() throws ServerException, UserException {
    try {
        AuthInterface authInterface = channel.get(AuthInterface.class);
        if (authenticationInfo instanceof UsernamePasswordAuthenticationInfo) {
            UsernamePasswordAuthenticationInfo usernamePasswordAuthenticationInfo = (UsernamePasswordAuthenticationInfo) authenticationInfo;
            setToken(authInterface.login(usernamePasswordAuthenticationInfo.getUsername(), usernamePasswordAuthenticationInfo.getPassword()));
        } else if (authenticationInfo instanceof AutologinAuthenticationInfo) {
            AutologinAuthenticationInfo autologinAuthenticationInfo = (AutologinAuthenticationInfo) authenticationInfo;
            setToken(autologinAuthenticationInfo.getAutologinCode());
        } else if (authenticationInfo instanceof TokenAuthentication) {
            TokenAuthentication tokenAuthentication = (TokenAuthentication) authenticationInfo;
            setToken(tokenAuthentication.getToken());
        } else if (authenticationInfo instanceof UserTokenAuthentication) {
            UserTokenAuthentication tokenAuthentication = (UserTokenAuthentication) authenticationInfo;
            setToken(authInterface.loginUserToken(tokenAuthentication.getToken()));
        } else if (authenticationInfo instanceof SystemAuthentication) {
        }
    } catch (PublicInterfaceNotFoundException e) {
        LOGGER.error("", e);
    }
}
Also used : AuthInterface(org.bimserver.shared.interfaces.AuthInterface) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) UserTokenAuthentication(org.bimserver.shared.UserTokenAuthentication) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) AutologinAuthenticationInfo(org.bimserver.shared.AutologinAuthenticationInfo) TokenAuthentication(org.bimserver.shared.TokenAuthentication) UserTokenAuthentication(org.bimserver.shared.UserTokenAuthentication) SystemAuthentication(org.bimserver.shared.SystemAuthentication)

Aggregations

TokenAuthentication (org.bimserver.shared.TokenAuthentication)2 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)1 SimpleTokenHolder (org.bimserver.client.SimpleTokenHolder)1 JsonBimServerClientFactory (org.bimserver.client.json.JsonBimServerClientFactory)1 JsonSocketReflectorFactory (org.bimserver.client.json.JsonSocketReflectorFactory)1 DatabaseSession (org.bimserver.database.DatabaseSession)1 SObjectType (org.bimserver.interfaces.objects.SObjectType)1 InternalServicePluginConfiguration (org.bimserver.models.store.InternalServicePluginConfiguration)1 Service (org.bimserver.models.store.Service)1 BimServerClientInterface (org.bimserver.plugins.services.BimServerClientInterface)1 AutologinAuthenticationInfo (org.bimserver.shared.AutologinAuthenticationInfo)1 BimServerClientFactory (org.bimserver.shared.BimServerClientFactory)1 ChannelConnectionException (org.bimserver.shared.ChannelConnectionException)1 ServiceMapInterface (org.bimserver.shared.ServiceMapInterface)1 SystemAuthentication (org.bimserver.shared.SystemAuthentication)1 UserTokenAuthentication (org.bimserver.shared.UserTokenAuthentication)1 UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)1 PublicInterfaceNotFoundException (org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)1 ServiceException (org.bimserver.shared.exceptions.ServiceException)1 AuthInterface (org.bimserver.shared.interfaces.AuthInterface)1