本文整理汇总了Java中org.owasp.esapi.errors.AuthenticationException.printStackTrace方法的典型用法代码示例。如果您正苦于以下问题:Java AuthenticationException.printStackTrace方法的具体用法?Java AuthenticationException.printStackTrace怎么用?Java AuthenticationException.printStackTrace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.owasp.esapi.errors.AuthenticationException
的用法示例。
在下文中一共展示了AuthenticationException.printStackTrace方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createUser
import org.owasp.esapi.errors.AuthenticationException; //导入方法依赖的package包/类
public String createUser(){
FileBasedAuthenticator auth = (FileBasedAuthenticator)FileBasedAuthenticator.getInstance();
/*if (input4 != input5){
System.out.println("Please enter same password!");
return "register";
}else{*/
try {
auth.createUser(input1, input4, input5);
System.out.println(auth.getUser(input1).getAccountId());
auth.getUser(auth.getUser(input1).getAccountId()).addRole("admin");
auth.getUser(auth.getUser(input1).getAccountId()).enable();
auth.getUser(auth.getUser(input1).getAccountId()).unlock();
System.out.println("getrole :"+auth.getUser(auth.getUser(input1).getAccountId()).getRoles());
} catch (AuthenticationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "userregistered";
}
示例2: testSetCurrentUser
import org.owasp.esapi.errors.AuthenticationException; //导入方法依赖的package包/类
/**
* Test of setCurrentUser method, of class org.owasp.esapi.Authenticator.
*
* @throws AuthenticationException
* the authentication exception
*/
public void testSetCurrentUser() throws AuthenticationException {
System.out.println("setCurrentUser");
final Authenticator instance = ESAPI.authenticator();
String user1 = ESAPI.randomizer().getRandomString(8, EncoderConstants.CHAR_UPPERS);
String user2 = ESAPI.randomizer().getRandomString(8, EncoderConstants.CHAR_UPPERS);
User userOne = instance.createUser(user1, "getCurrentUser", "getCurrentUser");
userOne.enable();
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
ESAPI.httpUtilities().setCurrentHTTP(request, response);
userOne.loginWithPassword("getCurrentUser");
User currentUser = instance.getCurrentUser();
assertEquals( currentUser, userOne );
User userTwo = instance.createUser(user2, "getCurrentUser", "getCurrentUser");
instance.setCurrentUser( userTwo );
assertFalse( currentUser.getAccountName().equals( userTwo.getAccountName() ) );
Runnable echo = new Runnable() {
private int count = 1;
public void run() {
User u=null;
try {
String password = ESAPI.randomizer().getRandomString(8, EncoderConstants.CHAR_ALPHANUMERICS);
u = instance.createUser("test" + count++, password, password);
instance.setCurrentUser(u);
ESAPI.getLogger("test").info( Logger.SECURITY_SUCCESS, "Got current user" );
// ESAPI.authenticator().removeUser( u.getAccountName() );
} catch (AuthenticationException e) {
e.printStackTrace();
}
}
};
for ( int i = 0; i<10; i++ ) {
new Thread( echo ).start();
}
}
示例3: main
import org.owasp.esapi.errors.AuthenticationException; //导入方法依赖的package包/类
public static void main (String[] args){
FileBasedAuthenticator auth = (FileBasedAuthenticator)FileBasedAuthenticator.getInstance();
try {
auth.createUser("admin", "Test1234", "Test1234");
System.out.println(auth.getUser("admin").getAccountId());
auth.getUser(auth.getUser("admin").getAccountId()).addRole("admin");
auth.getUser(auth.getUser("admin").getAccountId()).enable();
auth.getUser(auth.getUser("admin").getAccountId()).unlock();
System.out.println("getrole :"+auth.getUser(auth.getUser("admin").getAccountId()).getRoles());
auth.createUser("user", "Test12345", "Test12345");
System.out.println(auth.getUser("user").getAccountId());
auth.getUser(auth.getUser("user").getAccountId()).addRole("user");
auth.getUser(auth.getUser("user").getAccountId()).enable();
auth.getUser(auth.getUser("user").getAccountId()).unlock();
System.out.println("getrole :"+auth.getUser(auth.getUser("user").getAccountId()).getRoles());
} catch (AuthenticationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例4: testGetCurrentUser
import org.owasp.esapi.errors.AuthenticationException; //导入方法依赖的package包/类
/**
* Test of getCurrentUser method, of class org.owasp.esapi.Authenticator.
*
*
* @throws Exception
*/
public void testGetCurrentUser() throws Exception {
System.out.println("getCurrentUser");
Authenticator instance = ESAPI.authenticator();
String username1 = ESAPI.randomizer().getRandomString(8, EncoderConstants.CHAR_ALPHANUMERICS);
String username2 = ESAPI.randomizer().getRandomString(8, EncoderConstants.CHAR_ALPHANUMERICS);
User user1 = instance.createUser(username1, "getCurrentUser", "getCurrentUser");
User user2 = instance.createUser(username2, "getCurrentUser", "getCurrentUser");
user1.enable();
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
ESAPI.httpUtilities().setCurrentHTTP(request, response);
user1.loginWithPassword("getCurrentUser");
User currentUser = instance.getCurrentUser();
assertEquals( currentUser, user1 );
instance.setCurrentUser( user2 );
assertFalse( currentUser.getAccountName().equals( user2.getAccountName() ) );
Runnable echo = new Runnable() {
private int count = 1;
private boolean result = false;
public void run() {
Authenticator auth = ESAPI.authenticator();
User a = null;
try {
String password = auth.generateStrongPassword();
String accountName = "TestAccount" + count++;
a = auth.getUser(accountName);
if ( a != null ) {
auth.removeUser(accountName);
}
a = auth.createUser(accountName, password, password);
auth.setCurrentUser(a);
} catch (AuthenticationException e) {
e.printStackTrace();
}
User b = auth.getCurrentUser();
result &= a.equals(b);
}
};
ThreadGroup tg = new ThreadGroup("test");
for ( int i = 0; i<10; i++ ) {
new Thread( tg, echo ).start();
}
while (tg.activeCount() > 0 ) {
Thread.sleep(100);
}
}