BAEL-4019: Added logger to log exceptions
This commit is contained in:
parent
bd617e9cae
commit
6c6dc6b159
|
@ -19,8 +19,12 @@ import org.apache.shiro.authz.AuthorizationInfo;
|
|||
import org.apache.shiro.authz.SimpleAuthorizationInfo;
|
||||
import org.apache.shiro.realm.jdbc.JdbcRealm;
|
||||
import org.apache.shiro.subject.PrincipalCollection;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class CustomRealm extends JdbcRealm {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(CustomRealm.class);
|
||||
|
||||
private Map<String, String> credentials = new HashMap<>();
|
||||
private Map<String, Set<String>> roles = new HashMap<>();
|
||||
|
@ -60,7 +64,7 @@ public class CustomRealm extends JdbcRealm {
|
|||
roles.addAll(getRoleNamesForUser(null, (String) user));
|
||||
permissions.addAll(getPermissions(null, null, roles));
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
SimpleAuthorizationInfo authInfo = new SimpleAuthorizationInfo(roles);
|
||||
|
|
|
@ -6,6 +6,8 @@ import org.apache.shiro.SecurityUtils;
|
|||
import org.apache.shiro.authc.AuthenticationException;
|
||||
import org.apache.shiro.authc.UsernamePasswordToken;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
@ -16,6 +18,8 @@ import com.baeldung.shiro.models.UserCredentials;
|
|||
|
||||
@Controller
|
||||
public class ShiroController {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(ShiroController.class);
|
||||
|
||||
@GetMapping("/")
|
||||
public String index() {
|
||||
|
@ -37,7 +41,7 @@ public class ShiroController {
|
|||
try {
|
||||
subject.login(token);
|
||||
} catch (AuthenticationException ae) {
|
||||
ae.printStackTrace();
|
||||
logger.error(ae.getMessage());
|
||||
attr.addFlashAttribute("error", "Invalid Credentials");
|
||||
return "redirect:/login";
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue