I configured spring social for facebook and also the spring social authentication in my application with a custom UsersConnectionRepository and ConnectionRepository.
Configuration file
#Configuration
public class SocialConfig extends SocialConfigurerAdapter{
...
#Override
public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator factoryLocator) {
SecUsersConnectionRepository repository = new SecUsersConnectionRepository(factoryLocator, userRepository, userConnectionRepository);
return repository;
}
...
}
Connection Repository implementation
public class SecConnectionRepository implements ConnectionRepository {
...
#Override
public void addConnection(Connection<?> connection) {
UserConnection userConnection = userRepository.findConnectionBy(user, connection.getKey().getProviderId(), connection.getKey().getProviderUserId());
if (userConnection == null) {
...
userConnection.setProviderId(data.getProviderId());
userConnection.setProviderUserId(data.getProviderUserId());
userConnection.setDisplayName(data.getDisplayName());
userConnection.setProfileUrl(data.getProfileUrl());
userConnection.setImageUrl(data.getImageUrl());
...
} else {
throw new DuplicateConnectionException(connection.getKey());
}
}
When I add my facebook login, the Connect<A> interface object fetch the profileUrl, But the URL is in this format
https://www.facebook.com/profile.php?id=XXXXXXXXXXXXXXX&_rdr
If I open up this link the browser is says
Gradle file
buildscript {
repositories {
maven { url "https://repo.spring.io/libs-release" }
... }
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.3.RELEASE")
}
}
apply plugin: 'java'
...
jar {...}
repositories {
...
maven { url "https://repo.spring.io/libs-release" }
}
dependencies {
...
compile("org.springframework.social:spring-social-facebook")
compile("org.springframework.social:spring-social-security")
... }
task wrapper(type: Wrapper) {...}
What am I doing wrong here?
SOLUTION
updating the FB libary in spring solved the issue.
compile("org.springframework.social:spring-social-facebook:2.0.1.RELEASE")
Check if you're using the most recent version of Spring Social. The profileUrl should nowadays have the scheme
https://www.facebook.com/app_scoped_user_id/{app_scoped_user_id}/
where {app_scoped_user_id} is the actual app-scoped user id.
See
https://developers.facebook.com/docs/apps/changelog#v2_0_graph_api
Related
I just write a class which extends Transform class like this:
package com.example.plugin;
import org.gradle.internal.impldep.org.apache.commons.io.FileUtils;
import ...;
public class MyTransform extends Transform{
...
#Override
public void transform(TransformInvocation transformInvocation) throws TransformException, InterruptedException, IOException {
Collection<TransformInput> inputs = transformInvocation.getInputs();
TransformOutputProvider outputProvider = transformInvocation.getOutputProvider();
inputs.forEach(transformInput -> {
transformInput.getJarInputs().forEach(jarInput -> {
File dest = outputProvider.getContentLocation(jarInput.getName(), jarInput.getContentTypes(), jarInput.getScopes(), Format.JAR);
try {
// System.out.println(jarInput.getName());
FileUtils.copyFile(jarInput.getFile(), dest);
} catch (IOException e) {
e.printStackTrace();
}
});
transformInput.getDirectoryInputs().forEach(directoryInput -> {
File dest = outputProvider.getContentLocation(directoryInput.getName(), directoryInput.getContentTypes(), directoryInput.getScopes(), Format.DIRECTORY);
try {
// System.out.println(directoryInput.getName());
FileUtils.copyDirectoryToDirectory(directoryInput.getFile(), dest);
} catch (IOException e) {
e.printStackTrace();
}
});
});
}
}
However, when I use it on other gradle application, it got error with gradle build:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesWithMr_Spade is coming.ForDebug'.
> org/gradle/internal/impldep/org/apache/commons/io/FileUtils
It seems that the class FileUtils has some problems, but I just don't know what's wrong.
Here is the build.gradle of plugin:
plugins {
// Apply the Java Gradle plugin development plugin to add support for developing Gradle plugins
id 'java-gradle-plugin'
id 'maven-publish'
}
dependencies {
implementation 'org.testng:testng:7.4.0'
// Use JUnit Jupiter for testing.
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
implementation 'com.android.tools.build:gradle:7.1.3'
implementation "androidx.navigation:navigation-safe-args-gradle-plugin:2.4.2"
// implementation 'org.ow2.asm:asm:9.2'
// implementation 'org.ow2.asm:asm-tree:9.2'
implementation 'org.apache.commons:commons-io:1.3.2'
}
gradlePlugin {
// Define the plugin
plugins {
greeting {
id = 'com.example.plugin.greeting'
implementationClass = 'com.example.plugin.Plugin_project_namePlugin'
}
}
}
publishing {
publications {
maven(MavenPublication) {
groupId = 'aaa.bbb'
artifactId = 'ccc.ddd'
version = '1.0'
from components.java
}
}
repositories {
maven {
// change to point to your repo, e.g. http://my.org/repo
url = layout.buildDirectory.dir('../../repo')
}
}
}
...
build.gradle of application:
plugins {
id 'com.android.application'
id 'com.example.plugin.greeting'
}
...
dependencies {
// implementation gradleApi() //gradle sdk
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
// implementation 'org.apache.commons:commons-io:1.3.2'
...
}
By the way, since my plugin folder and app folder are in the same folder, so i will use command like "build"(for plugin)->"publish"(for plugin)->"build"(for app), and the fact is the first two step is success, but the last step is failed. Just like that the plugin itself do not have problem but occurs some problem when it work on the app :(
I'm trying to use a fragment autocomplete UI from ---> https://docs.mapbox.com/android/plugins/overview/places/
but the IDE says that it can't resolve the symbol CarmenFeature and I don't know how to import that class or solve this exception
I've tried :
to import ---> import com.mapbox.api.v4.models.CarmenFeature;
but I think that the API folder does not exist
sync with gradle
invalidate cache and restart
rebuild project
clean project
autocompleteFragment = (SupportPlaceAutocompleteFragment) getSupportFragmentManager().findFragmentByTag(TAG);
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
#Override
public void onPlaceSelected( CarmenFeature carmenFeature) {
}
#Override
public void onError(Status status) {
}
});
Well the problem is that the class cannot be imported and loaded. You need to configure inside the build.gradle in the root of your project :
allprojects {
repositories {
...
...
maven
{
url 'https://mapbox.bintray.com/mapbox'
}
}
}
and inside your /app/build.gradle :
dependencies {
...
...
// MAPBOX DEPENDENCIES
implementation ('com.mapbox.mapboxsdk:mapbox-android-sdk:6.5.0#aar')
{
transitive=true
}
implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation:0.20.0'
implementation ('com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.20.0')
{
transitive = true
}
implementation 'com.google.android.gms:play-services-maps:16.0.0'
implementation 'com.android.support:design:27.0.2'
}
this is enough to use the CarmenFeature class.
I've created a small Apache Camel example, but it can't find the class org.apache.camel.impl.DefaultComponent. Here the full error log.
I've looked the class up on search.maven.org, which says it should be contained in org.apache.camel:camel-core. Adding it does not solve my problem.
What's wrong in this example?
This is the application
#SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication app = new SpringApplication(Application.class);
app.setWebApplicationType(WebApplicationType.NONE);
app.run(args);
}
}
and here the route.
#Component
public class ZmqRoute extends RouteBuilder {
#Override
public void configure() throws Exception {
//from("stream:in").to("stream:out");
String host = "zmq.devnet.iota.org";
from("zeromq:tcp://" + host + ":5556?socketType=SUBSCRIBE&topics=tx")
.to("stream:out")
.log("${body}");
}
}
Lastly, here the build.gradle.kts
plugins {
java
application
id("org.springframework.boot") version "2.1.2.RELEASE"
id("io.spring.dependency-management") version "1.0.6.RELEASE"
}
repositories {
jcenter()
}
application {
mainClassName = "org.example.camel.Application"
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
tasks.withType<JavaCompile>().configureEach {
options.compilerArgs.addAll(arrayOf("-Xlint:all"))
options.encoding = "UTF-8"
}
dependencies {
val camelVersion = "3.0.0-M1"
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.apache.camel:camel-spring-boot-starter:$camelVersion")
implementation("org.apache.camel:camel-stream-starter:$camelVersion")
//implementation("org.apache.camel:camel-core:$camelVersion")
implementation("org.apache-extras.camel-extra:camel-zeromq:2.22.0") {
exclude(module = "zeromq-scala-binding_2.10")
}
implementation("org.zeromq:jeromq:0.5.0")
testImplementation("junit:junit:4.12")
}
So basically, after looking at Camel Core 3.0.0.M1, I discovered the .class file for
org.apache.camel.impl.DefaultComponent
doesn't exists anymore!
camel-core-3.0.0-M1.jar\org\apache\camel\impl
Honestly it seems like a bug to me, or incompatibility with core-zeromq.
The class has been moved to https://github.com/apache/camel/blob/master/core/camel-support/src/main/java/org/apache/camel/support/DefaultComponent.java
so on a different package. This was reported also on the migration guide
https://github.com/apache/camel/blob/master/MIGRATION.md#migrating-custom-components
Module Class
public class MorphiaModule extends AbstractModule {
#Override
protected void configure() {
bind(PlayMorphia.class).asEagerSingleton();
}
}
PlayMorphia
#Singleton
public class PlayMorphia {
MongoClient mongo = null;
Datastore datastore = null;
Morphia morphia = null;
#Inject
public PlayMorphia(ApplicationLifecycle lifecycle, Environment env, Configuration config) {
try {
configure(config, env.classLoader(), env.isTest()); // Method calling to get the config
} catch (Exception e) {
e.printStackTrace();
}
lifecycle.addStopHook(()->{
if (env.isTest()) {
mongo().close();
}
return CompletableFuture.completedFuture(null);
});
}
}
In My application.conf, I mentioned the correct package/path name for Module class i.e.
play.modules.enabled += "configuration.MorphiaModule"
I followed the Play framework official doc on Eager Binding: https://www.playframework.com/documentation/2.6.x/JavaDependencyInjection#Eager-bindings
At compile time, I am getting this:
CreationException: Unable to create injector, see the following errors:
1) No implementation for play.inject.ApplicationLifecycle was bound.
while locating play.inject.ApplicationLifecycle
for the 1st parameter of configuration.PlayMorphia. .
(PlayMorphia.java:28)
at configuration.MorphiaModule.configure(MorphiaModule.java:24) (via
modules: com.google.inject.util.Modules$OverrideModule ->
configuration.MorphiaModule)
What am I doing wrong here? Any help would be appreciable.
I'm using Spring-Data-Neo4j 4.0.0.M1, and trying to connect to the server. I'm getting an exception:
Caused by: org.apache.http.client.HttpResponseException: Unauthorized
I have a password on the server interface, but I'm not sure how to tell Spring about it.
#Configuration
#EnableNeo4jRepositories(basePackages = "com.noxgroup.nitro.persistence")
#EnableTransactionManagement
public class MyConfiguration extends Neo4jConfiguration {
#Bean
public Neo4jServer neo4jServer () {
/*** I was quite surprised not to see an overloaded parameter here ***/
return new RemoteServer("http://localhost:7474");
}
#Bean
public SessionFactory getSessionFactory() {
return new SessionFactory("org.my.software.domain");
}
#Bean
ApplicationListener<BeforeSaveEvent> beforeSaveEventApplicationListener() {
return new ApplicationListener<BeforeSaveEvent>() {
#Override
public void onApplicationEvent(BeforeSaveEvent event) {
if (event.getEntity() instanceof User) {
User user = (User) event.getEntity();
user.encodePassword();
}
}
};
}
}
Side Note
4.0.0 Milestone 1 is absolutely fantastic. If anyone is using 3.x.x, I'd recommend checking it out!
The username and password are passed currently via system properties
e.g.
-Drun.jvmArguments="-Dusername=<usr> -Dpassword=<pwd>"
or
System.setProperty("username", "neo4j");
System.setProperty("password", "password");
https://jira.spring.io/browse/DATAGRAPH-627 is open (not targeted for 4.0 RC1 though), please feel free to add comments/vote it up