jsmile
Life is good
发贴: 127
积分: 52
|
于 2003-08-29 22:30
Assume you already know how LoginModule, CallbackHandler and Permission works (Authentication). Here's the different code of two authorization types: Declarative authorization: class SomelAction implements PrivilegedAction { public Object run() { AccessController.checkPermission(new SomeDefinedPermission("xxx")); // Perform tasks return new Integer(0); } }
Programmatic authorization: class SomeAction implements PrivilegedAction { public Object run() { AccessControlContext context = AccessController.getContext(); Subject subject = Subject.getSubject( context );
Set principals = subject.getPrincipals(); Iterator iterator = principals.iterator(); while (iterator.hasNext()) { MyPrincipal principal = (MyPrincipal)iterator.next(); if (principal.getName().equals( "Some Pre-Defined Role")) { // Perform tasks return new Integer(0); } } throw new AccessControlException("Denied"); } }
|