Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/authentication/AuthenticationComparator.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/authentication/AuthenticationComparator.java?rev=1695126&r1=1695125&r2=1695126&view=diff ============================================================================== --- ofbiz/trunk/framework/common/src/org/ofbiz/common/authentication/AuthenticationComparator.java (original) +++ ofbiz/trunk/framework/common/src/org/ofbiz/common/authentication/AuthenticationComparator.java Mon Aug 10 16:15:37 2015 @@ -1,76 +1,76 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ - -package org.ofbiz.common.authentication; - -import java.util.Comparator; - -import org.ofbiz.common.authentication.api.Authenticator; - -/** - * AuthenticationComparator - * - * Used to sort Authenticators by weight - */ -public class AuthenticationComparator implements Comparator<Authenticator> { - - /** - * Compares its two arguments for order. Returns a negative integer, - * zero, or a positive integer as the first argument is less than, equal - * to, or greater than the second.<p> - * <p/> - * The implementor must ensure that <tt>sgn(compare(x, y)) == - * -sgn(compare(y, x))</tt> for all <tt>x</tt> and <tt>y</tt>. (This - * implies that <tt>compare(x, y)</tt> must throw an exception if and only - * if <tt>compare(y, x)</tt> throws an exception.)<p> - * <p/> - * The implementor must also ensure that the relation is transitive: - * <tt>((compare(x, y)>0) && (compare(y, z)>0))</tt> implies - * <tt>compare(x, z)>0</tt>.<p> - * <p/> - * Finally, the implementer must ensure that <tt>compare(x, y)==0</tt> - * implies that <tt>sgn(compare(x, z))==sgn(compare(y, z))</tt> for all - * <tt>z</tt>.<p> - * <p/> - * It is generally the case, but <i>not</i> strictly required that - * <tt>(compare(x, y)==0) == (x.equals(y))</tt>. Generally speaking, - * any comparator that violates this condition should clearly indicate - * this fact. The recommended language is "Note: this comparator - * imposes orderings that are inconsistent with equals." - * - * @param a1 the first object to be compared. - * @param a2 the second object to be compared. - * @return a negative integer, zero, or a positive integer as the - * first argument is less than, equal to, or greater than the - * second. - * @throws ClassCastException if the arguments' types prevent them from - * being compared by this Comparator. - */ - public int compare(Authenticator a1, Authenticator a2) { - if (a1.getWeight() < a2.getWeight()) { - return -1; - } else if (a1.getWeight() > a2.getWeight()) { - return 1; - } else if (!a1.getClass().equals(a2.getClass())) { - return -1; - } else { - return a1.getClass().getName().compareTo(a2.getClass().getName()); - } - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ + +package org.ofbiz.common.authentication; + +import java.util.Comparator; + +import org.ofbiz.common.authentication.api.Authenticator; + +/** + * AuthenticationComparator + * + * Used to sort Authenticators by weight + */ +public class AuthenticationComparator implements Comparator<Authenticator> { + + /** + * Compares its two arguments for order. Returns a negative integer, + * zero, or a positive integer as the first argument is less than, equal + * to, or greater than the second.<p> + * <p/> + * The implementor must ensure that <tt>sgn(compare(x, y)) == + * -sgn(compare(y, x))</tt> for all <tt>x</tt> and <tt>y</tt>. (This + * implies that <tt>compare(x, y)</tt> must throw an exception if and only + * if <tt>compare(y, x)</tt> throws an exception.)<p> + * <p/> + * The implementor must also ensure that the relation is transitive: + * <tt>((compare(x, y)>0) && (compare(y, z)>0))</tt> implies + * <tt>compare(x, z)>0</tt>.<p> + * <p/> + * Finally, the implementer must ensure that <tt>compare(x, y)==0</tt> + * implies that <tt>sgn(compare(x, z))==sgn(compare(y, z))</tt> for all + * <tt>z</tt>.<p> + * <p/> + * It is generally the case, but <i>not</i> strictly required that + * <tt>(compare(x, y)==0) == (x.equals(y))</tt>. Generally speaking, + * any comparator that violates this condition should clearly indicate + * this fact. The recommended language is "Note: this comparator + * imposes orderings that are inconsistent with equals." + * + * @param a1 the first object to be compared. + * @param a2 the second object to be compared. + * @return a negative integer, zero, or a positive integer as the + * first argument is less than, equal to, or greater than the + * second. + * @throws ClassCastException if the arguments' types prevent them from + * being compared by this Comparator. + */ + public int compare(Authenticator a1, Authenticator a2) { + if (a1.getWeight() < a2.getWeight()) { + return -1; + } else if (a1.getWeight() > a2.getWeight()) { + return 1; + } else if (!a1.getClass().equals(a2.getClass())) { + return -1; + } else { + return a1.getClass().getName().compareTo(a2.getClass().getName()); + } + } +} Propchange: ofbiz/trunk/framework/common/src/org/ofbiz/common/authentication/AuthenticationComparator.java ('svn:eol-style' removed) Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/authentication/api/Authenticator.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/authentication/api/Authenticator.java?rev=1695126&r1=1695125&r2=1695126&view=diff ============================================================================== --- ofbiz/trunk/framework/common/src/org/ofbiz/common/authentication/api/Authenticator.java (original) +++ ofbiz/trunk/framework/common/src/org/ofbiz/common/authentication/api/Authenticator.java Mon Aug 10 16:15:37 2015 @@ -1,97 +1,97 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ - -package org.ofbiz.common.authentication.api; - -import org.ofbiz.service.LocalDispatcher; - -/** - * Authenticator - * - * Classes which implement this interface (directly) will be auto-discovered and loaded as Authenticators - * as long as isEnabled() returns true. All implementations MUST be in the org.ofbiz top level package in - * order to be discovered. - */ -public interface Authenticator { - - /** - * Method called when authenticator is first initialized (the delegator - * object can be obtained from the LocalDispatcher) - * @param dispatcher The LocalDispatcher to use for this Authenticator - */ - public void initialize(LocalDispatcher dispatcher); - - /** - * Method to authenticate a user - * @param username User's username - * @param password User's password - * @param isServiceAuth true if authentication is for a service call - * @return true if the user is authenticated - * @throws AuthenticatorException when a fatal error occurs during authentication - */ - public boolean authenticate(String username, String password, boolean isServiceAuth) throws AuthenticatorException; - - /** - * Logs a user out - * @param username User's username - * @throws AuthenticatorException when logout fails - */ - public void logout(String username) throws AuthenticatorException; - - /** - * Reads user information and syncs it to OFBiz (i.e. UserLogin, Person, etc) - * Note: when creating a UserLogin object, be sure to set 'externalAuthId' - * @param username User's username - * @throws AuthenticatorException user synchronization fails - */ - public void syncUser(String username) throws AuthenticatorException; - - /** - * Updates a user's password - * @param username User's username - * @param password User's current password - * @param newPassword User's new password - * @throws AuthenticatorException when update password fails - */ - public void updatePassword(String username, String password, String newPassword) throws AuthenticatorException; - - /** - * Weight of this authenticator (lower weights are run first) - * @return the weight of this Authenticator - */ - public float getWeight(); - - /** - * Is the user synchronized back to OFBiz - * @return true if the user record is copied to the OFB database - */ - public boolean isUserSynchronized(); - - /** - * Is this expected to be the only authenticator, if so errors will be thrown when users cannot be found - * @return true if this is expected to be the only Authenticator - */ - public boolean isSingleAuthenticator(); - - /** - * Flag to test if this Authenticator is enabled - * @return true if the Authenticator is enabled - */ - public boolean isEnabled(); -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ + +package org.ofbiz.common.authentication.api; + +import org.ofbiz.service.LocalDispatcher; + +/** + * Authenticator + * + * Classes which implement this interface (directly) will be auto-discovered and loaded as Authenticators + * as long as isEnabled() returns true. All implementations MUST be in the org.ofbiz top level package in + * order to be discovered. + */ +public interface Authenticator { + + /** + * Method called when authenticator is first initialized (the delegator + * object can be obtained from the LocalDispatcher) + * @param dispatcher The LocalDispatcher to use for this Authenticator + */ + public void initialize(LocalDispatcher dispatcher); + + /** + * Method to authenticate a user + * @param username User's username + * @param password User's password + * @param isServiceAuth true if authentication is for a service call + * @return true if the user is authenticated + * @throws AuthenticatorException when a fatal error occurs during authentication + */ + public boolean authenticate(String username, String password, boolean isServiceAuth) throws AuthenticatorException; + + /** + * Logs a user out + * @param username User's username + * @throws AuthenticatorException when logout fails + */ + public void logout(String username) throws AuthenticatorException; + + /** + * Reads user information and syncs it to OFBiz (i.e. UserLogin, Person, etc) + * Note: when creating a UserLogin object, be sure to set 'externalAuthId' + * @param username User's username + * @throws AuthenticatorException user synchronization fails + */ + public void syncUser(String username) throws AuthenticatorException; + + /** + * Updates a user's password + * @param username User's username + * @param password User's current password + * @param newPassword User's new password + * @throws AuthenticatorException when update password fails + */ + public void updatePassword(String username, String password, String newPassword) throws AuthenticatorException; + + /** + * Weight of this authenticator (lower weights are run first) + * @return the weight of this Authenticator + */ + public float getWeight(); + + /** + * Is the user synchronized back to OFBiz + * @return true if the user record is copied to the OFB database + */ + public boolean isUserSynchronized(); + + /** + * Is this expected to be the only authenticator, if so errors will be thrown when users cannot be found + * @return true if this is expected to be the only Authenticator + */ + public boolean isSingleAuthenticator(); + + /** + * Flag to test if this Authenticator is enabled + * @return true if the Authenticator is enabled + */ + public boolean isEnabled(); +} Propchange: ofbiz/trunk/framework/common/src/org/ofbiz/common/authentication/api/Authenticator.java ('svn:eol-style' removed) Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/authentication/api/AuthenticatorException.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/authentication/api/AuthenticatorException.java?rev=1695126&r1=1695125&r2=1695126&view=diff ============================================================================== --- ofbiz/trunk/framework/common/src/org/ofbiz/common/authentication/api/AuthenticatorException.java (original) +++ ofbiz/trunk/framework/common/src/org/ofbiz/common/authentication/api/AuthenticatorException.java Mon Aug 10 16:15:37 2015 @@ -1,102 +1,102 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ - -package org.ofbiz.common.authentication.api; - -import java.util.List; - -import org.ofbiz.base.util.GeneralException; - -/** - * AuthenticatorException - */ -public class AuthenticatorException extends GeneralException { - - private static final long serialVersionUID = 2836939874682240962L; - - /** - * Creates new <code>GeneralException</code> without detail message. - */ - public AuthenticatorException() { - super(); - } - - /** - * Constructs an <code>GeneralException</code> with the specified detail message. - * - * @param msg the detail message. - */ - public AuthenticatorException(String msg) { - super(msg); - } - - /** - * Constructs an <code>GeneralException</code> with the specified detail message and nested Exception. - * - * @param msg the detail message. - * @param nested the nested exception. - */ - public AuthenticatorException(String msg, Throwable nested) { - super(msg, nested); - } - - /** - * Constructs an <code>GeneralException</code> with the specified detail message and nested Exception. - * - * @param nested the nested exception. - */ - public AuthenticatorException(Throwable nested) { - super(nested); - } - - /** - * Constructs an <code>GeneralException</code> with the specified detail message, list and nested Exception. - * - * @param msg the detail message. - * @param messages error message list. - */ - public AuthenticatorException(String msg, List<String> messages) { - super(msg, messages); - } - - /** - * Constructs an <code>GeneralException</code> with the specified detail message, list and nested Exception. - * - * @param msg the detail message. - * @param messages error message list. - * @param nested the nested exception - */ - public AuthenticatorException(String msg, List<String> messages, Throwable nested) { - super(msg, messages, nested); - } - - /** - * Constructs an <code>GeneralException</code> with the specified detail message list and nested Exception. - * - * @param messages error message list. - * @param nested the nested exception. - */ - public AuthenticatorException(List<String> messages, Throwable nested) { - super(messages, nested); - } - - public AuthenticatorException(List<String> messages) { - super(messages); - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ + +package org.ofbiz.common.authentication.api; + +import java.util.List; + +import org.ofbiz.base.util.GeneralException; + +/** + * AuthenticatorException + */ +public class AuthenticatorException extends GeneralException { + + private static final long serialVersionUID = 2836939874682240962L; + + /** + * Creates new <code>GeneralException</code> without detail message. + */ + public AuthenticatorException() { + super(); + } + + /** + * Constructs an <code>GeneralException</code> with the specified detail message. + * + * @param msg the detail message. + */ + public AuthenticatorException(String msg) { + super(msg); + } + + /** + * Constructs an <code>GeneralException</code> with the specified detail message and nested Exception. + * + * @param msg the detail message. + * @param nested the nested exception. + */ + public AuthenticatorException(String msg, Throwable nested) { + super(msg, nested); + } + + /** + * Constructs an <code>GeneralException</code> with the specified detail message and nested Exception. + * + * @param nested the nested exception. + */ + public AuthenticatorException(Throwable nested) { + super(nested); + } + + /** + * Constructs an <code>GeneralException</code> with the specified detail message, list and nested Exception. + * + * @param msg the detail message. + * @param messages error message list. + */ + public AuthenticatorException(String msg, List<String> messages) { + super(msg, messages); + } + + /** + * Constructs an <code>GeneralException</code> with the specified detail message, list and nested Exception. + * + * @param msg the detail message. + * @param messages error message list. + * @param nested the nested exception + */ + public AuthenticatorException(String msg, List<String> messages, Throwable nested) { + super(msg, messages, nested); + } + + /** + * Constructs an <code>GeneralException</code> with the specified detail message list and nested Exception. + * + * @param messages error message list. + * @param nested the nested exception. + */ + public AuthenticatorException(List<String> messages, Throwable nested) { + super(messages, nested); + } + + public AuthenticatorException(List<String> messages) { + super(messages); + } +} Propchange: ofbiz/trunk/framework/common/src/org/ofbiz/common/authentication/api/AuthenticatorException.java ('svn:eol-style' removed) Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/authentication/example/TestFailAuthenticator.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/authentication/example/TestFailAuthenticator.java?rev=1695126&r1=1695125&r2=1695126&view=diff ============================================================================== --- ofbiz/trunk/framework/common/src/org/ofbiz/common/authentication/example/TestFailAuthenticator.java (original) +++ ofbiz/trunk/framework/common/src/org/ofbiz/common/authentication/example/TestFailAuthenticator.java Mon Aug 10 16:15:37 2015 @@ -1,138 +1,138 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ - -package org.ofbiz.common.authentication.example; - -import org.ofbiz.common.authentication.api.Authenticator; -import org.ofbiz.common.authentication.api.AuthenticatorException; -import org.ofbiz.service.LocalDispatcher; -import org.ofbiz.entity.Delegator; -import org.ofbiz.base.util.Debug; - -/** - * LocalAuthenticator - */ -public class TestFailAuthenticator implements Authenticator { - - private static final String module = TestFailAuthenticator.class.getName(); - protected Delegator delegator; - protected LocalDispatcher dispatcher; - protected float weight = 1; - - /** - * Method called when authenticator is first initialized (the delegator - * object can be obtained from the LocalDispatcher) - * - * @param dispatcher The LocalDispatcher to use for this Authenticator - */ - public void initialize(LocalDispatcher dispatcher) { - this.dispatcher = dispatcher; - this.delegator = dispatcher.getDelegator(); - Debug.logInfo(this.getClass().getName() + " Authenticator initialized", module); - } - - /** - * Method to authenticate a user - * - * @param username User's username - * @param password User's password - * @param isServiceAuth true if authentication is for a service call - * @return true if the user is authenticated - * @throws org.ofbiz.common.authentication.api.AuthenticatorException - * when a fatal error occurs during authentication - */ - public boolean authenticate(String username, String password, boolean isServiceAuth) throws AuthenticatorException { - Debug.logInfo(this.getClass().getName() + " Authenticator authenticate() -- returning false", module); - return false; - } - - /** - * Logs a user out - * - * @param username User's username - * @throws org.ofbiz.common.authentication.api.AuthenticatorException - * when logout fails - */ - public void logout(String username) throws AuthenticatorException { - Debug.logInfo(this.getClass().getName() + " Authenticator logout()", module); - } - - /** - * Reads user information and syncs it to OFBiz (i.e. UserLogin, Person, etc) - * - * @param username User's username - * @throws org.ofbiz.common.authentication.api.AuthenticatorException - * user synchronization fails - */ - public void syncUser(String username) throws AuthenticatorException { - Debug.logInfo(this.getClass().getName() + " Authenticator syncUser()", module); - // no user info to sync - } - - /** - * Updates a user's password - * - * @param username User's username - * @param password User's current password - * @param newPassword User's new password - * @throws org.ofbiz.common.authentication.api.AuthenticatorException - * when update password fails - */ - public void updatePassword(String username, String password, String newPassword) throws AuthenticatorException { - Debug.logInfo(this.getClass().getName() + " Authenticator updatePassword()", module); - } - - /** - * Weight of this authenticator (lower weights are run first) - * - * @return the weight of this Authenticator - */ - public float getWeight() { - return 1; - } - - /** - * Is the user synchronized back to OFBiz - * - * @return true if the user record is copied to the OFB database - */ - public boolean isUserSynchronized() { - Debug.logInfo(this.getClass().getName() + " Authenticator isUserSynchronized()", module); - return true; - } - - /** - * Is this expected to be the only authenticator, if so errors will be thrown when users cannot be found - * - * @return true if this is expected to be the only Authenticator - */ - public boolean isSingleAuthenticator() { - Debug.logInfo(this.getClass().getName() + " Authenticator isSingleAuthenticator()", module); - return false; - } - - /** - * Flag to test if this Authenticator is enabled - * - * @return true if the Authenticator is enabled - */ - public boolean isEnabled() { - return false; - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ + +package org.ofbiz.common.authentication.example; + +import org.ofbiz.common.authentication.api.Authenticator; +import org.ofbiz.common.authentication.api.AuthenticatorException; +import org.ofbiz.service.LocalDispatcher; +import org.ofbiz.entity.Delegator; +import org.ofbiz.base.util.Debug; + +/** + * LocalAuthenticator + */ +public class TestFailAuthenticator implements Authenticator { + + private static final String module = TestFailAuthenticator.class.getName(); + protected Delegator delegator; + protected LocalDispatcher dispatcher; + protected float weight = 1; + + /** + * Method called when authenticator is first initialized (the delegator + * object can be obtained from the LocalDispatcher) + * + * @param dispatcher The LocalDispatcher to use for this Authenticator + */ + public void initialize(LocalDispatcher dispatcher) { + this.dispatcher = dispatcher; + this.delegator = dispatcher.getDelegator(); + Debug.logInfo(this.getClass().getName() + " Authenticator initialized", module); + } + + /** + * Method to authenticate a user + * + * @param username User's username + * @param password User's password + * @param isServiceAuth true if authentication is for a service call + * @return true if the user is authenticated + * @throws org.ofbiz.common.authentication.api.AuthenticatorException + * when a fatal error occurs during authentication + */ + public boolean authenticate(String username, String password, boolean isServiceAuth) throws AuthenticatorException { + Debug.logInfo(this.getClass().getName() + " Authenticator authenticate() -- returning false", module); + return false; + } + + /** + * Logs a user out + * + * @param username User's username + * @throws org.ofbiz.common.authentication.api.AuthenticatorException + * when logout fails + */ + public void logout(String username) throws AuthenticatorException { + Debug.logInfo(this.getClass().getName() + " Authenticator logout()", module); + } + + /** + * Reads user information and syncs it to OFBiz (i.e. UserLogin, Person, etc) + * + * @param username User's username + * @throws org.ofbiz.common.authentication.api.AuthenticatorException + * user synchronization fails + */ + public void syncUser(String username) throws AuthenticatorException { + Debug.logInfo(this.getClass().getName() + " Authenticator syncUser()", module); + // no user info to sync + } + + /** + * Updates a user's password + * + * @param username User's username + * @param password User's current password + * @param newPassword User's new password + * @throws org.ofbiz.common.authentication.api.AuthenticatorException + * when update password fails + */ + public void updatePassword(String username, String password, String newPassword) throws AuthenticatorException { + Debug.logInfo(this.getClass().getName() + " Authenticator updatePassword()", module); + } + + /** + * Weight of this authenticator (lower weights are run first) + * + * @return the weight of this Authenticator + */ + public float getWeight() { + return 1; + } + + /** + * Is the user synchronized back to OFBiz + * + * @return true if the user record is copied to the OFB database + */ + public boolean isUserSynchronized() { + Debug.logInfo(this.getClass().getName() + " Authenticator isUserSynchronized()", module); + return true; + } + + /** + * Is this expected to be the only authenticator, if so errors will be thrown when users cannot be found + * + * @return true if this is expected to be the only Authenticator + */ + public boolean isSingleAuthenticator() { + Debug.logInfo(this.getClass().getName() + " Authenticator isSingleAuthenticator()", module); + return false; + } + + /** + * Flag to test if this Authenticator is enabled + * + * @return true if the Authenticator is enabled + */ + public boolean isEnabled() { + return false; + } +} Propchange: ofbiz/trunk/framework/common/src/org/ofbiz/common/authentication/example/TestFailAuthenticator.java ('svn:eol-style' removed) Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/authentication/example/TestPassAuthenticator.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/authentication/example/TestPassAuthenticator.java?rev=1695126&r1=1695125&r2=1695126&view=diff ============================================================================== --- ofbiz/trunk/framework/common/src/org/ofbiz/common/authentication/example/TestPassAuthenticator.java (original) +++ ofbiz/trunk/framework/common/src/org/ofbiz/common/authentication/example/TestPassAuthenticator.java Mon Aug 10 16:15:37 2015 @@ -1,57 +1,57 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ - -package org.ofbiz.common.authentication.example; - -import org.ofbiz.base.util.Debug; -import org.ofbiz.common.authentication.api.AuthenticatorException; - -/** - * TestPassAuthenticator - */ -public class TestPassAuthenticator extends TestFailAuthenticator { - - private static final String module = TestPassAuthenticator.class.getName(); - - /** - * Method to authenticate a user - * - * @param username User's username - * @param password User's password - * @param isServiceAuth true if authentication is for a service call - * @return true if the user is authenticated - * @throws org.ofbiz.common.authentication.api.AuthenticatorException - * when a fatal error occurs during authentication - */ - @Override - public boolean authenticate(String username, String password, boolean isServiceAuth) throws AuthenticatorException { - Debug.logInfo(this.getClass().getName() + " Authenticator authenticate() -- returning false", module); - return true; - } - - /** - * Flag to test if this Authenticator is enabled - * - * @return true if the Authenticator is enabled - */ - @Override - public boolean isEnabled() { - return false; - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ + +package org.ofbiz.common.authentication.example; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.common.authentication.api.AuthenticatorException; + +/** + * TestPassAuthenticator + */ +public class TestPassAuthenticator extends TestFailAuthenticator { + + private static final String module = TestPassAuthenticator.class.getName(); + + /** + * Method to authenticate a user + * + * @param username User's username + * @param password User's password + * @param isServiceAuth true if authentication is for a service call + * @return true if the user is authenticated + * @throws org.ofbiz.common.authentication.api.AuthenticatorException + * when a fatal error occurs during authentication + */ + @Override + public boolean authenticate(String username, String password, boolean isServiceAuth) throws AuthenticatorException { + Debug.logInfo(this.getClass().getName() + " Authenticator authenticate() -- returning false", module); + return true; + } + + /** + * Flag to test if this Authenticator is enabled + * + * @return true if the Authenticator is enabled + */ + @Override + public boolean isEnabled() { + return false; + } +} Propchange: ofbiz/trunk/framework/common/src/org/ofbiz/common/authentication/example/TestPassAuthenticator.java ('svn:eol-style' removed) Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallScript.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallScript.java?rev=1695126&r1=1695125&r2=1695126&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallScript.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallScript.java Mon Aug 10 16:15:37 2015 @@ -1,149 +1,149 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.minilang.method.callops; - -import org.ofbiz.base.util.ScriptUtil; -import org.ofbiz.base.util.Scriptlet; -import org.ofbiz.base.util.StringUtil; -import org.ofbiz.base.util.UtilXml; -import org.ofbiz.minilang.MiniLangException; -import org.ofbiz.minilang.MiniLangRuntimeException; -import org.ofbiz.minilang.MiniLangUtil; -import org.ofbiz.minilang.MiniLangValidate; -import org.ofbiz.minilang.SimpleMethod; -import org.ofbiz.minilang.method.MethodContext; -import org.ofbiz.minilang.method.MethodOperation; -import org.w3c.dom.Element; - -/** - * Implements the <script> element. - * - * @see <a href="https://cwiki.apache.org/confluence/display/OFBADMIN/Mini-language+Reference#Mini-languageReference-{{%3Cscript%3E}}">Mini-language Reference</a> - */ -public final class CallScript extends MethodOperation { - - public static final String module = CallScript.class.getName(); - - // This method is needed only during the v1 to v2 transition - private static boolean autoCorrect(Element element) { - String errorListAttr = element.getAttribute("error-list-name"); - if (errorListAttr.length() > 0) { - element.removeAttribute("error-list-name"); - return true; - } - return false; - } - - /* - * Developers - the location attribute is a constant for security reasons. - * Script invocations should always be hard-coded. - */ - private final String location; - private final String method; - private final Scriptlet scriptlet; - - public CallScript(Element element, SimpleMethod simpleMethod) throws MiniLangException { - super(element, simpleMethod); - if (MiniLangValidate.validationOn()) { - MiniLangValidate.attributeNames(simpleMethod, element, "location", "script"); - MiniLangValidate.requireAnyAttribute(simpleMethod, element, "location", "script"); - MiniLangValidate.constantAttributes(simpleMethod, element, "location"); - MiniLangValidate.scriptAttributes(simpleMethod, element, "script"); - MiniLangValidate.noChildElements(simpleMethod, element); - } - boolean elementModified = autoCorrect(element); - if (elementModified && MiniLangUtil.autoCorrectOn()) { - MiniLangUtil.flagDocumentAsCorrected(element); - } - String scriptLocation = element.getAttribute("location"); - if (scriptLocation.isEmpty()) { - this.location = null; - this.method = null; - } else { - int pos = scriptLocation.lastIndexOf("#"); - if (pos == -1) { - this.location = scriptLocation; - this.method = null; - } else { - this.location = scriptLocation.substring(0, pos); - this.method = scriptLocation.substring(pos + 1); - } - } - String inlineScript = element.getAttribute("script"); - if (inlineScript.isEmpty()) { - inlineScript = UtilXml.elementValue(element); - } - if (inlineScript != null && MiniLangUtil.containsScript(inlineScript)) { - this.scriptlet = new Scriptlet(StringUtil.convertOperatorSubstitutions(inlineScript)); - } else { - this.scriptlet = null; - } - } - - @Override - public boolean exec(MethodContext methodContext) throws MiniLangException { - if (this.location != null) { - if (location.endsWith(".xml")) { - SimpleMethod.runSimpleMethod(location, method, methodContext); - } else { - ScriptUtil.executeScript(this.location, this.method, methodContext.getEnvMap()); - } - } - if (this.scriptlet != null) { - try { - this.scriptlet.executeScript(methodContext.getEnvMap()); - } catch (Exception e) { - throw new MiniLangRuntimeException(e.getMessage(), this); - } - } - return true; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder("<script "); - if (this.location != null) { - sb.append("location=\"").append(this.location); - if (this.method != null) { - sb.append("#").append(this.method); - } - sb.append("\" "); - } - if (this.scriptlet != null) { - sb.append("script=\"").append(this.scriptlet).append("\" "); - } - sb.append("/>"); - return sb.toString(); - } - - /** - * A factory for the <script> element. - */ - public static final class CallScriptFactory implements Factory<CallScript> { - @Override - public CallScript createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { - return new CallScript(element, simpleMethod); - } - - @Override - public String getName() { - return "script"; - } - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.minilang.method.callops; + +import org.ofbiz.base.util.ScriptUtil; +import org.ofbiz.base.util.Scriptlet; +import org.ofbiz.base.util.StringUtil; +import org.ofbiz.base.util.UtilXml; +import org.ofbiz.minilang.MiniLangException; +import org.ofbiz.minilang.MiniLangRuntimeException; +import org.ofbiz.minilang.MiniLangUtil; +import org.ofbiz.minilang.MiniLangValidate; +import org.ofbiz.minilang.SimpleMethod; +import org.ofbiz.minilang.method.MethodContext; +import org.ofbiz.minilang.method.MethodOperation; +import org.w3c.dom.Element; + +/** + * Implements the <script> element. + * + * @see <a href="https://cwiki.apache.org/confluence/display/OFBADMIN/Mini-language+Reference#Mini-languageReference-{{%3Cscript%3E}}">Mini-language Reference</a> + */ +public final class CallScript extends MethodOperation { + + public static final String module = CallScript.class.getName(); + + // This method is needed only during the v1 to v2 transition + private static boolean autoCorrect(Element element) { + String errorListAttr = element.getAttribute("error-list-name"); + if (errorListAttr.length() > 0) { + element.removeAttribute("error-list-name"); + return true; + } + return false; + } + + /* + * Developers - the location attribute is a constant for security reasons. + * Script invocations should always be hard-coded. + */ + private final String location; + private final String method; + private final Scriptlet scriptlet; + + public CallScript(Element element, SimpleMethod simpleMethod) throws MiniLangException { + super(element, simpleMethod); + if (MiniLangValidate.validationOn()) { + MiniLangValidate.attributeNames(simpleMethod, element, "location", "script"); + MiniLangValidate.requireAnyAttribute(simpleMethod, element, "location", "script"); + MiniLangValidate.constantAttributes(simpleMethod, element, "location"); + MiniLangValidate.scriptAttributes(simpleMethod, element, "script"); + MiniLangValidate.noChildElements(simpleMethod, element); + } + boolean elementModified = autoCorrect(element); + if (elementModified && MiniLangUtil.autoCorrectOn()) { + MiniLangUtil.flagDocumentAsCorrected(element); + } + String scriptLocation = element.getAttribute("location"); + if (scriptLocation.isEmpty()) { + this.location = null; + this.method = null; + } else { + int pos = scriptLocation.lastIndexOf("#"); + if (pos == -1) { + this.location = scriptLocation; + this.method = null; + } else { + this.location = scriptLocation.substring(0, pos); + this.method = scriptLocation.substring(pos + 1); + } + } + String inlineScript = element.getAttribute("script"); + if (inlineScript.isEmpty()) { + inlineScript = UtilXml.elementValue(element); + } + if (inlineScript != null && MiniLangUtil.containsScript(inlineScript)) { + this.scriptlet = new Scriptlet(StringUtil.convertOperatorSubstitutions(inlineScript)); + } else { + this.scriptlet = null; + } + } + + @Override + public boolean exec(MethodContext methodContext) throws MiniLangException { + if (this.location != null) { + if (location.endsWith(".xml")) { + SimpleMethod.runSimpleMethod(location, method, methodContext); + } else { + ScriptUtil.executeScript(this.location, this.method, methodContext.getEnvMap()); + } + } + if (this.scriptlet != null) { + try { + this.scriptlet.executeScript(methodContext.getEnvMap()); + } catch (Exception e) { + throw new MiniLangRuntimeException(e.getMessage(), this); + } + } + return true; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("<script "); + if (this.location != null) { + sb.append("location=\"").append(this.location); + if (this.method != null) { + sb.append("#").append(this.method); + } + sb.append("\" "); + } + if (this.scriptlet != null) { + sb.append("script=\"").append(this.scriptlet).append("\" "); + } + sb.append("/>"); + return sb.toString(); + } + + /** + * A factory for the <script> element. + */ + public static final class CallScriptFactory implements Factory<CallScript> { + @Override + public CallScript createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { + return new CallScript(element, simpleMethod); + } + + @Override + public String getName() { + return "script"; + } + } +} Propchange: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallScript.java ('svn:eol-style' removed) Modified: ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Instrumenter.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Instrumenter.java?rev=1695126&r1=1695125&r2=1695126&view=diff ============================================================================== --- ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Instrumenter.java (original) +++ ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Instrumenter.java Mon Aug 10 16:15:37 2015 @@ -1,29 +1,29 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.base.start; - -import java.io.File; -import java.io.IOException; - -public interface Instrumenter { - File getDefaultFile() throws IOException; - void open(File dataFile, boolean forInstrumenting) throws IOException; - byte[] instrumentClass(byte[] bytes) throws IOException; - void close() throws IOException; -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.base.start; + +import java.io.File; +import java.io.IOException; + +public interface Instrumenter { + File getDefaultFile() throws IOException; + void open(File dataFile, boolean forInstrumenting) throws IOException; + byte[] instrumentClass(byte[] bytes) throws IOException; + void close() throws IOException; +} Propchange: ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Instrumenter.java ('svn:eol-style' removed) Modified: ofbiz/trunk/framework/start/src/org/ofbiz/base/start/InstrumenterWorker.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/start/src/org/ofbiz/base/start/InstrumenterWorker.java?rev=1695126&r1=1695125&r2=1695126&view=diff ============================================================================== --- ofbiz/trunk/framework/start/src/org/ofbiz/base/start/InstrumenterWorker.java (original) +++ ofbiz/trunk/framework/start/src/org/ofbiz/base/start/InstrumenterWorker.java Mon Aug 10 16:15:37 2015 @@ -1,192 +1,192 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.base.start; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.InputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.lang.Runtime; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.List; -import java.util.ArrayList; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; -import java.util.zip.ZipOutputStream; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import java.util.concurrent.ScheduledThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -public final class InstrumenterWorker { - - public static final void copy(InputStream in, OutputStream out) throws IOException { - byte[] buf = new byte[4096]; - int r; - while ((r = in.read(buf)) != -1) { - out.write(buf, 0, r); - } - } - - public static List<File> instrument(List<File> srcPaths, String instrumenterFileName, String instrumenterClassName) { - if (instrumenterFileName == null) return srcPaths; - if (instrumenterClassName == null) return srcPaths; - Instrumenter instrumenter; - try { - List<URL> tmpUrls = new ArrayList<URL>(); - for (File file: srcPaths) { - tmpUrls.add(file.toURI().toURL()); - } - ClassLoader tmpLoader = new URLClassLoader(tmpUrls.toArray(new URL[tmpUrls.size()]), InstrumenterWorker.class.getClassLoader()); - instrumenter = (Instrumenter) tmpLoader.loadClass(instrumenterClassName).newInstance(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - return srcPaths; - } catch (InstantiationException e) { - e.printStackTrace(); - return srcPaths; - } catch (IOException e) { - e.printStackTrace(); - return srcPaths; - } catch (ClassNotFoundException e) { - return srcPaths; - } - ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(Runtime.getRuntime().availableProcessors()); - try { - File instrumenterFile = new File(instrumenterFileName); - instrumenterFile.delete(); - instrumenter.open(instrumenterFile, true); - List<Future<File>> futures = new ArrayList<Future<File>>(); - for (File file: srcPaths) { - String path = file.getPath(); - if (path.matches(".*/ofbiz[^/]*\\.(jar|zip)")) { - futures.add(executor.submit(new FileInstrumenter(instrumenter, file))); - } else { - futures.add(new ConstantFutureFile(file)); - } - } - List<File> result = new ArrayList<File>(futures.size()); - for (Future<File> future: futures) { - result.add(future.get()); - } - instrumenter.close(); - return result; - } catch (ExecutionException e) { - e.printStackTrace(); - return srcPaths; - } catch (InterruptedException e) { - e.printStackTrace(); - return srcPaths; - } catch (IOException e) { - e.printStackTrace(); - return srcPaths; - } finally { - executor.shutdown(); - } - } - - private static final class ConstantFutureFile implements Future<File> { - private final File file; - - protected ConstantFutureFile(File file) { - this.file = file; - } - - public boolean cancel(boolean mayInterruptIfRunning) { - return false; - } - - public File get() { - return file; - } - - public File get(long timeout, TimeUnit unit) { - return file; - } - - public boolean isCancelled() { - return false; - } - - public boolean isDone() { - return true; - } - } - - private static final class FileInstrumenter implements Callable<File> { - private final Instrumenter instrumenter; - private final File file; - private final String path; - - protected FileInstrumenter(Instrumenter instrumenter, File file) { - this.instrumenter = instrumenter; - this.file = file; - this.path = file.getPath(); - } - - public File call() throws IOException { - System.err.println(Thread.currentThread() + ":instrumenting " + path); - String prefix = path.substring(0, path.length() - 4); - int slash = prefix.lastIndexOf("/"); - if (slash != -1) prefix = prefix.substring(slash + 1); - prefix += "-"; - File zipTmp = File.createTempFile("instrumented-" + prefix, path.substring(path.length() - 4)); - try { - zipTmp.deleteOnExit(); - ZipInputStream zin = new ZipInputStream(new FileInputStream(file)); - ZipOutputStream zout = new ZipOutputStream(new FileOutputStream(zipTmp)); - ZipEntry entry; - while ((entry = zin.getNextEntry()) != null) { - InputStream in; - long size; - if (entry.getName().endsWith(".class")) { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - copy(zin, baos); - byte[] bytes = instrumenter.instrumentClass(baos.toByteArray()); - size = bytes.length; - in = new ByteArrayInputStream(bytes); - } else { - in = zin; - size = entry.getSize(); - } - ZipEntry newEntry = new ZipEntry(entry); - newEntry.setSize(size); - newEntry.setCompressedSize(-1); - zout.putNextEntry(newEntry); - copy(in, zout); - if (entry.getName().endsWith(".class")) { - in.close(); - } - } - zout.close(); - return zipTmp; - } catch (IOException e) { - zipTmp.delete(); - throw e; - } - } - } -} - +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.base.start; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.lang.Runtime; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.List; +import java.util.ArrayList; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; +import java.util.zip.ZipOutputStream; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +public final class InstrumenterWorker { + + public static final void copy(InputStream in, OutputStream out) throws IOException { + byte[] buf = new byte[4096]; + int r; + while ((r = in.read(buf)) != -1) { + out.write(buf, 0, r); + } + } + + public static List<File> instrument(List<File> srcPaths, String instrumenterFileName, String instrumenterClassName) { + if (instrumenterFileName == null) return srcPaths; + if (instrumenterClassName == null) return srcPaths; + Instrumenter instrumenter; + try { + List<URL> tmpUrls = new ArrayList<URL>(); + for (File file: srcPaths) { + tmpUrls.add(file.toURI().toURL()); + } + ClassLoader tmpLoader = new URLClassLoader(tmpUrls.toArray(new URL[tmpUrls.size()]), InstrumenterWorker.class.getClassLoader()); + instrumenter = (Instrumenter) tmpLoader.loadClass(instrumenterClassName).newInstance(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + return srcPaths; + } catch (InstantiationException e) { + e.printStackTrace(); + return srcPaths; + } catch (IOException e) { + e.printStackTrace(); + return srcPaths; + } catch (ClassNotFoundException e) { + return srcPaths; + } + ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(Runtime.getRuntime().availableProcessors()); + try { + File instrumenterFile = new File(instrumenterFileName); + instrumenterFile.delete(); + instrumenter.open(instrumenterFile, true); + List<Future<File>> futures = new ArrayList<Future<File>>(); + for (File file: srcPaths) { + String path = file.getPath(); + if (path.matches(".*/ofbiz[^/]*\\.(jar|zip)")) { + futures.add(executor.submit(new FileInstrumenter(instrumenter, file))); + } else { + futures.add(new ConstantFutureFile(file)); + } + } + List<File> result = new ArrayList<File>(futures.size()); + for (Future<File> future: futures) { + result.add(future.get()); + } + instrumenter.close(); + return result; + } catch (ExecutionException e) { + e.printStackTrace(); + return srcPaths; + } catch (InterruptedException e) { + e.printStackTrace(); + return srcPaths; + } catch (IOException e) { + e.printStackTrace(); + return srcPaths; + } finally { + executor.shutdown(); + } + } + + private static final class ConstantFutureFile implements Future<File> { + private final File file; + + protected ConstantFutureFile(File file) { + this.file = file; + } + + public boolean cancel(boolean mayInterruptIfRunning) { + return false; + } + + public File get() { + return file; + } + + public File get(long timeout, TimeUnit unit) { + return file; + } + + public boolean isCancelled() { + return false; + } + + public boolean isDone() { + return true; + } + } + + private static final class FileInstrumenter implements Callable<File> { + private final Instrumenter instrumenter; + private final File file; + private final String path; + + protected FileInstrumenter(Instrumenter instrumenter, File file) { + this.instrumenter = instrumenter; + this.file = file; + this.path = file.getPath(); + } + + public File call() throws IOException { + System.err.println(Thread.currentThread() + ":instrumenting " + path); + String prefix = path.substring(0, path.length() - 4); + int slash = prefix.lastIndexOf("/"); + if (slash != -1) prefix = prefix.substring(slash + 1); + prefix += "-"; + File zipTmp = File.createTempFile("instrumented-" + prefix, path.substring(path.length() - 4)); + try { + zipTmp.deleteOnExit(); + ZipInputStream zin = new ZipInputStream(new FileInputStream(file)); + ZipOutputStream zout = new ZipOutputStream(new FileOutputStream(zipTmp)); + ZipEntry entry; + while ((entry = zin.getNextEntry()) != null) { + InputStream in; + long size; + if (entry.getName().endsWith(".class")) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + copy(zin, baos); + byte[] bytes = instrumenter.instrumentClass(baos.toByteArray()); + size = bytes.length; + in = new ByteArrayInputStream(bytes); + } else { + in = zin; + size = entry.getSize(); + } + ZipEntry newEntry = new ZipEntry(entry); + newEntry.setSize(size); + newEntry.setCompressedSize(-1); + zout.putNextEntry(newEntry); + copy(in, zout); + if (entry.getName().endsWith(".class")) { + in.close(); + } + } + zout.close(); + return zipTmp; + } catch (IOException e) { + zipTmp.delete(); + throw e; + } + } + } +} + Propchange: ofbiz/trunk/framework/start/src/org/ofbiz/base/start/InstrumenterWorker.java ('svn:eol-style' removed) Modified: ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestListContainer.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestListContainer.java?rev=1695126&r1=1695125&r2=1695126&view=diff ============================================================================== --- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestListContainer.java (original) +++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestListContainer.java Mon Aug 10 16:15:37 2015 @@ -1,126 +1,126 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.testtools; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.LinkedList; -import java.util.List; - -import org.ofbiz.base.component.ComponentConfig; -import org.ofbiz.base.config.GenericConfigException; -import org.ofbiz.base.config.ResourceHandler; -import org.ofbiz.base.container.Container; -import org.ofbiz.base.container.ContainerException; -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.UtilMisc; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -/** - * A Container implementation to run the tests configured through this testtools stuff. - */ -public class TestListContainer implements Container { - - public static final String module = TestListContainer.class.getName(); - - private String name; - private String outputLocation; - private String mode = "text"; - - public static final class FoundTest { - public final String componentName; - public final String suiteName; - - public FoundTest(String componentName, String suiteName) { - this.componentName = componentName; - this.suiteName = suiteName; - } - } - - @Override - public void init(String[] args, String name, String configFile) { - this.name = name; - this.outputLocation = args[0]; - for (int i = 1; i < args.length; i++) { - if ("-ant".equals(args[i])) { - mode = "ant"; - } else if ("-text".equals(args[i])) { - mode = "text"; - } - } - } - - public boolean start() throws ContainerException { - List<FoundTest> foundTests = new LinkedList<FoundTest>(); - for (ComponentConfig.TestSuiteInfo testSuiteInfo: ComponentConfig.getAllTestSuiteInfos(null)) { - String componentName = testSuiteInfo.getComponentConfig().getComponentName(); - ResourceHandler testSuiteResource = testSuiteInfo.createResourceHandler(); - - try { - Document testSuiteDocument = testSuiteResource.getDocument(); - Element documentElement = testSuiteDocument.getDocumentElement(); - foundTests.add(new FoundTest(componentName, documentElement.getAttribute("suite-name"))); - } catch (GenericConfigException e) { - String errMsg = "Error reading XML document from ResourceHandler for loader [" + testSuiteResource.getLoaderName() + "] and location [" + testSuiteResource.getLocation() + "]"; - Debug.logError(e, errMsg, module); - throw new IllegalArgumentException(errMsg); - } - } - try { - FileOutputStream fout = new FileOutputStream(outputLocation + ".tmp"); - PrintStream pout = new PrintStream(fout); - if ("text".equals(mode)) { - for (FoundTest foundTest: foundTests) { - pout.format("%s:%s\n", foundTest.componentName, foundTest.suiteName); - } - } else if ("ant".equals(mode)) { - pout.println("<project default=\"all-tests\">"); - pout.print(" <target name=\"all-tests\" depends=\""); - for (int i = 0; i < foundTests.size(); i++) { - if (i != 0) pout.print(','); - FoundTest foundTest = foundTests.get(i); - pout.format("%s:%s", foundTest.componentName, foundTest.suiteName); - } - pout.println("\"/>\n"); - for (FoundTest foundTest : foundTests) { - pout.format(" <target name=\"%1$s:%2$s\">\n <ant antfile=\"build.xml\" target=\"run-single-test-suite\">\n <property name=\"test.component\" value=\"%1$s\"/>\n <property name=\"test.suiteName\" value=\"%2$s\"/>\n </ant>\n </target>\n", foundTest.componentName, foundTest.suiteName); - } - pout.println("</project>"); - } - pout.close(); - fout.close(); - new File(outputLocation + ".tmp").renameTo(new File(outputLocation)); - } catch (IOException e) { - Debug.logError(e, module); - throw UtilMisc.initCause(new IllegalArgumentException(e.getMessage()), e); - } - - return true; - } - - public void stop() throws ContainerException { - } - - public String getName() { - return name; - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.testtools; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.LinkedList; +import java.util.List; + +import org.ofbiz.base.component.ComponentConfig; +import org.ofbiz.base.config.GenericConfigException; +import org.ofbiz.base.config.ResourceHandler; +import org.ofbiz.base.container.Container; +import org.ofbiz.base.container.ContainerException; +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilMisc; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * A Container implementation to run the tests configured through this testtools stuff. + */ +public class TestListContainer implements Container { + + public static final String module = TestListContainer.class.getName(); + + private String name; + private String outputLocation; + private String mode = "text"; + + public static final class FoundTest { + public final String componentName; + public final String suiteName; + + public FoundTest(String componentName, String suiteName) { + this.componentName = componentName; + this.suiteName = suiteName; + } + } + + @Override + public void init(String[] args, String name, String configFile) { + this.name = name; + this.outputLocation = args[0]; + for (int i = 1; i < args.length; i++) { + if ("-ant".equals(args[i])) { + mode = "ant"; + } else if ("-text".equals(args[i])) { + mode = "text"; + } + } + } + + public boolean start() throws ContainerException { + List<FoundTest> foundTests = new LinkedList<FoundTest>(); + for (ComponentConfig.TestSuiteInfo testSuiteInfo: ComponentConfig.getAllTestSuiteInfos(null)) { + String componentName = testSuiteInfo.getComponentConfig().getComponentName(); + ResourceHandler testSuiteResource = testSuiteInfo.createResourceHandler(); + + try { + Document testSuiteDocument = testSuiteResource.getDocument(); + Element documentElement = testSuiteDocument.getDocumentElement(); + foundTests.add(new FoundTest(componentName, documentElement.getAttribute("suite-name"))); + } catch (GenericConfigException e) { + String errMsg = "Error reading XML document from ResourceHandler for loader [" + testSuiteResource.getLoaderName() + "] and location [" + testSuiteResource.getLocation() + "]"; + Debug.logError(e, errMsg, module); + throw new IllegalArgumentException(errMsg); + } + } + try { + FileOutputStream fout = new FileOutputStream(outputLocation + ".tmp"); + PrintStream pout = new PrintStream(fout); + if ("text".equals(mode)) { + for (FoundTest foundTest: foundTests) { + pout.format("%s:%s\n", foundTest.componentName, foundTest.suiteName); + } + } else if ("ant".equals(mode)) { + pout.println("<project default=\"all-tests\">"); + pout.print(" <target name=\"all-tests\" depends=\""); + for (int i = 0; i < foundTests.size(); i++) { + if (i != 0) pout.print(','); + FoundTest foundTest = foundTests.get(i); + pout.format("%s:%s", foundTest.componentName, foundTest.suiteName); + } + pout.println("\"/>\n"); + for (FoundTest foundTest : foundTests) { + pout.format(" <target name=\"%1$s:%2$s\">\n <ant antfile=\"build.xml\" target=\"run-single-test-suite\">\n <property name=\"test.component\" value=\"%1$s\"/>\n <property name=\"test.suiteName\" value=\"%2$s\"/>\n </ant>\n </target>\n", foundTest.componentName, foundTest.suiteName); + } + pout.println("</project>"); + } + pout.close(); + fout.close(); + new File(outputLocation + ".tmp").renameTo(new File(outputLocation)); + } catch (IOException e) { + Debug.logError(e, module); + throw UtilMisc.initCause(new IllegalArgumentException(e.getMessage()), e); + } + + return true; + } + + public void stop() throws ContainerException { + } + + public String getName() { + return name; + } +} Propchange: ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestListContainer.java ('svn:eol-style' removed) |
Free forum by Nabble | Edit this page |