WSO2 Self Registration Confirmation Email - wso2

I have a client using the UserInformationRecoveryServiceStub to register new users. This works until I configure WSO2 IS to send a confirmation email.
in identity-mgt.properties I set:
Identity.Listener.Enable=true
Notification.Sending.Internally.Managed=true
Authentication.Policy.Account.Lock.On.Creation=true
Notification.Expire.Time=7200
Notification.Sending.Enable=true
Authentication.Policy.Enable=true
Now when the client call UserInformationRecoveryServiceStub.registerUser(), the user is added to the user store but no email is sent and the client receives the following exception:
SEVERE: null
org.wso2.carbon.identity.mgt.stub.UserInformationRecoveryServiceIdentityMgtServiceExceptionE(uxception: UserInformationRecoveryServiceIdentityMgtServiceExceptionException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at java.lang.Class.newInstance(Class.java:433)
at org.wso2.carbon.identity.mgt.stub.UserInformationRecoveryServiceStub.registerUser(UserInformationRecoveryServiceStub.java:685)
at com.ijet.wso2is.client.UserInformationRecoveryServiceClient.registerBjnUser(UserInformationRecoveryServiceClient.java:191)
at com.ijet.wso2is.client.UserInformationRecoveryServiceClient.main(UserInformationRecoveryServiceClient.java:69)
The following is the client code of interest.
UserIdentityClaimDTO claim = new UserIdentityClaimDTO();
claim.setClaimUri("http://wso2.org/claims/emailaddress");
claim.setClaimValue("testee#xyz.com");
claimList.add(claim);
claim = new UserIdentityClaimDTO();
claim.setClaimUri("http://wso2.org/claims/givenname");
claim.setClaimValue("Testee");
claimList.add(claim);
claim = new UserIdentityClaimDTO();
claim.setClaimUri("http://wso2.org/claims/lastname");
claim.setClaimValue("Tester");
claimList.add(claim);
serviceStub.registerUser(TEST_USERNAME,
"Password#1",
claimList.toArray(new UserIdentityClaimDTO[claimList.size()]),
null,
null);

Are you working on IS 5.0.0? I went through the code and it seems that the sending of emails is commented out. Simply commenting it in didn't work.
But it worked for me, if you register the user without specifying a password. In that use case the server runs through a different part of code which really sends out emails.

Related

How to change the email that SES sends from?

Right now I have a few domains verified in AWS. I just started using SES with SMTP to send some emails from contact forms/password resets on my site but have run into a bit of an issue.
I have the domain example.com verified and am wanting to send emails from no-reply#example.com but whenever I send them it sends from my work email me#example.com
What can I do to get this setup? I posted on Reddit and was told that I can setup CloudFormation in order to do it but that seems way over complicated for what I'm trying to do. I just want to change the email that it's sent from on a verified domain, I would assume that's pretty simple.
Any help would be great, thanks!
I used SES with the SMTP interface (from a .net application), and because my domains are verified, all I need to do is change the 'FROM' address, and it will send from whichever email address I want.
Here is a code example:
using (var msg = new MailMessage())
{
msg.From = new MailAddress("anything#my-verified-domain.com");
msg.To.Add(s.EmailAddress);
msg.Subject = "Test Subject";
msg.Body = body;
msg.IsBodyHtml = true;
msg.Headers.Add("X-SES-CONFIGURATION-SET", "configset-1");
using (var smtp = new SmtpClient())
{
smtp.Send(msg);
}
}
Maybe if you shared some code we could see where you are going wrong.

SocketTimeoutException after connecting via proxy with authentication

I wrote code to communicate with a non-public webservice and everything seemed to work even when connecting via proxy. The problem started after changing to proxy with authorization. I get the following warning:
WARN [HttpMethodDirector] Required credentials not available for BASIC <any realm>#destination.url.com:80
WARN [HttpMethodDirector] Preemptive authentication requested but no default credentials available
After which an exception is thrown: java.net.SocketTimeoutException: Read timed out
"destination.url.com" is the destination address, so I guess I went past the proxy.
I read somewhere on stackoverflow that this warning is usually thrown when passing in a username/password when don't need to. I don't know if it's true. Using HttpProxy to connect to a host with preemtive authentication
Also here some guys point the same problem, but reproducible by running through a non-authenticated proxy to an authenticated remote repository. My situation is the opposite. The destination doesn't require authorization (the authorization data are put into the body of SOAP messages).
https://www.jfrog.com/jira/browse/RTFACT-4147
Any ideas how to help my situation? Here is some of my code:
MyStub stub = new MyStub();
Options Options = stub._getServiceClient().getOptions();
Options.setProperty(org.apache.axis2.Constants.Configuration.CHARACTER_SET_ENCODING,"utf-8");
Options.setProperty(org.apache.axis2.Constants.Configuration.ENABLE_SWA,org.apache.axis2.Constants.VALUE_FALSE);
HttpTransportProperties.ProxyProperties proxyProperties = new HttpTransportProperties.ProxyProperties();
proxyProperties.setProxyName("proxyAddress");
proxyProperties.setProxyPort("proxyPort");
proxyProperties.setUserName("proxyUsername");
proxyProperties.setPassWord("proxyPassword");
Options.setProperty(org.apache.axis2.transport.http.HTTPConstants.PROXY,proxyProperties);
It happens that the warning has nothing to do with the exception. Exception is thrown because the webservice doesn't support chunked messages. Simply adding this solves the problem:
options.setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED, Boolean.FALSE);
The warning itself is strange, but there is a way to remove it, by simply adding any login and password. The destination doesn't require any, but the warning vanishes.

RESTEasy Client Proxy Preemptive Basic Authentication

