1 package com.sslexplorer.security; 2 3 import java.util.Iterator ; 4 5 import com.sslexplorer.core.CoreAttributeConstants; 6 import com.sslexplorer.core.CoreEvent; 7 import com.sslexplorer.core.CoreEventConstants; 8 import com.sslexplorer.core.CoreServlet; 9 import com.sslexplorer.policyframework.DefaultResourceType; 10 import com.sslexplorer.policyframework.PolicyConstants; 11 import com.sslexplorer.policyframework.Resource; 12 import com.sslexplorer.policyframework.ResourceChangeEvent; 13 import com.sslexplorer.policyframework.ResourceDeleteEvent; 14 15 21 public class AuthenticationSchemeResourceType extends DefaultResourceType { 22 23 26 public AuthenticationSchemeResourceType() { 27 super(PolicyConstants.AUTHENTICATION_SCHEMES_RESOURCE_TYPE_ID, "policyframework", PolicyConstants.SYSTEM_CLASS); 28 } 29 30 35 public Resource getResourceById(int resourceId) throws Exception { 36 return SystemDatabaseFactory.getInstance().getAuthenticationSchemeSequence(resourceId); 37 } 38 39 42 public Resource getResourceByName(String resourceName, SessionInfo session) throws Exception { 43 return SystemDatabaseFactory.getInstance().getAuthenticationSchemeSequence(resourceName, session.getUser().getRealm().getRealmID()); 44 } 45 46 52 public Resource removeResource(int resourceId, SessionInfo session) throws Exception { 53 try { 54 AuthenticationScheme resource = SystemDatabaseFactory.getInstance().getAuthenticationSchemeSequence( 55 resourceId); 56 SystemDatabaseFactory.getInstance().deleteAuthenticationSchemeSequence(resourceId); 57 CoreServlet.getServlet().fireCoreEvent( 58 new ResourceDeleteEvent(this, CoreEventConstants.DELETE_AUTHENTICATION_SCHEME, resource, session, 59 CoreEvent.STATE_SUCCESSFUL)); 60 return resource; 61 } catch (Exception e) { 62 CoreServlet.getServlet().fireCoreEvent( 63 new ResourceDeleteEvent(this, CoreEventConstants.DELETE_AUTHENTICATION_SCHEME, null, session, 64 CoreEvent.STATE_UNSUCCESSFUL)); 65 throw e; 66 } 67 } 68 69 75 public void updateResource(Resource resource, SessionInfo session) throws Exception { 76 try { 77 SystemDatabaseFactory.getInstance() 78 .updateAuthenticationSchemeSequence((AuthenticationScheme) resource); 79 CoreEvent evt = new ResourceChangeEvent(this, CoreEventConstants.UPDATE_AUTHENTICATION_SCHEME, resource, 80 session, CoreEvent.STATE_SUCCESSFUL); 81 int authCounter = 1; 82 for(Iterator i = ((AuthenticationScheme) resource).modules();i.hasNext(); ) { 83 String s = (String ) i.next(); 84 AuthenticationSchemeResourceType.addAuthenticationModule(evt, s, authCounter); 85 authCounter++; 86 } 87 CoreServlet.getServlet().fireCoreEvent(evt); 88 } catch (Exception e) { 89 CoreServlet.getServlet().fireCoreEvent( 90 new ResourceChangeEvent(this, CoreEventConstants.UPDATE_AUTHENTICATION_SCHEME, session, e)); 91 throw e; 92 } 93 } 94 95 100 public static void addAuthenticationModule(CoreEvent evt, String authenticationModule, int position){ 101 evt.addAttribute(CoreAttributeConstants.EVENT_ATTR_AUTHENTICATION_MODULE+position, authenticationModule); 102 } 103 104 } 105 | Popular Tags |