List of usage examples for org.apache.shiro.authc UsernamePasswordToken UsernamePasswordToken
public UsernamePasswordToken()
From source file:ch.bastiangardel.easypay.dto.CredentialDTO.java
License:Open Source License
public UsernamePasswordToken daoToModel(String host) { UsernamePasswordToken tmp = new UsernamePasswordToken(); tmp.setHost(host);/*from w w w . j a va2 s . c o m*/ tmp.setRememberMe(false); if (password != null) tmp.setPassword(password.toCharArray()); else tmp.setPassword(null); tmp.setUsername(username); return tmp; }
From source file:com.glaf.shiro.ShiroSecurity.java
License:Apache License
public static void login(String actorId, String password) { logger.info("login user:" + actorId); Subject currentUser = SecurityUtils.getSubject(); try {/*w ww . ja va 2 s . c o m*/ UsernamePasswordToken token = new UsernamePasswordToken(); token.setUsername(actorId); token.setPassword(actorId.toCharArray()); token.setRememberMe(false); Session session = currentUser.getSession(); session.setAttribute(Constants.LOGIN_ACTORID, actorId); currentUser.login(token); logger.info("User [" + currentUser.getPrincipal() + "] logged in successfully."); } catch (Exception ex) { ex.printStackTrace(); logger.error(ex); } }
From source file:com.ikanow.aleph2.security.service.SecurityServiceTest.java
License:Apache License
@Test @Ignore/*from w w w . ja v a 2s . c o m*/ public void testSecondRealm() { String role = "admin"; UsernamePasswordToken token = new UsernamePasswordToken(); token.setRememberMe(true); ISubject subject = securityService.login("trojan", "none"); assertEquals(true, securityService.hasRole(subject, role)); }
From source file:com.tensorwrench.shiro.realm.MongoUserPasswordRealmAuthenticationTest.java
License:Apache License
@Test public void supportsPassword() { assertTrue(realm.supports(new UsernamePasswordToken()), "Realm should support usernames and passwords."); }
From source file:org.opendaylight.aaa.shiro.filters.AuthenticationListenerTest.java
License:Open Source License
@Test public void testOnSuccess() throws Exception { // sets up a successful authentication attempt final AuthenticationListener authenticationListener = new AuthenticationListener(); final UsernamePasswordToken authenticationToken = new UsernamePasswordToken(); authenticationToken.setUsername("successfulUser1"); authenticationToken.setHost("successfulHost1"); final SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo(); // the following call produces accounting output authenticationListener.onSuccess(authenticationToken, simpleAuthenticationInfo); // grab the latest log output and make sure it is in line with what is expected final List<LoggingEvent> loggingEvents = TestAppender.getCurrentInstance().getEvents(); // the latest logging event is the one we need to inspect final int whichLoggingEvent = loggingEvents.size() - 1; final LoggingEvent latestLoggingEvent = loggingEvents.get(whichLoggingEvent); final String latestLogMessage = latestLoggingEvent.getMessage(); assertEquals("Successful authentication attempt by successfulUser1 from successfulHost1", latestLogMessage); }
From source file:org.opendaylight.aaa.shiro.filters.AuthenticationListenerTest.java
License:Open Source License
@Test public void testOnFailure() throws Exception { // variables for an unsucessful authentication attempt final AuthenticationListener authenticationListener = new AuthenticationListener(); final UsernamePasswordToken authenticationToken = new UsernamePasswordToken(); authenticationToken.setUsername("unsuccessfulUser1"); authenticationToken.setHost("unsuccessfulHost1"); final AuthenticationException authenticationException = new AuthenticationException("test auth exception"); // produces unsuccessful authentication attempt output authenticationListener.onFailure(authenticationToken, authenticationException); // grab the latest log output and ensure it is in line with what is expected final List<LoggingEvent> loggingEvents = TestAppender.getCurrentInstance().getEvents(); final int whichLoggingEvent = loggingEvents.size() - 1; final LoggingEvent latestLoggingEvent = loggingEvents.get(whichLoggingEvent); final String latestLogMessage = latestLoggingEvent.getMessage(); assertEquals("Unsuccessful authentication attempt by unsuccessfulUser1 from unsuccessfulHost1", latestLogMessage);/*from www . j a v a2 s . c o m*/ }
From source file:org.opendaylight.aaa.shiro.filters.AuthenticationTokenUtilsTest.java
License:Open Source License
@Test public void testIsUsernamePasswordToken() throws Exception { // null test/*from w w w . j a v a 2 s .c o m*/ final AuthenticationToken nullUsernamePasswordToken = null; assertFalse(AuthenticationTokenUtils.isUsernamePasswordToken(nullUsernamePasswordToken)); // alternate implementation of AuthenticationToken final AuthenticationToken notUsernamePasswordToken = new NotUsernamePasswordToken(); assertFalse(AuthenticationTokenUtils.isUsernamePasswordToken(notUsernamePasswordToken)); // positive test case final AuthenticationToken positiveUsernamePasswordToken = new UsernamePasswordToken(); assertTrue(AuthenticationTokenUtils.isUsernamePasswordToken(positiveUsernamePasswordToken)); }
From source file:org.opendaylight.aaa.shiro.filters.AuthenticationTokenUtilsTest.java
License:Open Source License
@Test public void testExtractUsername() throws Exception { // null test// ww w . ja va 2 s.c o m final AuthenticationToken nullAuthenticationToken = null; assertEquals(AuthenticationTokenUtils.DEFAULT_TOKEN, AuthenticationTokenUtils.extractUsername(nullAuthenticationToken)); // non-UsernamePasswordToken test final AuthenticationToken notUsernamePasswordToken = new NotUsernamePasswordToken(); assertEquals(AuthenticationTokenUtils.DEFAULT_TOKEN, AuthenticationTokenUtils.extractUsername(notUsernamePasswordToken)); // null username test final UsernamePasswordToken nullUsername = new UsernamePasswordToken(); nullUsername.setUsername(null); assertEquals(AuthenticationTokenUtils.DEFAULT_USERNAME, AuthenticationTokenUtils.extractUsername(nullUsername)); // positive test final UsernamePasswordToken positiveUsernamePasswordToken = new UsernamePasswordToken(); final String testUsername = "testUser1"; positiveUsernamePasswordToken.setUsername(testUsername); assertEquals(testUsername, AuthenticationTokenUtils.extractUsername(positiveUsernamePasswordToken)); }
From source file:org.opendaylight.aaa.shiro.filters.AuthenticationTokenUtilsTest.java
License:Open Source License
@Test public void testExtractHostname() throws Exception { // null test/*w ww . j a v a 2s . co m*/ final AuthenticationToken nullAuthenticationToken = null; assertEquals(AuthenticationTokenUtils.DEFAULT_HOSTNAME, AuthenticationTokenUtils.extractHostname(nullAuthenticationToken)); // non-UsernamePasswordToken test final AuthenticationToken notUsernamePasswordToken = new NotUsernamePasswordToken(); assertEquals(AuthenticationTokenUtils.DEFAULT_HOSTNAME, AuthenticationTokenUtils.extractHostname(notUsernamePasswordToken)); // null hostname test final UsernamePasswordToken nullHostname = new UsernamePasswordToken(); nullHostname.setHost(null); assertEquals(AuthenticationTokenUtils.DEFAULT_HOSTNAME, AuthenticationTokenUtils.extractHostname(nullHostname)); // positive test final UsernamePasswordToken positiveUsernamePasswordToken = new UsernamePasswordToken(); final String testUsername = "testHostname1"; positiveUsernamePasswordToken.setHost(testUsername); assertEquals(testUsername, AuthenticationTokenUtils.extractHostname(positiveUsernamePasswordToken)); }
From source file:org.opendaylight.aaa.shiro.filters.AuthenticationTokenUtilsTest.java
License:Open Source License
@Test public void testGenerateUnsuccessfulAuthenticationMessage() throws Exception { final UsernamePasswordToken unsuccessfulToken = new UsernamePasswordToken(); unsuccessfulToken.setUsername("unsuccessfulUser1"); unsuccessfulToken.setHost("unsuccessfulHost1"); assertEquals("Unsuccessful authentication attempt by unsuccessfulUser1 from unsuccessfulHost1", AuthenticationTokenUtils.generateUnsuccessfulAuthenticationMessage(unsuccessfulToken)); }