I am using RESTEasy Proxy Framework to call my Rest-Services. I would like to use preemptive authentication with the proxy framework.
Thats my current Code:
public void callSomeService() throws Exception {
RegisterBuiltin.register(ResteasyProviderFactory.getInstance());
DefaultHttpClient client = new DefaultHttpClient();
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(
USERNAME, PASSWORD);
AuthScope authscope = new AuthScope(AuthScope.ANY_HOST,
AuthScope.ANY_PORT, AuthScope.ANY_REALM);
client.getCredentialsProvider().setCredentials(authscope, credentials);
ApacheHttpClient4Executor executer = new ApacheHttpClient4Executor(client);
dummyResource = ProxyFactory.create(DummyResource.class,
"http://localhost:8888/myapp/rest/", executer);
// Do some calls here
}
When I monitor the traffic of my application, the Rest-Service gets called twice:
First the client receives an 401 Error (UNAUTHORIZED)
In the second request there is the Authorization Header added and everything works
fine.
What I actually want to do is that the Authorization Header is already added in the first request! How can I do that?
I am using RESTEasy 2.3.5! I also read the documentation (http://docs.jboss.org/resteasy/docs/2.3.5.Final/userguide/html_single/index.html#transport_layer) where is an example given for preemptive authentication, which actually doesnt work, because of this code:
BasicScheme basicAuth = new BasicScheme();
authCache.put("com.bluemonkeydiamond.sippycups", basicAuth);
You're right, the example in the documentation does not compile. Try replacing the string "com.bluemonkeydiamond.sippycups" with an instance of HttpHost. The HttpHost class has several constructors so be sure to look at the JavaDocs. The simplest constructor takes a string. For example,
BasicScheme basicAuth = new BasicScheme();
authCache.put(new HttpHost("com.bluemonkeydiamond.sippycups"), basicAuth);

Stub generated using Axis2 Webservice forming new connection for redirect URL...Need same TCP connection...!

I am badly stuck with a SOAP based integration using Axis2 framework for generation of client stubs from the Server WSDL. The scenario is as follows :
There is always a login API call first, which gives a Success response in SOAP body and Temporary Redirect in HTTP header. Also provides a URL which contains the session ID in the Location field of HTTP Header.
The next API call is required to be made at this redirect location. IN THE SAME TCP CONNECTION, for getting a proper response.
Now, the problem is, as a part of Webservice implementation using Axis2 generated stubs, I need to reload this redirect URL and re-instantiate it as --- "stub=new Stub(newurl)"
As soon as this is done, it creates a new TCP connection and so, the next request gives the response as "session ID invalid" because it goes out-of-sync with login API.
I have tried everything mentioned as a solution in this forum and nothing is working out.
For e.g --
MultiThreadedHttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager();
HttpClient httpClient = new HttpClient(httpConnectionManager);
ServiceClient serviceClient = stub._getServiceClient();
Options opts = stub._getServiceClient().getOptions();
opts.setTo(new EndpointReference(prop.getProperty("target_end_point_url")));
opts.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Constants.VALUE_TRUE);
opts.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);
serviceClient.setOptions(opts);
stub._setServiceClient(serviceClient);
Similarly, I have tried many other options too. But it's not helpful at all.
Faced exactly the same issue.
Following steps solved the issue.
1. Using HttpClient, perform login. Don't use stub object to perform login.
2. Use the Location Header URL, to create new stub object i.e. stub = new Stub(locationURL). (Your existing options setting should be retained.)
3. There is a default timeout, by which server disconnects the TCP connection. In my case it was 50 seconds. Hence as soon as i performed login in step 1, i execute a timer every 40 seconds, to send an empty requests to new Location URL using HeadMethod of same HttpClient object.

Django Email backend (keeps sending email from incorrect "sender")

I have several instances in my project where I attempt to send an email within a Django view.
I want to be able to hardcode the email sender within the view. When I try to do so, though, it continues to send the emails from the default account specified in my settings file.
Here is an example:
if testform.is_valid():
beta=testform.save()
subject="Hi Beta Tester"
sender="correct#email.com"
recipient=[testform.cleaned_data['email']]
text=loader.get_template('registration/beta_email.txt')
html=loader.get_template('registration/beta_email.html')
site_name='mysite'
d=Context({'site_name':site_name})
text_content=text.render(d)
html_content=html.render(d)
#This sends two mail versions, plain text and html
msg=EmailMultiAlternatives(subject, text_content, sender, recipient)
msg.attach_alternative(html_content, "text/html")
msg.send()
return HttpResponseRedirect('/splash/')
I thought that I could send specify the sender argument explicitly here. And, yet, when I test it, the email is being sent from the address listed in my settings file, configured as the following:
EMAIL_USE_TLS=True
EMAIL_HOST='smtp.gmail.com'
EMAIL_HOST_USER='wrong#email.com'
EMAIL_HOST_PASSWORD='private'
DEFAULT_FROM_EMAIL='wrong#email.com'
Do I just have to remove the DEFAULT_FROM_EMAIL constant to make it work? I tried doing so and it seems to be working but I'm confused. In the Django documentation, it suggests that setting sender in the view should override the DEFAULT.
I've finally figured out the issue here. Unfortunately, gmail rewrites the from and the
envelope on authenticated smtp.
If you want to get around that, you have to use a third party mail server (which doesn't act like such a prissy) and then send mail to gmail users.
For the sender e-mail try putting it in < > and you can add a name:
sender = "Formal Name <correct#email.com>"
that is exactly the syntax I have in my e-mail sending view and it works.
There really shouldn't be a reason that adding the name to it would change how it's sending, but it may be worth trying and perhaps you want an easily readable name anyway.