1 16 package org.apache.juddi.function; 17 18 import org.apache.commons.logging.Log; 19 import org.apache.commons.logging.LogFactory; 20 import org.apache.juddi.datastore.DataStore; 21 import org.apache.juddi.datastore.DataStoreFactory; 22 import org.apache.juddi.datatype.RegistryObject; 23 import org.apache.juddi.datatype.publisher.Publisher; 24 import org.apache.juddi.datatype.request.AuthInfo; 25 import org.apache.juddi.datatype.request.DiscardAuthToken; 26 import org.apache.juddi.datatype.request.GetAuthToken; 27 import org.apache.juddi.datatype.response.AuthToken; 28 import org.apache.juddi.datatype.response.DispositionReport; 29 import org.apache.juddi.datatype.response.Result; 30 import org.apache.juddi.error.AuthTokenRequiredException; 31 import org.apache.juddi.error.RegistryException; 32 import org.apache.juddi.registry.RegistryEngine; 33 import org.apache.juddi.util.Config; 34 35 38 public class DiscardAuthTokenFunction extends AbstractFunction 39 { 40 private static Log log = LogFactory.getLog(DiscardAuthTokenFunction.class); 42 43 46 public DiscardAuthTokenFunction(RegistryEngine registry) 47 { 48 super(registry); 49 } 50 51 54 public RegistryObject execute(RegistryObject regObject) 55 throws RegistryException 56 { 57 DiscardAuthToken request = (DiscardAuthToken)regObject; 59 String generic = request.getGeneric(); 60 AuthInfo authInfo = request.getAuthInfo(); 61 62 DataStore dataStore = DataStoreFactory.getDataStore(); 64 65 try 66 { 67 dataStore.beginTrans(); 68 69 Publisher publisher = getPublisher(authInfo,dataStore); 71 String publisherID = publisher.getPublisherID(); 72 73 String authToken = authInfo.getValue(); 74 if ((authInfo == null) || (authInfo.getValue() == null)) 75 throw new AuthTokenRequiredException("discard_authToken: "+ 76 "authInfo="+authInfo); 77 78 dataStore.retireAuthToken(authToken); 79 dataStore.commit(); 80 81 log.info("Publisher '"+publisherID+"' has discarded AuthToken: "+authToken); 82 } 83 catch(AuthTokenRequiredException authex) 84 { 85 try { dataStore.rollback(); } catch(Exception e) { } 86 log.info(authex.getMessage()); 87 throw (RegistryException)authex; 88 } 89 catch(RegistryException regex) 90 { 91 try { dataStore.rollback(); } catch(Exception e) { } 92 log.error(regex); 93 throw (RegistryException)regex; 94 } 95 catch(Exception ex) 96 { 97 try { dataStore.rollback(); } catch(Exception e) { } 98 log.error(ex); 99 throw new RegistryException(ex); 100 } 101 finally 102 { 103 if (dataStore != null) 104 dataStore.release(); 105 } 106 107 Result result = new Result(Result.E_SUCCESS); 111 result.setErrCode(Result.lookupErrCode(Result.E_SUCCESS)); 112 DispositionReport dispRpt = new DispositionReport(); 113 dispRpt.setGeneric(generic); 114 dispRpt.setOperator(Config.getOperator()); 115 dispRpt.addResult(result); 116 117 return dispRpt; 118 } 119 120 121 122 123 124 125 126 public static void main(String [] args) 127 { 128 RegistryEngine reg = new RegistryEngine(); 130 reg.init(); 131 132 try 133 { 134 GetAuthToken getRequest = new GetAuthToken("sviens","password"); 136 137 AuthToken getResponse = (AuthToken)(new GetAuthTokenFunction(reg).execute(getRequest)); 139 140 DiscardAuthToken discardRequest1 = new DiscardAuthToken(getResponse.getAuthInfo()); 142 DispositionReport discardResponse = (DispositionReport)(new DiscardAuthTokenFunction(reg).execute(discardRequest1)); 144 System.out.println("errno: "+discardResponse.toString()); 145 146 DiscardAuthToken discardRequest2 = new DiscardAuthToken(); 148 discardRequest2.setAuthInfo(new AuthInfo("**-BadAuthToken-**")); 149 DispositionReport discardResponse2 = (DispositionReport)(new DiscardAuthTokenFunction(reg).execute(discardRequest2)); 151 System.out.println("errno: "+discardResponse2.toString()); 152 } 153 catch (Exception ex) 154 { 155 ex.printStackTrace(); 157 } 158 finally 159 { 160 reg.dispose(); 162 } 163 } 164 } | Popular Tags |