[prev in list] [next in list] [prev in thread] [next in thread] 

List:       wsf-c-dev
Subject:    Re: [Dev] Identity Server - Problems implementing a custom JDBC user store
From:       Thomas LEGRAND <thomas.legrand () versusmind ! eu>
Date:       2017-07-28 7:04:37
Message-ID: CAJN4piT0GYfSmBFBzpQ6uKgjYwZm=YBEBsGWhaCnO7DRD5LJtw () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hello Nuwandi,

Thank you for your answer. Actually, I found the current implementation
from the org.wso2.carbon.identity.user.store.count_5.7.5.jar located in
<WSO2EI_HOME>/repository/components/plugins from where I found which
dependency to add to my POM and tried to implement one myself but that did
not work. I think some of the OSGi notion are missing on my side, because
even if I register my "UserSotreCountRetriever", that does not work. The
code I wrote was something like:

    protected void activate(ComponentContext ctxt) {
>         BundleContext bundleContext = ctxt.getBundleContext();
>
>         MyUserStoreManager userStoreManager = new MyUserStoreManager();
>         bundleContext.registerService(UserStoreManager.class.getName(),
> userStoreManager, null);
>
> bundleContext.registerService(UserStoreCountRetriever.class.getName(),
> userStoreManager, null);
>     }
>

Of course, MyUserStoreManager implemented the UserStoreCountRetriever
interface

So, I concluded by just removing the custom "UserStoreCountRetriever" class
property and I can retrieve my usernames without any error message
concerning the counting;

However, if you have a tutorial or a documentation to implement custom
things like that for realzies, that would be cool :)

Regards,

Thomas

2017-07-28 4:17 GMT+02:00 Nuwandi Wickramasinghe <nuwandiw@wso2.com>:

> Hi Thomas,
>
> User counter is different from "UserStoreManager". Therefore you cannot
> give your custom User store manager class as CountRetrieverClass. [1] is
> the class used for this by default. You should be able to customize the
> count implementation by writing a new count retriever extending
> *AbstractUserStoreCountRetriever *and then providing that class as the
> "UserStoreCountRetriever". In your custom count retriever class override
> "countUsers" method and change the implementation as you wish.
>
> regards
> Nuwandi
>
> On Thu, Jul 27, 2017 at 6:59 PM, Thomas LEGRAND <
> thomas.legrand@versusmind.eu> wrote:
>
>> Hello,
>>
>> For the second problem, I know from where this came from. It is just my
>> String[] contained a null value which triggered a NPE during the
>> verification of the presence of a '|' in the name like it is written at
>> line 180 of this source code [1].
>>
>> However, the other problem remains concerning the UserStoreCountService
>> because I always have:
>>
>> [2017-07-27 15:26:20,293] ERROR {org.wso2.carbon.identity.user
>>> .store.count.UserStoreCountService} -  Error while getting user count
>>> from user store domain : myUserStore
>>> org.wso2.carbon.identity.user.store.count.exception.UserStoreCounterException:
>>> ORA-00942: Table ou vue inexistante
>>>
>>
>> Regards,
>>
>> Thomas
>>
>> [1] https://github.com/wso2-attic/carbon-identity/blob/master/co
>> mponents/user-mgt/org.wso2.carbon.user.mgt/src/main/java/org
>> /wso2/carbon/user/mgt/UserRealmProxy.java#L180
>>
>>
>> 2017-07-27 11:14 GMT+02:00 Thomas LEGRAND <thomas.legrand@versusmind.eu>:
>>
>>> Hello,
>>>
>>> I am trying to create a custom JDBC user store by extending the
>>> org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager. For the moment, I
>>> just implemented the doListUsers method to display them in the IS. But I
>>> can't even list my users because I have two problems:
>>>
>>> - The first one concerns the method to count the retrieved users. I
>>> noticed the default used class is org.wso2.carbon.identity.us
>>> er.store.count.jdbc.JDBCUserStoreCountRetriever but it seems to use the
>>> SQL request defined in the properties to execute the count. So I configured
>>> my user-store configuration file to use my custom JDBCUserStoreManager as
>>> "UserStoreCountRetriever". But now, the error appearing is it want to
>>> execute the "countUsers" method that I can't even see in the source code in
>>> [1]. Which interface/class should I implement/extend to allow my custom
>>> JDBCUserStoreManager to use itself as "UserStoreCountRetriever". I ask that
>>> because I have not found the source code of this class :(
>>> - The second one is the content of the list of users itself. So the call
>>> of the doListUsers. My SQL request is executed but I have a problem because
>>> a stacktrace appears tellming me that a NPE occured in the class
>>> UserRealmProxy and I don't know what to do:
>>>
>>> [2017-07-27 11:03:45,555] ERROR {org.wso2.carbon.user.mgt.UserRealmProxy}
>>>> -
>>>> java.lang.NullPointerException
>>>>         at org.wso2.carbon.user.mgt.UserRealmProxy.listAllUsers(UserRea
>>>> lmProxy.java:180)
>>>>         at org.wso2.carbon.user.mgt.UserAdmin.listAllUsers(UserAdmin.ja
>>>> va:82)
>>>>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>>         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce
>>>> ssorImpl.java:62)
>>>>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe
>>>> thodAccessorImpl.java:43)
>>>>         at java.lang.reflect.Method.invoke(Method.java:498)
>>>>         ...
>>>
>>>
>>> In addition, I followed the documentation [1] but it is not complete
>>> because the part to register the OSGi bundle is missing. So I followed the
>>> end of the tuto [2] to do so (the part "Register Custom User Store Manager
>>> in OSGI framework"). And if I can make a comment, most of the tuto does not
>>> display which packages to use which is very wrong (hopefully, there was a
>>> sample :)) because there is a big difference between importing
>>> org.wso2.carbon.user.api.UserStoreManager and importing
>>> org.wso2.carbon.user.core.UserStoreManager. There is no way to know
>>> which one to use.
>>>
>>> Can you help me, please?
>>>
>>> Regards,
>>>
>>> Thomas
>>>
>>> [1] https://docs.wso2.com/display/IS530/Writing+a+Custom+Use
>>> r+Store+Manager#WritingaCustomUserStoreManager-Deployingandc
>>> onfiguringthecustomuserstoremanager
>>> [2] http://pushpalankajaya.blogspot.fr/2013/09/how-to-write-
>>> custom-user-store-manager.html
>>>
>>
>>
>> _______________________________________________
>> Dev mailing list
>> Dev@wso2.org
>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>
>>
>
>
> --
>
> Best Regards,
>
> Nuwandi Wickramasinghe
>
> Software Engineer
>
> WSO2 Inc.
>
> Web : http://wso2.com
>
> Mobile : 0719214873
>

