Last active
December 16, 2015 03:39
-
-
Save tk120404/5371054 to your computer and use it in GitHub Desktop.
Enabling the mysql bcrypt for cas
Update the cas.properties file of cas-server-webapp Update the pom file of the cas-server-support-jdbc
Add BCryptSearchModeSearchDatabaseAuthenticationHandler.java to cas-server-support-jdbc
Update the deployerConfigContext.xml of cas-server-webapp
Update the pom file of the cas-server-webapp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.jasig.cas.adaptors.jdbc; | |
import org.jasig.cas.authentication.principal.UsernamePasswordCredentials; | |
import org.springframework.security.crypto.bcrypt.BCrypt; | |
import org.springframework.beans.factory.InitializingBean; | |
import org.jasig.cas.adaptors.jdbc.AbstractJdbcUsernamePasswordAuthenticationHandler; | |
public class BCryptSearchModeSearchDatabaseAuthenticationHandler extends | |
AbstractJdbcUsernamePasswordAuthenticationHandler implements InitializingBean { | |
private String fieldUser; | |
private String fieldPassword; | |
private String tableUsers; | |
private String sql; | |
public boolean authenticateUsernamePasswordInternal(UsernamePasswordCredentials credentials) { | |
final String username = getPrincipalNameTransformer().transform(credentials.getUsername()); | |
final String plainTextPassword = credentials.getPassword(); | |
final String encryptedPassword = getJdbcTemplate().queryForObject(sql, String.class, username); | |
return isPasswordValid(plainTextPassword, encryptedPassword); | |
} | |
public void afterPropertiesSet() throws Exception { | |
sql = "select " + fieldPassword + " from " + | |
tableUsers + " where " + fieldUser + " = ?"; | |
} | |
private boolean isPasswordValid(String plainTextPassword, String encryptedPassword) { | |
if(plainTextPassword == null || plainTextPassword.trim().length() == 0 || | |
encryptedPassword == null || encryptedPassword.trim().length() == 0) { | |
return false; | |
} | |
return BCrypt.checkpw(plainTextPassword, encryptedPassword); | |
} | |
/** | |
* @param fieldPassword The name of the encrypted password field. | |
*/ | |
public final void setFieldPassword(final String fieldPassword) { | |
this.fieldPassword = fieldPassword; | |
} | |
/** | |
* @param fieldUser The name of the username field. | |
*/ | |
public final void setFieldUser(final String fieldUser) { | |
this.fieldUser = fieldUser; | |
} | |
/** | |
* @param tableUsers The name of the table holding the user information. | |
*/ | |
public final void setTableUsers(final String tableUsers) { | |
this.tableUsers = tableUsers; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Licensed to Jasig under one or more contributor license | |
# agreements. See the NOTICE file distributed with this work | |
# for additional information regarding copyright ownership. | |
# Jasig licenses this file to you under the Apache License, | |
# Version 2.0 (the "License"); you may not use this file | |
# except in compliance with the License. You may obtain a | |
# copy of the License at the following location: | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, | |
# software distributed under the License is distributed on an | |
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
# KIND, either express or implied. See the License for the | |
# specific language governing permissions and limitations | |
# under the License. | |
# | |
## | |
# Services Management Web UI Security | |
server.name=https://localhost:8443 | |
server.prefix=${server.name}/cas | |
cas.securityContext.serviceProperties.service=${server.prefix}/services/j_acegi_cas_security_check | |
# Names of roles allowed to access the CAS service manager | |
cas.securityContext.serviceProperties.adminRoles=ROLE_ADMIN | |
cas.securityContext.casProcessingFilterEntryPoint.loginUrl=${server.prefix}/login | |
cas.securityContext.ticketValidator.casServerUrlPrefix=${server.prefix} | |
# IP address or CIDR subnet allowed to access the /status URI of CAS that exposes health check information | |
cas.securityContext.status.allowedSubnet=127.0.0.1 | |
cas.themeResolver.defaultThemeName=cas-theme-default | |
cas.viewResolver.basename=default_views | |
## | |
# Unique CAS node name | |
# host.name is used to generate unique Service Ticket IDs and SAMLArtifacts. This is usually set to the specific | |
# hostname of the machine running the CAS node, but it could be any label so long as it is unique in the cluster. | |
host.name=cas01.example.org | |
## | |
# Database flavors for Hibernate | |
# | |
# One of these is needed if you are storing Services or Tickets in an RDBMS via JPA. | |
# | |
# database.hibernate.dialect=org.hibernate.dialect.OracleDialect | |
database.hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect | |
# database.hibernate.dialect=org.hibernate.dialect.HSQLDialect | |
## | |
# CAS Logout Behavior | |
# WEB-INF/cas-servlet.xml | |
# | |
# Specify whether CAS should redirect to the specifyed service parameter on /logout requests | |
# cas.logout.followServiceRedirects=false | |
## | |
# Single Sign-On Session Timeouts | |
# Defaults sourced from WEB-INF/spring-configuration/ticketExpirationPolices.xml | |
# | |
# Maximum session timeout - TGT will expire in maxTimeToLiveInSeconds regardless of usage | |
# tgt.maxTimeToLiveInSeconds=28800 | |
# | |
# Idle session timeout - TGT will expire sooner than maxTimeToLiveInSeconds if no further requests | |
# for STs occur within timeToKillInSeconds | |
# tgt.timeToKillInSeconds=7200 | |
## | |
# Service Ticket Timeout | |
# Default sourced from WEB-INF/spring-configuration/ticketExpirationPolices.xml | |
# | |
# Service Ticket timeout - typically kept short as a control against replay attacks, default is 10s. You'll want to | |
# increase this timeout if you are manually testing service ticket creation/validation via tamperdata or similar tools | |
# st.timeToKillInSeconds=10 | |
## | |
# Single Logout Out Callbacks | |
# Default sourced from WEB-INF/spring-configuration/argumentExtractorsConfiguration.xml | |
# | |
# To turn off all back channel SLO requests set slo.disabled to true | |
# slo.callbacks.disabled=false | |
## | |
# Service Registry Periodic Reloading Scheduler | |
# Default sourced from WEB-INF/spring-configuration/applicationContext.xml | |
# | |
# Force a startup delay of 2 minutes. | |
# service.registry.quartz.reloader.startDelay=120000 | |
# | |
# Reload services every 2 minutes | |
# service.registry.quartz.reloader.repeatInterval=120000 | |
## | |
# Log4j | |
# Default sourced from WEB-INF/spring-configuration/log4jConfiguration.xml: | |
# | |
# It is often time helpful to externalize log4j.xml to a system path to preserve settings between upgrades. | |
# e.g. log4j.config.location=/etc/cas/log4j.xml | |
# log4j.config.location=classpath:log4j.xml | |
# | |
# log4j refresh interval in millis | |
# log4j.refresh.interval=60000 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<beans xmlns="http://www.springframework.org/schema/beans" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xmlns:p="http://www.springframework.org/schema/p" | |
xmlns:tx="http://www.springframework.org/schema/tx" | |
xmlns:sec="http://www.springframework.org/schema/security" | |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd | |
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd | |
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd"> | |
<bean id="authenticationManager" | |
class="org.jasig.cas.authentication.AuthenticationManagerImpl"> | |
<property name="credentialsToPrincipalResolvers"> | |
<list> | |
<bean class="org.jasig.cas.authentication.principal.UsernamePasswordCredentialsToPrincipalResolver" > | |
<property name="attributeRepository" ref="attributeRepository" /> | |
</bean> | |
<bean | |
class="org.jasig.cas.authentication.principal.HttpBasedServiceCredentialsToPrincipalResolver" /> | |
</list> | |
</property> | |
<property name="authenticationHandlers"> | |
<list> | |
<bean class="org.jasig.cas.adaptors.jdbc.BCryptSearchModeSearchDatabaseAuthenticationHandler"> | |
<property name="dataSource" ref="dataSource" /> | |
<property name="tableUsers"> | |
<value>users</value> | |
</property> | |
<property name="fieldUser"> | |
<value>email</value> | |
</property> | |
<property name="fieldPassword"> | |
<value>password</value> | |
</property> | |
</bean> | |
</list> | |
</property> | |
</bean> | |
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> | |
<property name="driverClassName"> | |
<value>com.mysql.jdbc.Driver</value> | |
</property> | |
<property name="url"> | |
<value>jdbc:mysql://localhost:3306/production</value> | |
</property> | |
<property name="username"> | |
<value>root</value> | |
</property> | |
<property name="password"> | |
<value>root</value> | |
</property> | |
</bean> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
cas-server-webapp | |
--> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | |
<parent> | |
<groupId>org.jasig.cas</groupId> | |
<artifactId>cas-server</artifactId> | |
<version>3.5.2</version> | |
</parent> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>org.jasig.cas</groupId> | |
<artifactId>cas-server-webapp</artifactId> | |
<packaging>war</packaging> | |
<name>Jasig CAS Web Application</name> | |
<dependencies> | |
<dependency> | |
<groupId>org.mockito</groupId> | |
<artifactId>mockito-all</artifactId> | |
<version>${mockito.version}</version> | |
<scope>test</scope> | |
<type>jar</type> | |
</dependency> | |
<dependency> | |
<groupId>com.github.inspektr</groupId> | |
<artifactId>inspektr-support-spring</artifactId> | |
<scope>runtime</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.security</groupId> | |
<artifactId>spring-security-core</artifactId> | |
<scope>compile</scope> | |
</dependency> | |
<dependency> | |
<groupId>mysql</groupId> | |
<artifactId>mysql-connector-java</artifactId> | |
<version>5.1.20</version> | |
</dependency> | |
<dependency> | |
<groupId>org.jasig.cas</groupId> | |
<artifactId>cas-server-support-jdbc</artifactId> | |
<version>${project.version}</version> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.security</groupId> | |
<artifactId>spring-security-web</artifactId> | |
<scope>compile</scope> | |
</dependency> | |
<dependency> | |
<groupId>commons-dbcp</groupId> | |
<artifactId>commons-dbcp</artifactId> | |
<version>1.4</version> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.security</groupId> | |
<artifactId>spring-security-cas</artifactId> | |
<scope>runtime</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.security</groupId> | |
<artifactId>spring-security-config</artifactId> | |
<scope>runtime</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework</groupId> | |
<artifactId>spring-aop</artifactId> | |
</dependency> | |
<dependency> | |
<groupId>org.jasig.cas</groupId> | |
<artifactId>cas-server-core</artifactId> | |
<version>${project.version}</version> | |
</dependency> | |
<dependency> | |
<groupId>org.jasig.cas.client</groupId> | |
<artifactId>cas-client-core</artifactId> | |
<version>3.2.1</version> | |
<exclusions> | |
<exclusion> | |
<groupId>javax.servlet</groupId> | |
<artifactId>servlet-api</artifactId> | |
</exclusion> | |
</exclusions> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework</groupId> | |
<artifactId>spring-context-support</artifactId> | |
<scope>compile</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework</groupId> | |
<artifactId>spring-expression</artifactId> | |
<version>${spring.version}</version> | |
<scope>compile</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.opensymphony.quartz</groupId> | |
<artifactId>quartz</artifactId> | |
<version>1.6.1</version> | |
<type>jar</type> | |
</dependency> | |
<dependency> | |
<groupId>net.sf.spring-json</groupId> | |
<artifactId>spring-json</artifactId> | |
<version>1.3.1</version> | |
<scope>runtime</scope> | |
<exclusions> | |
<exclusion> | |
<groupId>net.sf.sojo</groupId> | |
<artifactId>sojo-optional</artifactId> | |
</exclusion> | |
<exclusion> | |
<groupId>org.springframework</groupId> | |
<artifactId>spring</artifactId> | |
</exclusion> | |
<exclusion> | |
<groupId>org.springframework</groupId> | |
<artifactId>spring-mock</artifactId> | |
</exclusion> | |
<exclusion> | |
<groupId>org.springframework</groupId> | |
<artifactId>spring-webmvc</artifactId> | |
</exclusion> | |
<exclusion> | |
<groupId>cglib</groupId> | |
<artifactId>cglib-full</artifactId> | |
</exclusion> | |
</exclusions> | |
</dependency> | |
<dependency> | |
<groupId>cglib</groupId> | |
<artifactId>cglib-nodep</artifactId> | |
<version>2.2.2</version> | |
<scope>runtime</scope> | |
</dependency> | |
<dependency> | |
<groupId>net.sf.sojo</groupId> | |
<artifactId>sojo</artifactId> | |
<version>1.0.5</version> | |
<exclusions> | |
<exclusion> | |
<groupId>commons-attributes</groupId> | |
<artifactId>commons-attributes-api</artifactId> | |
</exclusion> | |
<exclusion> | |
<groupId>commons-logging</groupId> | |
<artifactId>commons-logging</artifactId> | |
</exclusion> | |
</exclusions> | |
</dependency> | |
<dependency> | |
<groupId>javax.servlet</groupId> | |
<artifactId>jstl</artifactId> | |
<version>1.1.2</version> | |
<type>jar</type> | |
</dependency> | |
<dependency> | |
<groupId>taglibs</groupId> | |
<artifactId>standard</artifactId> | |
<version>1.1.2</version> | |
<type>jar</type> | |
</dependency> | |
<dependency> | |
<groupId>ognl</groupId> | |
<artifactId>ognl</artifactId> | |
<version>2.7.3</version> | |
<scope>runtime</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.hibernate</groupId> | |
<artifactId>hibernate-validator</artifactId> | |
<scope>runtime</scope> | |
</dependency> | |
</dependencies> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-war-plugin</artifactId> | |
<configuration> | |
<warName>cas</warName> | |
<webResources> | |
<resource> | |
<directory>${basedir}/src/main/webapp/WEB-INF</directory> | |
<filtering>true</filtering> | |
<targetPath>WEB-INF</targetPath> | |
<includes> | |
<include>**/web.xml</include> | |
</includes> | |
</resource> | |
</webResources> | |
</configuration> | |
</plugin> | |
<plugin> | |
<groupId>org.jasig.maven</groupId> | |
<artifactId>maven-translate-plugin</artifactId> | |
<version>0.0.1</version> | |
<executions> | |
<execution> | |
<goals> | |
<goal>check</goal> | |
</goals> | |
<phase>process-resources</phase> | |
</execution> | |
</executions> | |
<configuration> | |
<messagesDirectory>${basedir}/src/main/webapp/WEB-INF/classes/</messagesDirectory> | |
<mainMessagesFile>messages_en.properties</mainMessagesFile> | |
</configuration> | |
</plugin> | |
</plugins> | |
<pluginManagement> | |
<plugins> | |
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.--> | |
<plugin> | |
<groupId>org.eclipse.m2e</groupId> | |
<artifactId>lifecycle-mapping</artifactId> | |
<version>1.0.0</version> | |
<configuration> | |
<lifecycleMappingMetadata> | |
<pluginExecutions> | |
<pluginExecution> | |
<pluginExecutionFilter> | |
<groupId>org.jasig.maven</groupId> | |
<artifactId>maven-translate-plugin</artifactId> | |
<versionRange>[0.0.1,)</versionRange> | |
<goals> | |
<goal>check</goal> | |
</goals> | |
</pluginExecutionFilter> | |
<action> | |
<ignore /> | |
</action> | |
</pluginExecution> | |
</pluginExecutions> | |
</lifecycleMappingMetadata> | |
</configuration> | |
</plugin> | |
</plugins> | |
</pluginManagement> | |
</build> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment