• Post Reply Bookmark Topic Watch Topic
  • New Topic

Get Role of username, passed in a SOAP header, in ejbcontext ?

 
Shabd Sandeep
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using ServiceImplementation as a Session Bean, exposing bean as a service.
My current requirement needs that.
How can I get user roles, stored in myrealm, in weblogic, for the user passed in SOAP header ?

System.out.println(ctx.getCallerPrincipal().getName()); <----- should show the username in SOAP header
if(ctx.isCallerInRole("Monitors")) <---- the user's role in weblogic?

Here is the implementation class. How can it be done with and without authentication ?
Thank You for the help !

----------------------------------------
Impl. java

@WebService(
serviceName="SecurityService",
targetNamespace="http://www.bea.com/wls103",
endpointInterface="com.onstar.vcs.webservices.SecurePort")
@WLHttpTransport(contextPath="role",serviceUri="SecurityService",portName="SecurePort")
public class SecurePortImpl implements SecurePort,SessionBean {

/**
*
*/
private static final long serialVersionUID = 1L;
SessionContext ctx = null;
public SecurePortImpl() {

}
public void ejbCreate() throws CreateException {

}
public java.lang.String getRole(java.lang.String name)

{
System.out.println("***************start************");
System.out.println(ctx.getCallerPrincipal().getName());
if(ctx.isCallerInRole("Monitors"))
{
System.out.println("****************Monitors*************");
return "Monitors";
}
else if(ctx.isCallerInRole("Operators"))
{
System.out.println("****************Operators*************");
return "Operators";
}

else
{
System.out.println("****************not found*************");
return "not found";
}

/* System.out.println("****************Monitors*************");
// TODO replace with your impl here
return ctx.getCallerPrincipal().getName(); */
}

public void ejbActivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub

}

public void ejbPassivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub

}

public void ejbRemove() throws EJBException, RemoteException {
// TODO Auto-generated method stub

}

public void setSessionContext(SessionContext arg0) throws EJBException,
RemoteException {
ctx=arg0;
// TODO Auto-generated method stub

}
}

-------------------------

SOAP message -
The manager has role of "Monitor" in weblogic security realm.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wls="http://www.bea.com/wls103">
<soapenv:Header>

<ServiceAuthHeader>
<Username>manager</Username>

</ServiceAuthHeader>
</soapenv:Header>

<soapenv:Body>
<wls:roleName>test</wls:roleName>
</soapenv:Body>
</soapenv:Envelope>

-------------------

Console output
***************start************
<anonymous>
****************not found*************
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!