<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: UNAUTHENTICATED is not granted any of the required roles: eventAdministrator eventCreator catalogAdministrator</title>
	<atom:link href="http://www.albeesonline.com/blog/2008/11/09/unauthenticated-is-not-granted-any-of-the-required-roles-eventadministrator-eventcreator-catalogadministrator/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.albeesonline.com/blog/2008/11/09/unauthenticated-is-not-granted-any-of-the-required-roles-eventadministrator-eventcreator-catalogadministrator/</link>
	<description>Something about JEE and WebSphere. Java, JEE and WebSphere tips and tutorials</description>
	<lastBuildDate>Mon, 30 Jan 2012 13:08:13 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
	<item>
		<title>By: Niraj</title>
		<link>http://www.albeesonline.com/blog/2008/11/09/unauthenticated-is-not-granted-any-of-the-required-roles-eventadministrator-eventcreator-catalogadministrator/comment-page-1/#comment-82490</link>
		<dc:creator>Niraj</dc:creator>
		<pubDate>Tue, 28 Jun 2011 11:41:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.albeesonline.com/blog/?p=265#comment-82490</guid>
		<description>Mostly its not good way to change the existing application security role ,
best way is to authenticate the user and you can use authenticate the user using Jaas api.

Below is the code which does the authenticate and then call the secured resource api. Also i have used default CallbackHandler, you can use user callback if you to

javax.security.auth.login.LoginContext lc = null;

		try {
		  lc = new javax.security.auth.login.LoginContext(&quot;WSLogin&quot;,
		        new com.ibm.websphere.security.auth.callback.WSCallbackHandlerImpl
		        (&quot;usernam&quot;, &quot;password&quot;));

		  // create a LoginContext and specify a CallbackHandler implementation
		  // CallbackHandler implementation determine how authentication data is collected
		  // in this case, the authentication data is &quot;pushed&quot; to the authentication
		  // mechanism implemented by the LoginModule.
		} catch(javax.security.auth.login.LoginException e) {
		  System.err.println(&quot;ERROR: failed to instantiate a LoginContext &quot;
		                     + &quot;and the exception: &quot; + e.getMessage());
		  e.printStackTrace();

		  // may be javax.security.auth.AuthPermission &quot;createLoginContext&quot; is not granted
		  // to the application, or the JAAS login configuration is not defined.
		}

		if (lc != null) 
		{
		  try 
		  {
			  
		    lc.login();  // perform login

		    // get the authenticated subject
		    javax.security.auth.Subject s = lc.getSubject();

		    // Invoke a J2EE resources using the authenticated subject
		    com.ibm.websphere.security.auth.WSSubject.doAs(s, 
		                 new java.security.PrivilegedAction() 
		    	{
				      public Object run() {
				        try {
				          bankAccount.deposit(100.00);
				          // where bankAccount is an protected resource
				        } catch (Exception e) {
				          System.out.println(&quot;ERROR: error while accessing resource, exception: &quot; +
				                              e.getMessage());
				          e.printStackTrace();
				        }
				        return null;
				      }
		    	});
				      
		    
		  } catch (javax.security.auth.login.LoginException e) 
		    {
		    System.err.println(&quot;ERROR: login failed with exception: &quot; + e.getMessage());
		    e.printStackTrace();

		    // login failed, might want to provide relogin logic
		  }
		}

	}</description>
		<content:encoded><![CDATA[<p>Mostly its not good way to change the existing application security role ,<br />
best way is to authenticate the user and you can use authenticate the user using Jaas api.</p>
<p>Below is the code which does the authenticate and then call the secured resource api. Also i have used default CallbackHandler, you can use user callback if you to</p>
<p>javax.security.auth.login.LoginContext lc = null;</p>
<p>		try {<br />
		  lc = new javax.security.auth.login.LoginContext(&#8220;WSLogin&#8221;,<br />
		        new com.ibm.websphere.security.auth.callback.WSCallbackHandlerImpl<br />
		        (&#8220;usernam&#8221;, &#8220;password&#8221;));</p>
<p>		  // create a LoginContext and specify a CallbackHandler implementation<br />
		  // CallbackHandler implementation determine how authentication data is collected<br />
		  // in this case, the authentication data is &#8220;pushed&#8221; to the authentication<br />
		  // mechanism implemented by the LoginModule.<br />
		} catch(javax.security.auth.login.LoginException e) {<br />
		  System.err.println(&#8220;ERROR: failed to instantiate a LoginContext &#8221;<br />
		                     + &#8220;and the exception: &#8221; + e.getMessage());<br />
		  e.printStackTrace();</p>
<p>		  // may be javax.security.auth.AuthPermission &#8220;createLoginContext&#8221; is not granted<br />
		  // to the application, or the JAAS login configuration is not defined.<br />
		}</p>
<p>		if (lc != null)<br />
		{<br />
		  try<br />
		  {</p>
<p>		    lc.login();  // perform login</p>
<p>		    // get the authenticated subject<br />
		    javax.security.auth.Subject s = lc.getSubject();</p>
<p>		    // Invoke a J2EE resources using the authenticated subject<br />
		    com.ibm.websphere.security.auth.WSSubject.doAs(s,<br />
		                 new java.security.PrivilegedAction()<br />
		    	{<br />
				      public Object run() {<br />
				        try {<br />
				          bankAccount.deposit(100.00);<br />
				          // where bankAccount is an protected resource<br />
				        } catch (Exception e) {<br />
				          System.out.println(&#8220;ERROR: error while accessing resource, exception: &#8221; +<br />
				                              e.getMessage());<br />
				          e.printStackTrace();<br />
				        }<br />
				        return null;<br />
				      }<br />
		    	});</p>
<p>		  } catch (javax.security.auth.login.LoginException e)<br />
		    {<br />
		    System.err.println(&#8220;ERROR: login failed with exception: &#8221; + e.getMessage());<br />
		    e.printStackTrace();</p>
<p>		    // login failed, might want to provide relogin logic<br />
		  }<br />
		}</p>
<p>	}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Miguel</title>
		<link>http://www.albeesonline.com/blog/2008/11/09/unauthenticated-is-not-granted-any-of-the-required-roles-eventadministrator-eventcreator-catalogadministrator/comment-page-1/#comment-30834</link>
		<dc:creator>Miguel</dc:creator>
		<pubDate>Tue, 24 Feb 2009 09:49:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.albeesonline.com/blog/?p=265#comment-30834</guid>
		<description>Excellent post! This saved me a lot of time  :mrgreen: 

Thank you!</description>
		<content:encoded><![CDATA[<p>Excellent post! This saved me a lot of time  <img src='http://www.albeesonline.com/blog/wp-includes/images/smilies/icon_mrgreen.gif' alt=':mrgreen:' class='wp-smiley' />  </p>
<p>Thank you!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

