How can we access the java security package in Jmeter? - jmeter

I need to access the security package in Java using Jmeter on Bean Shell. Is there anyway to do this ?
I have got error like this.
Sourced file: inline evaluation of: ``import android.util.Base64.*; import java.security.spec.X509EncodedKeySpec;
Help on this is useful!

I suspect the problem is with import android.util.Base64.* - android package is not part of Java. You probably meant to have
import java.util.Base64;
Note that you need to have Java 8

Related

Spring security test with user

At https://docs.spring.io/spring-security/site/docs/4.0.4.RELEASE/reference/html/test-mockmvc.html
I see test example
mvc.perform(get("/admin").with(user("admin").password("pass")...
What imports I have to perform for using
user("admin")
and
password("pass")
ok, don't bother it is
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.*;

missing dependencies in latest spring security test

I need to resolve certain methods (status, jsonPath, content) mentioned in code shown below -
mockMvc.perform(MockMvcRequestBuilders.get("/api/token")
.with(getAuthentication(getOauthTestAuthentication()))
.sessionAttr("scopedTarget.oauth2ClientContext", getOauth2ClientContext()))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$.username").value("cominventor"))
.andExpect(jsonPath("$.token").value("my-fun-token"));
When I searched for related projects containing these methods, many of them are importing the following
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
The problem is that I am unable to find a counterpart in package spring-security-test with version 4.2.2.RELEASE
The closest options that could have worked but haven't are
import static org.springframework.test.web.servlet.ResultMatcher.*;
import static org.springframework.security.test.web.servlet.response.SecurityMockMvcResultMatchers.*;
The above don't contain the methods I am looking for. Any idea where should I look for these methods or their newer counterparts.
Everything worked out once I set the spring-security-test version to 4.0.2.RELEASE
I had the same problem, and I solved it importing the artifact
org.springframework.security:spring-security-test:4.2.3.RELEASE
I am using spring-boot-starter-test:1.5.3, and for some reason the folks at Spring decided not to include spring-security-test in its POM.

Class.forName(Driver.class)

In context of making a database Connection, we normally import the required packages and use Class.forName() to load the required Driver classes by the classloader of the calling class.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
....
....
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection(...);
Can not we simply drop off the Class.forName() as in this:-
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import com.mysql.jdbc.*;
....
....
Connection con=DriverManager.getConnection(...);
My question is when the dependencies of a class are loaded by the same classloader that loaded the dependent class, by the same mechanism used with Class.forName(className) implicitly, the why to give Class.forName() explicitly. Just include the driver class in import statement.
Will the driver class not automatically loaded when it incounters the DriverManager.getConnection() line? com.mysql.jdbc package is in import statement.
Or do i need to add al line like
Class clazz=com.mysq.jdbc.Driver.class
to trigger the Class.forName() .
First, loading the driver class shouldn't be necessary anymore, because Java has a built-in service provider loading mechanism that looks in the jar files in the classpath to find available drivers.
Just importing a class is not sufficient to load it. All an import does is allow you, at compile time, to refer to the class using its simple name rather than its fully qualified name. But if you never actually load the class, it won't do anything.
You could indeed load the class without using reflection, but that means that you need to have tthe driver as a compile-time dependency, which is often unwanted: you shouldn't rely on database-specific classes from the driver, but only on standard JDBC interfaces. Not having the driver in the compile classpath makes that sure.
An import statement does not do anything at run-time. It is not even part of the compiled class. It just tells the compiler where to look for stuff.
A line like Class<?> dummy = com.mysql.jdbc.Driver.class will work, but then you have a compile-time dependency on the MySQL driver JAR file (which Class.forName does not have, but may not be a bad thing in the grand scheme of things).
As long as your driver is JDBC 4.0 compliant, you don't need the Class.forName().
Please read the introduction on DriverManager JavaDoc for how this has been handled.
Of cause, the driver still needs to be on the classpath. Which was true for Class.forName() as well (would've thrown ClassNotFoundException otherwise)

liferay event listener

i have some hard task, i need to change some part of my project using jboss portal 2.7.2 into liferay. Ofc less change better but all jboss portal must disappear. I need 2 replace classes below. So my question is how using liferay portal implements(or not(if already exist)) listener which will know when someone is trying 2 log in. Make login possible without reloading etc. Ofc it was nice if there was some pro eventlistener in liferay which can recognise other events not only logging but i will be glad for all help. 4 the rest of this class will be nice if someone know replacment 4 them in liferay.
import org.jboss.portal.api.event.PortalEvent;
import org.jboss.portal.api.event.PortalEventContext;
import org.jboss.portal.api.event.PortalEventListener;
import org.jboss.portal.api.session.PortalSession;
import org.jboss.portal.api.user.event.UserAuthenticationEvent;
import org.jboss.portal.identity.IdentityException;
import org.jboss.portal.identity.NoSuchUserException;
import org.jboss.portal.identity.User;
import org.jboss.portal.identity.UserModule;
import org.jboss.portal.identity.UserProfileModule;
Liferay has similar approache. Create a Hook and add properties like http://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/extending-and-overriding-%3Cem%3Eportal-properties%3C-e-1
With the properties you can specificy wich class schould be call by the portal events:
login.events.post=my.package.AfterLoginHandler
with the same approche you can listen to creating/changes/removes of entities:
value.object.listener.com.liferay.portal.model.User=my.package.UserListener
value.object.listener.com.liferay.portal.model.Layout=my.package.LayoutListener
...
Liferay does allow adding handlers to login events. More information can be found # http://www.learnercorner.in/topics?showTopic=16001

Log Output in DBUnit

I feel that this is something I could easily figure out but I'm having a hard time finding information on how to change the log level of DBUnit. Can anyone solve this problem for me?
After avoiding the problem for a while, I came to a solution.
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.core.util.StatusPrinter;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
Logger logger = (Logger)LoggerFactory.getLogger("org.dbunit")
logger.setLevel(Level. ERROR);
Hopefully this lead someone to a solution to their own similar problem.
When using log4j add the following to your log4j.properties:
# DbUnit
log4j.logger.org.dbunit=ERROR
When using Spring Boot, you may simply add the following property to your application.properties:
logging.level.org.dbunit: ERROR

Resources