[Attachment #5 (text/html)]

<div dir="ltr"><div><div><div><div><div>Hello Nuwandi,<br><br></div>Thank you for \
your answer. Actually, I found the current implementation from the \
org.wso2.carbon.identity.user.store.count_5.7.5.jar located in \
&lt;WSO2EI_HOME&gt;/repository/components/plugins from where I found which dependency \
to add to my POM and tried to implement one myself but that did not work. I think \
some of the OSGi notion are missing on my side, because even if I register my \
&quot;UserSotreCountRetriever&quot;, that does not work. The code I wrote was \
something like:<br><br><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">       protected void \
activate(ComponentContext ctxt) {<br>              BundleContext bundleContext = \
ctxt.getBundleContext();<br><br>              MyUserStoreManager userStoreManager = \
new MyUserStoreManager();<br>              \
bundleContext.registerService(UserStoreManager.class.getName(), userStoreManager, \
null);<br>              \
bundleContext.registerService(UserStoreCountRetriever.class.getName(), \
userStoreManager, null);<br>       }<br></blockquote><br></div><div>Of course, \
MyUserStoreManager  implemented the UserStoreCountRetriever \
interface<br></div><div><br></div>So, I concluded by just removing the custom \
&quot;UserStoreCountRetriever&quot; class property and I can retrieve my usernames \
without any error message concerning the counting;<br><br></div>However, if you have \
a tutorial or a documentation to implement custom things like that for realzies, that \
would be cool :)<br><br></div>Regards,<br><br></div>Thomas<br></div><div \
class="gmail_extra"><br><div class="gmail_quote">2017-07-28 4:17 GMT+02:00 Nuwandi \
Wickramasinghe <span dir="ltr">&lt;<a href="mailto:nuwandiw@wso2.com" \
target="_blank">nuwandiw@wso2.com</a>&gt;</span>:<br><blockquote class="gmail_quote" \
style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div \
dir="ltr">Hi Thomas,<div><br>User counter is different from \
&quot;UserStoreManager&quot;. Therefore you cannot give your custom User store \
manager class as CountRetrieverClass. [1] is the class used for this by default. You \
should be able to customize the count implementation by writing a new count retriever \
extending <i>AbstractUserStoreCountRetrieve<wbr>r  </i>and then providing that class \
as the &quot;UserStoreCountRetriever&quot;.  In your custom count retriever class \
override &quot;countUsers&quot; method and change the implementation as you \
wish.</div><div><br></div><div>regards</div><div>Nuwandi</div></div><div \
class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Thu, Jul 27, \
2017 at 6:59 PM, Thomas LEGRAND <span dir="ltr">&lt;<a \
href="mailto:thomas.legrand@versusmind.eu" \
target="_blank">thomas.legrand@versusmind.eu</a>&gt;</span> \
wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 \
.8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div \
dir="ltr"><div><div><div><div>Hello,<br><br></div>For the second problem, I know from \
where this came from. It is just my String[] contained a null value which triggered a \
NPE during the verification of the presence of a &#39;|&#39; in the name like it is \
written at line 180 of this source code [1].<br><br></div>However, the other problem \
remains concerning the UserStoreCountService because I always \
have:<br><br><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">[2017-07-27 \
15:26:20,293] ERROR {org.wso2.carbon.identity.user<wbr>.store.count.UserStoreCountSer<wbr>vice} \
-   Error while getting user count from user store domain : \
myUserStore<br>org.wso2.carbon.identity.user.<wbr>store.count.exception.UserStor<wbr>eCounterException: \
ORA-00942: Table ou vue \
inexistante<br></blockquote><br></div>Regards,<br><br></div>Thomas<br><br>[1] <a \
href="https://github.com/wso2-attic/carbon-identity/blob/master/components/user-mgt/or \
g.wso2.carbon.user.mgt/src/main/java/org/wso2/carbon/user/mgt/UserRealmProxy.java#L180" \
target="_blank">https://github.com/wso2-attic/<wbr>carbon-identity/blob/master/co<wbr> \
mponents/user-mgt/org.wso2.car<wbr>bon.user.mgt/src/main/java/org<wbr>/wso2/carbon/user/mgt/UserReal<wbr>mProxy.java#L180</a><br><div><div><br></div></div></div><div \
class="m_2606688694174287028HOEnZb"><div class="m_2606688694174287028h5"><div \
class="gmail_extra"><br><div class="gmail_quote">2017-07-27 11:14 GMT+02:00 Thomas \
LEGRAND <span dir="ltr">&lt;<a href="mailto:thomas.legrand@versusmind.eu" \
target="_blank">thomas.legrand@versusmind.eu</a>&gt;</span><wbr>:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div dir="ltr">Hello,<div><br></div><div>I am trying to \
create a custom JDBC user store by extending the \
org.wso2.carbon.user.core.jdbc<wbr>.JDBCUserStoreManager. For the moment, I just \
implemented the doListUsers method to display them in the IS. But I can&#39;t even \
list my users because I have two problems:</div><div><br></div><div>- The first one \
concerns the method to count the retrieved users. I noticed the default used class is \
<a href="http://org.wso2.carbon.identity.us" \
target="_blank">org.wso2.carbon.identity.us</a><wbr>er.store.count.jdbc.JDBCUserSt<wbr>oreCountRetriever \
but it seems to use the SQL request defined in the properties to execute the count. \
So I configured my user-store configuration file to use my custom \
JDBCUserStoreManager as &quot;UserStoreCountRetriever&quot;. But now, the error \
appearing is it want to execute the &quot;countUsers&quot; method that I can&#39;t \
even see in the source code in [1]. Which interface/class should I implement/extend \
to allow my custom JDBCUserStoreManager to use itself as \
&quot;UserStoreCountRetriever&quot;. I ask that because I have not found the source \
code of this class :(</div><div>- The second one is the content of the list of users \
itself. So the call of the doListUsers. My SQL request is executed but I have a \
problem because a stacktrace appears tellming me that a NPE occured in the class \
UserRealmProxy and I don&#39;t know what to do:</div><div><br></div><div><blockquote \
class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid \
rgb(204,204,204);padding-left:1ex">[2017-07-27 11:03:45,555] ERROR \
{org.wso2.carbon.user.mgt.User<wbr>RealmProxy} \
-<br>java.lang.NullPointerException<br>            at \
org.wso2.carbon.user.mgt.UserR<wbr>ealmProxy.listAllUsers(UserRea<wbr>lmProxy.java:180)<br> \
at org.wso2.carbon.user.mgt.UserA<wbr>dmin.listAllUsers(UserAdmin.ja<wbr>va:82)<br>   \
at sun.reflect.NativeMethodAccess<wbr>orImpl.invoke0(Native Method)<br>            at \
sun.reflect.NativeMethodAccess<wbr>orImpl.invoke(NativeMethodAcce<wbr>ssorImpl.java:62)<br> \
at sun.reflect.DelegatingMethodAc<wbr>cessorImpl.invoke(DelegatingMe<wbr>thodAccessorImpl.java:43)<br> \
at java.lang.reflect.Method.invok<wbr>e(Method.java:498)<br>            \
...</blockquote></div><div><br></div><div>In addition, I followed the documentation \
[1] but it is not complete because the part to register the OSGi bundle is missing. \
So I followed the end of the tuto [2] to do so (the part &quot;Register Custom User \
Store Manager in OSGI framework&quot;). And if I can make a comment, most of the tuto \
does not display which packages to use which is very wrong (hopefully, there was a \
sample :)) because there is a big difference between importing \
org.wso2.carbon.user.api.UserS<wbr>toreManager and importing \
org.wso2.carbon.user.core.User<wbr>StoreManager. There is no way to know which one to \
use.</div><div><br></div><div>Can you help me, \
please?</div><div><br></div><div>Regards,</div><div><br></div><div>Thomas</div><div><br></div><div>[1] \
<a href="https://docs.wso2.com/display/IS530/Writing+a+Custom+User+Store+Manager#WritingaCustomUserStoreManager-Deployingandconfiguringthecustomuserstoremanager" \
target="_blank">https://docs.wso2.com/disp<wbr>lay/IS530/Writing+a+Custom+Use<wbr>r+St \
ore+Manager#WritingaCustom<wbr>UserStoreManager-Deployingandc<wbr>onfiguringthecustomuserstorema<wbr>nager</a><br></div><div>[2] \
<a href="http://pushpalankajaya.blogspot.fr/2013/09/how-to-write-custom-user-store-manager.html" \
target="_blank">http://pushpalankajaya.blo<wbr>gspot.fr/2013/09/how-to-write-<wbr>custom-user-store-manager.html</a></div></div>
 </blockquote></div><br></div>
</div></div><br></div></div>______________________________<wbr>_________________<br>
Dev mailing list<br>
<a href="mailto:Dev@wso2.org" target="_blank">Dev@wso2.org</a><br>
<a href="http://wso2.org/cgi-bin/mailman/listinfo/dev" rel="noreferrer" \
target="_blank">http://wso2.org/cgi-bin/mailma<wbr>n/listinfo/dev</a><br> \
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div \
class="m_2606688694174287028gmail_signature" data-smartmail="gmail_signature"><div \
dir="ltr">


	
	
	
	<p style="margin-bottom:0in;line-height:100%"><span \
style="font-family:verdana,sans-serif">Best Regards,</span></p><span \
style="font-family:verdana,sans-serif"> </span><p \
style="margin-bottom:0in;line-height:100%"><span \
style="font-family:verdana,sans-serif">Nuwandi Wickramasinghe</span></p><span \
style="font-family:verdana,sans-serif"> </span><p \
style="margin-bottom:0in;line-height:100%"><span \
style="font-family:verdana,sans-serif">Software Engineer</span></p><span \
style="font-family:verdana,sans-serif"> </span><p \
style="margin-bottom:0in;line-height:100%"><span \
style="font-family:verdana,sans-serif">WSO2 Inc.</span></p><span \
style="font-family:verdana,sans-serif"> </span><p \
style="margin-bottom:0in;line-height:100%"><span \
style="font-family:verdana,sans-serif">Web : <a href="http://wso2.com/" \
target="_blank">http://wso2.com</a></span></p><span \
style="font-family:verdana,sans-serif"> </span><p \
style="margin-bottom:0in;line-height:100%"><span \
style="font-family:verdana,sans-serif">Mobile : 0719214873</span></p>

</div></div>
</div>
</blockquote></div><br></div>



_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic