Search in sources :

Example 1 with SOAuthServer

use of org.bimserver.interfaces.objects.SOAuthServer in project BIMserver by opensourceBIM.

the class OAuthServiceImpl method listRegisteredServersLocal.

@Override
public List<SOAuthServer> listRegisteredServersLocal() throws ServerException, UserException {
    try (DatabaseSession session = getBimServer().getDatabase().createSession()) {
        List<OAuthServer> allOfType = session.getAllOfType(StorePackage.eINSTANCE.getOAuthServer(), OAuthServer.class, OldQuery.getDefault());
        Iterator<OAuthServer> iterator = allOfType.iterator();
        while (iterator.hasNext()) {
            OAuthServer next = iterator.next();
            if (!next.isIncoming()) {
                iterator.remove();
            }
        }
        return getBimServer().getSConverter().convertToSListOAuthServer(allOfType);
    } catch (BimserverDatabaseException e) {
        return handleException(e);
    }
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) DatabaseSession(org.bimserver.database.DatabaseSession) SOAuthServer(org.bimserver.interfaces.objects.SOAuthServer) OAuthServer(org.bimserver.models.store.OAuthServer)

Example 2 with SOAuthServer

use of org.bimserver.interfaces.objects.SOAuthServer in project BIMserver by opensourceBIM.

the class OAuthServiceImpl method listRegisteredServers.

@Override
public List<SOAuthServer> listRegisteredServers() throws ServerException, UserException {
    try (DatabaseSession session = getBimServer().getDatabase().createSession()) {
        List<OAuthServer> allOfType = session.getAllOfType(StorePackage.eINSTANCE.getOAuthServer(), OAuthServer.class, OldQuery.getDefault());
        Iterator<OAuthServer> iterator = allOfType.iterator();
        while (iterator.hasNext()) {
            OAuthServer next = iterator.next();
            if (next.isIncoming()) {
                iterator.remove();
            }
        }
        return getBimServer().getSConverter().convertToSListOAuthServer(allOfType);
    } catch (BimserverDatabaseException e) {
        return handleException(e);
    }
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) DatabaseSession(org.bimserver.database.DatabaseSession) SOAuthServer(org.bimserver.interfaces.objects.SOAuthServer) OAuthServer(org.bimserver.models.store.OAuthServer)

Example 3 with SOAuthServer

use of org.bimserver.interfaces.objects.SOAuthServer in project BIMserver by opensourceBIM.

the class OAuthServiceImpl method registerRemoteApplication.

public SOAuthServer registerRemoteApplication(String redirectUrl, String name, String description) throws UserException {
    try {
        OAuthClientRequest request = OAuthClientRegistrationRequest.location(getBimServer().getServerSettingsCache().getServerSettings().getSiteAddress() + "/oauth/register/", OAuthRegistration.Type.PUSH).setName(name).setUrl(redirectUrl).setDescription(description).setRedirectURL(redirectUrl).buildJSONMessage();
        OAuthRegistrationClient oauthclient = new OAuthRegistrationClient(new org.bimserver.webservices.impl.URLConnectionClient());
        OAuthClientRegistrationResponse response = oauthclient.clientInfo(request);
        SOAuthServer server = new SOAuthServer();
        server.setClientId(response.getClientId());
        server.setClientSecret(response.getClientSecret());
        return server;
    } catch (Exception e) {
        throw new UserException(e);
    }
}
Also used : OAuthRegistrationClient(org.apache.oltu.oauth2.ext.dynamicreg.client.OAuthRegistrationClient) OAuthClientRegistrationResponse(org.apache.oltu.oauth2.ext.dynamicreg.client.response.OAuthClientRegistrationResponse) SOAuthServer(org.bimserver.interfaces.objects.SOAuthServer) UserException(org.bimserver.shared.exceptions.UserException) OAuthClientRequest(org.apache.oltu.oauth2.client.request.OAuthClientRequest) UserException(org.bimserver.shared.exceptions.UserException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Aggregations

BimserverDatabaseException (org.bimserver.BimserverDatabaseException)3 SOAuthServer (org.bimserver.interfaces.objects.SOAuthServer)3 DatabaseSession (org.bimserver.database.DatabaseSession)2 OAuthServer (org.bimserver.models.store.OAuthServer)2 OAuthClientRequest (org.apache.oltu.oauth2.client.request.OAuthClientRequest)1 OAuthRegistrationClient (org.apache.oltu.oauth2.ext.dynamicreg.client.OAuthRegistrationClient)1 OAuthClientRegistrationResponse (org.apache.oltu.oauth2.ext.dynamicreg.client.response.OAuthClientRegistrationResponse)1 ServerException (org.bimserver.shared.exceptions.ServerException)1 UserException (org.bimserver.shared.exceptions.UserException)1