我有一个使用spring安全性的spring启动应用程序所以在我的情况下我有两种类型的用户一个ADMIN,一个简单的用户我从Datasource获取数据然后我执行一个Query,我的问题是重定向我对每个用户一个不同的主页我想使用AthenticationSuccessHandler,但它不会工作请帮助这是我的代码;
我的Spring安全类配置:
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
import javax.sql.DataSource;
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
Securityhandler successHandler;
// Pour l'authentification des Utilisateur de Table Utilisateur
@Autowired
public void GlobalConfig(AuthenticationManagerBuilder auth,DataSource dataSource) throws Exception {
auth.jdbcAuthentication()
.dataSource(dataSource)
.usersByUsernameQuery("SELECT \"Pseudo\" AS principal , \"Password\" AS credentials , true FROM \"UTILISATEUR\" WHERE \"Pseudo\" = ? ")
.authoritiesByUsernameQuery("SELECT u.\"Pseudo\" AS principal , r.role as role …Run Code Online (Sandbox Code Playgroud) 我在Postgresql中有一个表:
CREATE TABLE "UTILISATEUR"(
"IdUtilisateur" serial NOT NULL,
"Nom" character varying(50),
"Prenom" character varying(50),
"Profil" character varying(50),
"Pseudo" character varying(20),
"IdSite" integer DEFAULT 0,
"Password" character varying(1024),
id_role integer,
)
Run Code Online (Sandbox Code Playgroud)
我在这张桌子上尝试Map所以我使用了@TableJPA注释(见下文).这是我的application.propreties:
spring.datasource.url = jdbc:postgresql://localhost/baseecu
spring.datasource.username = postgres
spring.datasource.password =root
spring.datasource.driverClassName=org.postgresql.Driver
spring.jpa.database = MYSQL
spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
Run Code Online (Sandbox Code Playgroud)
最后这是我的实体类:
@Entity
@Table(name="UTILISATEUR")
public class Utilisateur {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="IdUtilisateur")
public Long id ;
public String Nom ;
public String Prenom ;
public …Run Code Online (Sandbox Code Playgroud) 我试图插入一个格式如下的对象:
$scope.newObj = {1: "N/A", 2: "KO", 3: "OK", 4: "OK", 5: "OK", 15: "N/A", 19: "OK"}
Run Code Online (Sandbox Code Playgroud)
我尝试使用以下for循环:
var objt = $scope.newObject;
console.log($scope.newObject[0]) // undefined
for(i=0;i<$scope.newObj.length;i++)
{
$http.post("insert?etat="+$scope.newObject[0]+"&id="+Object.keys(objt))
}
Run Code Online (Sandbox Code Playgroud)
但它似乎没有用.我undefined到处都是.有没有人知道如何逐行从该对象检索数据然后将值插入服务?
大家好我试图@Query在我的春季启动应用程序中使用注释在表中插入数据我得到一个postgres例外:
org.postgresql.util.PSQLException: No results returned by the query
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
这是存储库
@Query(value="INSERT INTO \"FCT_BY_DEV\"(\"IdDev\", \"IdFonction\") VALUES (?, ?) ",nativeQuery=true)
public String isertfonctionstodev(int dev,int fonction);
Run Code Online (Sandbox Code Playgroud)
这是控制器:
@RequestMapping(value="/function/insert", method = RequestMethod.POST)
public String insererfonctions (int dev,int fonction){
System.out.println("dev="+dev+"fonction="+fonction);
fonctionRepository.isertfonctionstodev(dev, fonction);
System.out.println("********");
return "aaa";
}
Run Code Online (Sandbox Code Playgroud)
我在angularJs中使用$ http的这项服务
$http.post("/function/insert?dev="+$scope.id+"&fonction="+$scope.idf);
Run Code Online (Sandbox Code Playgroud)
最后这是服务器日志
dev=16006fonction=14
Hibernate: INSERT INTO "FCT_BY_DEV"("IdDev", "IdFonction") VALUES (?, ?)
2016-04-27 16:52:03.204 WARN 7036 --- [nio-8080-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: 02000
2016-04-27 16:52:03.204 ERROR 7036 --- [nio-8080-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper : Aucun résultat retourné …Run Code Online (Sandbox Code Playgroud) 我在Spring Boot应用程序中使用Spring Security,我想从当前登录的用户中获取,Principal#getName但我有模板解析错误,它包含我想要的用户名.
这是我的控制器:
import java.security.Principal;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class PageController {
@RequestMapping(value = "/api/loggeduser", method = RequestMethod.GET)
public String printWelcome(ModelMap model, Principal principal) {
String name = null;
if (principal !=null) {
name = principal.getName();
}
model.addAttribute("username", name);
return name;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的AngularJs函数来获取登录用户:
app.controller('Usercontr', function($scope, $http) {
$http.get("/api/loggeduser").success(function (data) {
$scope.nom = data;
console.log($scope.nom)
})
});
Run Code Online (Sandbox Code Playgroud)
这是错误:
解析模板"kamel.mili"时出错,模板可能不存在或任何已配置的模板解析器可能无法访问
Kamel.mili是登录的用户名.你能帮我么.我只使用百万美元登录页面,其他一切都是html + AngularJs.我不知道为什么百老汇会把它放在这个控制器上.
大家好,我有一个 Spring Boot 应用程序,我正在尝试执行查询,但出现此错误
illegal attempt to dereference collection [dev0_."IdDev".vehid] with element property reference [marque] [SELECT DISTINCT d FROM com.ardia.MDValidation.entities.Dev d Left Join d.validationdvd v WHERE d.etatdev.id = 6 AND d.vehid.marque.Nommarque= ?]
Run Code Online (Sandbox Code Playgroud)
这是我的开发班
@Entity
@Table(name="\"DEV\"")
public class Dev {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@JsonView(View.databymaj.class)
@Column(name="\"IdDev\"")
private int id ;
@JsonView(View.databymaj.class)
@Column(name="\"NomDev\"")
private String nomdev;
@Column(name="\"NomDLL\"")
private String dll ;
@ManyToOne(fetch=FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name="\"IdEtatDev\"")
private EtatDev etatdev ;
@JsonView(View.databymaj.class)
@ManyToOne(fetch=FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name="\"IdEcu\"")
private Ecu ecu ;
@ManyToMany(fetch=FetchType.EAGER)
@JoinTable(name="\"VEH_BY_DEV\""
,joinColumns={@JoinColumn(name="\"IdDev\"")},
inverseJoinColumns={@JoinColumn(name="\"GRPMOD\"")}) …Run Code Online (Sandbox Code Playgroud) 我一直面临着一个问题Omnifaces 2.1。
我byte[]在我的数据库中存储了一个图像类型,其中包含一个声明 java 类,如下所示:
@Lob
private byte[] image;
Run Code Online (Sandbox Code Playgroud)
在我的 xhtml 文件中,我在一个包含图像的类上有一个循环:
<ui:repeat var="listT" value="#{eventBean.listEvents}">
<o:graphicImage value="#{eventBean.getImage(listT.idEvent)}" dataURI="true" />
</ui:repeat>
Run Code Online (Sandbox Code Playgroud)
现在bean我尝试实现getImage()omnifaces文档中提到的功能:
@ManagedBean
@ViewScoped
public class EventBean implements Serializable {
private static final long serialVersionUID = 1L;
@EJB
private EventServiceLocal eventServiceLocal;
private Event event = new Event();
private List<Event> listEvents;
private List<Event> listEventsval;
private static Event eventSt;
private UploadedFile file;
public byte[] getImage(int eventID) {
return eventServiceLocal.listEventspicture(eventID);
}
Run Code Online (Sandbox Code Playgroud)
当我执行这个时,我没有图像,当我检查元素时,我得到了这个结果:
<o:graphicimage value="[B@1aeef88" datauri="true"></o:graphicimage>
Run Code Online (Sandbox Code Playgroud) spring-boot ×5
angularjs ×2
hibernate ×2
java ×2
jpa ×2
postgresql ×2
spring ×2
javascript ×1
jsf ×1
omnifaces ×1