SecurityMetadata securityMetadata = SecurityActions.getSecurityMetadata(sm, isQueue, name);
if (securityMetadata == null)
{
throw new JMSSecurityException("No security configuration avaliable for " + name);
}
// Authenticate. Need to save current SecurityContext
SecurityContext previousSCtx = SecurityActions.getSecurityContext();
final String username = conn.getUsername();
final String password = conn.getPassword();
SecurityActions.authenticate(sm, username, password);
// Authorize
final Set principals = checkType == CheckType.READ ? securityMetadata.getReadPrincipals() :
checkType == CheckType.WRITE ? securityMetadata.getWritePrincipals() :
securityMetadata.getCreatePrincipals();
try
{
final CheckType tmpCheckType = checkType;
if (!SecurityActions.authorize(sm, conn.getUsername(), principals, checkType))
{
String msg = "User: " + conn.getUsername() +
" is not authorized to " +
(checkType == CheckType.READ ? "read from" :
checkType == CheckType.WRITE ? "write to" : "create durable sub on") +
" destination " + name;
throw new JMSSecurityException(msg);
}
}
finally
{
// Restore previous SecurityContext