JAVA-18764: Changes made for updating the pkg

This commit is contained in:
Bipinkumar27 2023-10-19 19:33:27 +05:30
parent c8bc9634d5
commit 1071a07170
5 changed files with 29 additions and 37 deletions

View File

@ -1,30 +1,21 @@
package com.baeldung.cassecuredapp;
import org.jasig.cas.client.session.SingleSignOutFilter;
import org.jasig.cas.client.session.SingleSignOutHttpSessionListener;
import org.jasig.cas.client.validation.Cas30ServiceTicketValidator;
import org.jasig.cas.client.validation.TicketValidator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.context.event.EventListener;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.cas.ServiceProperties;
import org.springframework.security.cas.authentication.CasAuthenticationProvider;
import org.springframework.security.cas.web.CasAuthenticationEntryPoint;
import org.springframework.security.cas.web.CasAuthenticationFilter;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
import org.springframework.security.web.authentication.logout.LogoutFilter;
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
import javax.servlet.http.HttpSessionEvent;
import com.baeldung.cassecuredapp.service.CasUserDetailsService;
@SpringBootApplication
public class CasSecuredApplication {
@ -61,8 +52,8 @@ public class CasSecuredApplication {
}
@Bean
public MyUserDetailsService getUser(){
return new MyUserDetailsService();
public CasUserDetailsService getUser(){
return new CasUserDetailsService();
}
@Bean
public CasAuthenticationProvider casAuthenticationProvider(

View File

@ -1,15 +0,0 @@
package com.baeldung.cassecuredapp;
import java.util.Optional;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
@Repository
public interface UserRepository extends CrudRepository<Users, Long> {
Users findByEmail(@Param("email") String email);
}

View File

@ -1,15 +1,17 @@
package com.baeldung.cassecuredapp;
package com.baeldung.cassecuredapp.service;
import java.util.Collections;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
public class MyUserDetailsService implements UserDetailsService {
import com.baeldung.cassecuredapp.user.User;
import com.baeldung.cassecuredapp.user.UserRepository;
public class CasUserDetailsService implements UserDetailsService {
@Autowired
private UserRepository userRepository;
@ -17,18 +19,18 @@ public class MyUserDetailsService implements UserDetailsService {
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
// Get the user from the database.
Users users = getUserFromDatabase(username);
User user = getUserFromDatabase(username);
// Create a UserDetails object.
UserDetails userDetails = new User(
users.getEmail(),
users.getPassword(),
UserDetails userDetails = new org.springframework.security.core.userdetails.User(
user.getEmail(),
user.getPassword(),
Collections.singletonList(new SimpleGrantedAuthority("ROLE_ADMIN")));
return userDetails;
}
private Users getUserFromDatabase(String username) {
private User getUserFromDatabase(String username) {
return userRepository.findByEmail(username);
}
}

View File

@ -1,11 +1,11 @@
package com.baeldung.cassecuredapp;
package com.baeldung.cassecuredapp.user;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class Users {
public class User {
@Id
private Long id;

View File

@ -0,0 +1,14 @@
package com.baeldung.cassecuredapp.user;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import com.baeldung.cassecuredapp.user.User;
@Repository
public interface UserRepository extends CrudRepository<User, Long> {
User findByEmail(@Param("email") String email);
}