Hello Francois
I tried with Basic Auth and I always get 403 Status and in Logs I see the following
2013-07-15 08:36:18,031 DEBUG [jeeves.config.springutil.GeonetworkFilterSecurity
Interceptor] - Secure object: FilterInvocation: URL: /srv/eng/j_spring_security_
check; Attributes: [denyAll]
2013-07-15 08:36:18,031 DEBUG [jeeves.config.springutil.GeonetworkFilterSecurity
Interceptor] - Previously Authenticated: org.springframework.security.authentica
tion.UsernamePasswordAuthenticationToken@anonymised.com: Principal: org.fao.geonet.ker
nel.security.GeonetworkUser@anonymised.com; Credentials: [PROTECTED]; Authenticated: tr
ue; Details: org.springframework.security.web.authentication.WebAuthenticationDe
tails@anonymised.com: RemoteIpAddress: 192.168.1.212; SessionId: null; Granted Authorities: R
egisteredUser, Guest, Editor, Reviewer, Monitor, Administrator, UserAdmin
I was thinking if it was with issue with war file and I downloaded the geonetwork.exe file and tested and got the same response.
Following is the code that I used
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.PostMethod;
public class TestGNLogin {
/**
* @param args
*/
public static void main(String args) {
// TODO Auto-generated method stub
try {
HttpClient httpClient = new HttpClient();
String url = "http://192.168.1.172:8080/geonetwork/srv/eng/j_spring_security_check";
PostMethod post = new PostMethod(url);
// post.addParameter("username", "admin");
//post.addParameter("password", "admin");
// Send login request**
//Credentials creds = new UsernamePasswordCredentials("admin", "admin");
//httpClient.getState().setCredentials(AuthScope.ANY, creds);
String user = "admin" + ":" + "admin";
byte encoding = Base64.encodeBase64(user.getBytes());
post.setRequestHeader(new Header("Authorization", "Basic " + new String(encoding)));
post.setDoAuthentication( true );
// httpClient.executeMethod(post);
// System.out.println("Status Code :"+post.getStatusCode());
int result = httpClient.executeMethod(post);
System.out.println("result of Login is : "+result);
String redirectLocation;
Header locationHeader = post.getResponseHeader("location");
System.out.println("locationHeader is : "+locationHeader);
if (locationHeader != null) {
redirectLocation = locationHeader.getValue();
System.out.println("redirectLocation is : "+redirectLocation);
post.setPath(redirectLocation);
result = httpClient.executeMethod(post);
}
if (result == HttpStatus.SC_OK) {
post.releaseConnection();
System.out.println("Login Successful");
} else {
post.releaseConnection();
System.out.println("Login Not Successful");
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
and the output I get is
result of Login is : 403
locationHeader is : null
Login Not Successful
Any Help is appreciated.
Regards
Kumaran
On 12-07-2013 19:15, Francois Prunayre wrote:
Hi, in 2.10, I would recommend using Basic Authentication. Talend
Spatial is using it, it works well
https://github.com/talend-spatial/talend-spatial/blob/master/org.talend.libraries.sdi/src/main/java/org/talend/sdi/metadata/Catalogue.java#L111
and much simpler than using the login service.
HTH.
Francois
2013/7/12 Kumaran Narayanaswamy <kumaran@anonymised.com>:
Hello
I am using the below Sample Code in Java to test login to Geonetwork
2.10 from an external application and I always get Login Not Successful
Message. Do I need to enable any other config for this to work. I have
also tried with the url
http://192.168.1.172:8081/geonetwork/srv/eng/j_spring_security_check and
it did not work
.Any help is appreciated. Thanks.
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.PostMethod;
public class TestGNLogin {
/**
* @param args
*/
public static void main(String args) {
// TODO Auto-generated method stub
try {
HttpClient httpClient = new HttpClient();
String url =
"http://192.168.1.172:8081/geonetwork/j_spring_security_check";
PostMethod post = new PostMethod(url);
post.addParameter("username", "admin");
post.addParameter("password", "admin");
// Send login request**
httpClient.executeMethod(post);
if(post.getStatusCode() == HttpStatus.SC_OK) {
post.releaseConnection();
System.out.println("Login Successful");
} else {
post.releaseConnection();
System.out.println("Login Not Successful");
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
Regards
Kumaran
------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
GeoNetwork-devel mailing list
GeoNetwork-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geonetwork-devel
GeoNetwork OpenSource is maintained at http://sourceforge.net/projects/geonetwork
------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
GeoNetwork-users mailing list
GeoNetwork-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geonetwork-users
GeoNetwork OpenSource is maintained at
http://sourceforge.net/projects/geonetwork