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;
}
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);
}
}
Aggregations