Search in sources :

Example 6 with OAuthAuthorizationCode

use of org.bimserver.models.store.OAuthAuthorizationCode in project BIMserver by opensourceBIM.

the class ServiceImpl method getAllPrivateProfiles.

@Override
public List<SProfileDescriptor> getAllPrivateProfiles(String notificationsUrl, String serviceIdentifier) throws ServerException, UserException {
    if (notificationsUrl == null) {
        throw new UserException("Missing notificationsUrl");
    }
    requireRealUserAuthentication();
    try (DatabaseSession session = getBimServer().getDatabase().createSession()) {
        try (BimServerClientFactory factory = new JsonBimServerClientFactory(notificationsUrl, getBimServer().getServicesMap(), getBimServer().getJsonSocketReflectorFactory(), getBimServer().getReflectorFactory(), getBimServer().getMetaDataManager())) {
            BimServerClientInterface client = factory.create();
            OAuthServer oAuthServer = session.querySingle(StorePackage.eINSTANCE.getOAuthServer_ApiUrl(), notificationsUrl);
            User user = session.get(StorePackage.eINSTANCE.getUser(), getAuthorization().getUoid(), OldQuery.getDefault());
            for (OAuthAuthorizationCode oAuthAuthorizationCode : user.getOAuthAuthorizationCodes()) {
                if (oAuthAuthorizationCode.getOauthServer() == oAuthServer) {
                    return client.getRemoteServiceInterface().getPrivateProfiles(serviceIdentifier, oAuthAuthorizationCode.getCode());
                }
            }
            return null;
        }
    } catch (Exception e) {
        return handleException(e);
    }
}
Also used : SUser(org.bimserver.interfaces.objects.SUser) User(org.bimserver.models.store.User) DatabaseSession(org.bimserver.database.DatabaseSession) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) UserException(org.bimserver.shared.exceptions.UserException) OAuthServer(org.bimserver.models.store.OAuthServer) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) BimServerClientFactory(org.bimserver.shared.BimServerClientFactory) OAuthAuthorizationCode(org.bimserver.models.store.OAuthAuthorizationCode) IOException(java.io.IOException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) SerializerException(org.bimserver.plugins.serializers.SerializerException) BcfException(org.opensourcebim.bcf.BcfException) UserException(org.bimserver.shared.exceptions.UserException) CannotBeScheduledException(org.bimserver.longaction.CannotBeScheduledException) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) ServerException(org.bimserver.shared.exceptions.ServerException) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException)

Aggregations

BimserverDatabaseException (org.bimserver.BimserverDatabaseException)6 DatabaseSession (org.bimserver.database.DatabaseSession)6 OAuthAuthorizationCode (org.bimserver.models.store.OAuthAuthorizationCode)6 User (org.bimserver.models.store.User)5 ServerException (org.bimserver.shared.exceptions.ServerException)4 UserException (org.bimserver.shared.exceptions.UserException)4 SOAuthAuthorizationCode (org.bimserver.interfaces.objects.SOAuthAuthorizationCode)3 OAuthServer (org.bimserver.models.store.OAuthServer)3 IOException (java.io.IOException)2 ServletException (javax.servlet.ServletException)2 OAuthProblemException (org.apache.oltu.oauth2.common.exception.OAuthProblemException)2 OAuthSystemException (org.apache.oltu.oauth2.common.exception.OAuthSystemException)2 OAuthResponse (org.apache.oltu.oauth2.common.message.OAuthResponse)2 Authorization (org.bimserver.models.store.Authorization)2 RunServiceAuthorization (org.bimserver.models.store.RunServiceAuthorization)2 SingleProjectAuthorization (org.bimserver.models.store.SingleProjectAuthorization)2 PrintWriter (java.io.PrintWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1