store authentication :
Code:
public Subject authenticate(Object credentials) {
try{
Authentication authentication = authMgr.authenticate(getAuthentication(credentials));
registry.register(authentication.getName(), authentication);
return getSubject(authentication);
}catch(AuthenticationException e){
logger.warn(e);
throw new SecurityException(e);
}
}
set a delegatingmbean or use aop :
Code:
<aop:config>
<aop:pointcut id="jmx-pointcut" expression="execution(public * javax.management.MBeanServer.invoke(..))" />
<aop:aspect ref="jmx-security-handler">
<aop:around pointcut-ref="jmx-pointcut" method="invoke"/>
</aop:aspect>
</aop:config>
lookup authentication info :
Code:
public Object invoke(ProceedingJoinPoint pjp) throws Throwable{
try{
SecurityContextHolder.getContext().setAuthentication(lookup());
return pjp.proceed();
}finally{
SecurityContextHolder.clearContext();
if (logger.isDebugEnabled()) {
logger.debug("Cleared SecurityContextHolder.");
}
}
}
private Authentication lookup(){
try{
return registry.get(lookup(Subject.getSubject(AccessController.getContext())));
}catch(Exception e){
logger.warn(e.getMessage());
}
return null;
}
private String lookup(Subject subject){
return subject.getPrincipals(JMXPrincipal.class).iterator().next().getName();
}